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(
"The quick fox jumped over the lazy, brown dog",
"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"
);
List<List<IndexableField>> docs = new ArrayList<>();
for (String text : texts) {
List<IndexableField> doc = new ArrayList<>();
doc.add(new TextField("text", text, Field.Store.YES));
docs.add(doc);
}
return docs;
}