comparison 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
comparison
equal deleted inserted replaced
1524:7902e74bfe5c 1525:f848d40b3b07
83 luceneWriter.updateDocument(term,doc); 83 luceneWriter.updateDocument(term,doc);
84 } 84 }
85 85
86 private Document newDocument(Map<String,Object> storedFields) { 86 private Document newDocument(Map<String,Object> storedFields) {
87 Document doc = new Document(); 87 Document doc = new Document();
88 addFields(doc,storedFields,Field.Store.YES); 88 MoreFieldInfo more = goodConfig.getMoreFieldInfo(storedFields);
89 Map<String,Object> unstoredFields = goodConfig.getUnstoredFields(storedFields); 89 addFields(doc,storedFields,Field.Store.YES,more.boosts);
90 addFields(doc,unstoredFields,Field.Store.NO); 90 addFields(doc,more.unstoredFields,Field.Store.NO,more.boosts);
91 return doc; 91 return doc;
92 } 92 }
93 93
94 private void addFields( Document doc, Map<String,Object> fields, Field.Store store ) { 94 private void addFields( Document doc, Map<String,Object> fields, Field.Store store, Map<String,Float> boosts ) {
95 for( Map.Entry<String,Object> entry : fields.entrySet() ) { 95 for( Map.Entry<String,Object> entry : fields.entrySet() ) {
96 String name = entry.getKey(); 96 String name = entry.getKey();
97 Object value = entry.getValue(); 97 Object value = entry.getValue();
98 Float boost = boosts.get(name);
98 if( value instanceof List ) { 99 if( value instanceof List ) {
99 for( Object v : (List)value ) { 100 for( Object v : (List)value ) {
100 doc.add( newField(name,v,store) ); 101 doc.add( newField(name,v,store,boost) );
101 } 102 }
102 } else { 103 } else {
103 doc.add( newField(name,value,store) ); 104 doc.add( newField(name,value,store,boost) );
104 } 105 }
105 } 106 }
107 }
108
109 private Field newField( String name, Object value, Field.Store store, Float boost ) {
110 Field field = newField(name,value,store);
111 if( boost != null )
112 field.setBoost(boost);
113 return field;
106 } 114 }
107 115
108 private Field newField( String name, Object value, Field.Store store ) { 116 private Field newField( String name, Object value, Field.Store store ) {
109 boolean isIndexed = isIndexed(name); 117 boolean isIndexed = isIndexed(name);
110 if( store==Field.Store.NO && !isIndexed ) 118 if( store==Field.Store.NO && !isIndexed )