diff src/goodjava/lucene/api/LuceneIndexWriter.java @ 1525:f848d40b3b07

lucene.api add boosts
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 18 Jul 2020 20:41:47 -0600
parents 7d145095cc0b
children 3bd4d7963456
line wrap: on
line diff
--- a/src/goodjava/lucene/api/LuceneIndexWriter.java	Sat Jul 18 01:00:21 2020 -0600
+++ b/src/goodjava/lucene/api/LuceneIndexWriter.java	Sat Jul 18 20:41:47 2020 -0600
@@ -85,26 +85,34 @@
 
 	private Document newDocument(Map<String,Object> storedFields) {
 		Document doc = new Document();
-		addFields(doc,storedFields,Field.Store.YES);
-		Map<String,Object> unstoredFields = goodConfig.getUnstoredFields(storedFields);
-		addFields(doc,unstoredFields,Field.Store.NO);
+		MoreFieldInfo more = goodConfig.getMoreFieldInfo(storedFields);
+		addFields(doc,storedFields,Field.Store.YES,more.boosts);
+		addFields(doc,more.unstoredFields,Field.Store.NO,more.boosts);
 		return doc;
 	}
 
-	private void addFields( Document doc, Map<String,Object> fields, Field.Store store ) {
+	private void addFields( Document doc, Map<String,Object> fields, Field.Store store, Map<String,Float> boosts ) {
 		for( Map.Entry<String,Object> entry : fields.entrySet() ) {
 			String name = entry.getKey();
 			Object value = entry.getValue();
+			Float boost = boosts.get(name);
 			if( value instanceof List ) {
 				for( Object v : (List)value ) {
-					doc.add( newField(name,v,store) );
+					doc.add( newField(name,v,store,boost) );
 				}
 			} else {
-				doc.add( newField(name,value,store) );
+				doc.add( newField(name,value,store,boost) );
 			}
 		}
 	}
 
+	private Field newField( String name, Object value, Field.Store store, Float boost ) {
+		Field field = newField(name,value,store);
+		if( boost != null )
+			field.setBoost(boost);
+		return field;
+	}
+
 	private Field newField( String name, Object value, Field.Store store ) {
 		boolean isIndexed = isIndexed(name);
 		if( store==Field.Store.NO && !isIndexed )