Creating Documents
We will create a list of documents, where each document has a single field, text
.
We use the TextField
type to indicate that it’s a “full text” field, to be split into individual tokens
during indexing.
In order to retrieve the original field value in our search results, we indicate that we want the field value
stored using Field.Store.YES
.
private static List<List<IndexableField>> createDocuments() {
List<String> texts = List.of(
"Lorem ipsum, dolor sit amet",
"She left the web, she left the loom, she made three paces through the room",
"The sly fox sneaks past the oblivious dog",
"The quick fox jumped over the lazy, brown dog"
);
List<List<IndexableField>> docs = new ArrayList<>();
int i = 0;
for (String text : texts) {
List<IndexableField> doc = new ArrayList<>();
doc.add(new TextField("text", text, Field.Store.YES));
doc.add(new FloatField("floatField", i, Field.Store.YES));
doc.add(new FloatDocValuesField("floatDocValuesField", i));
docs.add(doc);
i++;
}
return docs;
}