Thomas
Thomas

Reputation: 12087

Lucene 5.3 term vector

I am moving from Lucene 3 to Lucene 5.3 and I am having a problem to convert a line of code.

I used to pass the fields Field.Index.ANALYZED, Field.TermVector.YES

And now, with this code:

Document.Add(new TextField("Tags", Data.Tags, Field.Store.YES));

I do not know how to pass the TermVector field so that the tag words can be looked up.
The 5.3 doc is essentially a class list with no real explanation about anything and while Lucene 3 has a lot of info in forums, I can't find anything about 5.3 yet

Upvotes: 3

Views: 891

Answers (1)

femtoRgon
femtoRgon

Reputation: 33341

This is a change that occurred in Lucene 4.0, so you may be looking over the wrong resources to understand this one. It's covered in the 4.0 Migration Guide (look for the section titled "Separate IndexableFieldType from Field instances")

You need to define a FieldType to pass into a the Field constructor. If you mostly want TextField behavior, but with term vectors, you can copy the standard FieldTypes of TextField, and modify them, something like this:

FieldType myFieldType = new FieldType(TextField.TYPE_NOT_STORED);
myFieldType.setStoreTermVectors(true);
...
Field f = new Field("Tags", Data.Tags, myFieldType);

Upvotes: 6

Related Questions