Reputation: 754
I defined a field as follows:
@Column(name = "clip_segments")
@Field(store = Store.YES)
public long getClipSegments() {
return clipSegments;
}
And I wanted to apply a NumericRangeQuery to it, when searching for objects (return all objects with the field value > 0):
org.apache.lucene.search.Query onlyCompilableQuery = NumericRangeQuery
.newIntRange("clipSegments", 0, Integer.MAX_VALUE, false,
false);
However, this always fails, i.e. no results are returned. I examined the index with Luke and I can see that the fields are annotated as numeric and they have different values.
I tried several ways but always with the same results. Ultimately, I decided to use the IntegerBridge:
@Column(name = "clip_segments")
@Field(store = Store.YES)
@FieldBridge(impl = IntegerBridge.class)
public long getClipSegments() {
return clipSegments;
}
And use a simple keyword search on the field:
org.apache.lucene.search.Query onlyCompilableQuery = qb.keyword()
.onFields("clipSegments").matching("0")
.createQuery();
And this works if I do a BooleanJunction with .not() on the query to get all the objects with the string field different than "0".
I don't understand what I'm doing wrong with the NumericField. Any help is appreciated.
Also, is the performance much better using the NumericRangeQuery?
Upvotes: 0
Views: 405
Reputation: 10539
I'm not really surprised, Integers and Longs are encoded differently in the Lucene index.
Try with NumericRangeQuery.newLongRange instead of newIntRange.
That being said, you should use the DSL which will do the work for you and avoid these errors. See http://docs.jboss.org/hibernate/search/5.5/reference/en-US/html_single/#_range_queries for some examples.
You have an example with below(), in your case, you should just use above(0l).
Upvotes: 2