Domanda

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?

È stato utile?

Soluzione

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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top