You can certainly add fields to the index, just not Field
s. It's fairly simple for StringField
and TextField
, since there is a nice convenience method for you to use. For a StringField
, something like:
index.addField("thestring", text, new KeywordAnalyzer());
For a TextField
:
index.addField("sometext", text, new StandardAnalyzer(Version.LUCENE_47));
For an IntField
and other numerics, you'll need to produce the tokenstream yourself. NumericTokenStream
is the class of interest here:
NumericTokenStream stream = new NumericTokenStream();
stream.setIntValue(myInt);
index.addField("aninteger", stream);