Reputation: 25269
I was reading the following article, http://www.searchworkings.org/blog/-/blogs/the-state-and-future-of-spatial-search/, which states,
A SpatialFilter which uses NumericRangeQuery based bounding boxes to easily filter out documents outside of a certain range.
Investigating a bit, I don't see that actually happening in the SOLR source code:
I.e. at line 201 I see:
Query latRange = latField.getType().getRangeQuery(parser, latField,
String.valueOf(latMin),String.valueOf(latMax),true, true);
Which seems to use a TermRangeQuery. Crossing over to the NumericRangeQuery javadoc here http://lucene.apache.org/core/old_versioned_docs/versions/3_1_0/api/all/org/apache/lucene/search/NumericRangeQuery.html, it appears that NumericRangeQuery is definitely preferable, as it's much much faster:
Comparisons of the different types of RangeQueries on an index with about 500,000 docs showed that TermRangeQuery in boolean rewrite mode (with raised BooleanQuery clause count) took about 30-40 secs to complete, TermRangeQuery in constant score filter rewrite mode took 5 secs and executing this class took <100ms to complete (on an Opteron64 machine, Java 1.5, 8 bit precision step).
I really want the uber fast NumericRangeQuery but it doesn't look like I get it out of the box. I must be missing something.
EDIT:
LatLonType from schema.xml:
<fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
Which is I think, the default that ships with Solr...
Upvotes: 1
Views: 813
Reputation: 9964
Actually, the bbox
and geofilt
spatial filters will use createSpatialQuery
whereas the default (Lucene) query parser (using syntax [start TO end]
) will use getRangeQuery
.
In both cases, these methods leverage getRangeQuery
on the sub fields. The type of range query will depend on this sub field type, which is configurable using the subFieldType
or subFieldSuffix
attribute of the LatLon field type. If you want to use numeric range queries, just use an instance of TrieDoubleField
.
For example
<fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
<fieldType name="latLon" class="solr.LatLonType" subFieldSuffix="_latLon"/>
<field name="lat_lon" type="latLon" indexed="true" stored="true"/>
<dynamicField name="*_latLon" type="tdouble" indexed="true" stored="false" multiValued="true"/>
Upvotes: 2