Another answer comes from this thread (third answer): Lucene 4.0 IndexWriter updateDocument for Numeric Term
Basically, you create a Term with your int value like this:
String field = "myfield"; int value = 4711; BytesRef bytes = new BytesRef(NumericUtils.BUF_SIZE_INT); NumericUtils.intToPrefixCoded(value, 0, bytes); Term term = new Term(field, bytes); Then you can use this term for searching, or deleting/updating your index. In a first test, this worked fine for me. I can't tell if this is the "right" way to do things however. I've used the NumericRangeFilter before for filtering IntFields, but now I'm inclined to use this approach and use regular TermsFilter, or TermQueries instead.
Read full article from java - How to search an int field in Lucene 4? - Stack Overflow
No comments:
Post a Comment