Question

I would like to use lucene's MemoryIndex (using 4.7.1) but I need to be able to add lucene Fields so that I can use things like the integer field or a StringField.

I know this is possible in RAMDirectory by adding a Document which can contain Lucene Fields but is this possible in MemoryIndex?

Était-ce utile?

La solution

You can certainly add fields to the index, just not Fields. 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);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top