Store term vectors in the FULL_RECIPE index
- Id
- 62746337ea7c64f725679919cf9133a072cb3d0c
- Author
- Caio
- Commit time
- 2019-04-05T12:18:18+02:00
Modified src/main/java/co/caio/cerberus/search/Indexer.java
package co.caio.cerberus.search;
import static co.caio.cerberus.search.IndexField.*;
+import co.caio.cerberus.lucene.TextFieldWithVectors;
import co.caio.cerberus.model.Recipe;
import java.io.IOException;
import java.nio.file.Path;
recipe.instructions().forEach(i -> doc.add(new TextField(INSTRUCTIONS, i, Store.NO)));
recipe.ingredients().forEach(i -> doc.add(new TextField(INGREDIENTS, i, Store.NO)));
- doc.add(new TextField(FULL_RECIPE, recipe.name(), Store.NO));
- recipe.instructions().forEach(i -> doc.add(new TextField(FULL_RECIPE, i, Store.NO)));
- recipe.ingredients().forEach(i -> doc.add(new TextField(FULL_RECIPE, i, Store.NO)));
+ doc.add(new TextFieldWithVectors(FULL_RECIPE, recipe.name()));
+ recipe.instructions().forEach(i -> doc.add(new TextFieldWithVectors(FULL_RECIPE, i)));
+ recipe.ingredients().forEach(i -> doc.add(new TextFieldWithVectors(FULL_RECIPE, i)));
recipe
.diets()
Created src/main/java/co/caio/cerberus/lucene/TextFieldWithVectors.java
+package co.caio.cerberus.lucene;
+
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.index.IndexOptions;
+
+public class TextFieldWithVectors extends Field {
+ // Tokenized, with vectors, not stored
+ public static final FieldType TYPE;
+
+ static {
+ TYPE = new FieldType();
+ TYPE.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
+ TYPE.setTokenized(true);
+ TYPE.setStoreTermVectors(true);
+ TYPE.freeze();
+ }
+
+ public TextFieldWithVectors(String name, String value) {
+ super(name, value, TYPE);
+ }
+}