我正在阅读以下文章,http://www.searchworkings.org/blog/-/blogs/the-state-and-future-of-spatial-search/ ,其中指出,
A SpatialFilter which uses NumericRangeQuery based bounding boxes to easily filter out documents outside of a certain range.
调查了一下,我没有看到 SOLR 源代码中实际发生的情况:
即在第 201 行我看到:
Query latRange = latField.getType().getRangeQuery(parser, latField,
String.valueOf(latMin),String.valueOf(latMax),true, true);
这似乎使用了 TermRangeQuery。转到此处的 NumericRangeQuery javadoc http://lucene.apache.org/core/old_versioned_docs/versions/3_1_0/api/all/org/apache/lucene/search/NumericRangeQuery.html ,看来 NumericRangeQuery 绝对是更可取的,因为它要快得多:
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).
我真的想要 super 快速的 NumericRangeQuery,但看起来我并没有把它开箱即用。我肯定错过了什么。
编辑:
来自 schema.xml 的 LatLonType:
<fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
我认为这是 Solr 附带的默认设置...
最佳答案
实际上,bbox
和 geofilt
空间过滤器将使用 createSpatialQuery
,而默认 (Lucene) 查询解析器(使用语法 [ start TO end]
)将使用 getRangeQuery
。
在这两种情况下,这些方法都会利用子字段上的 getRangeQuery
。范围查询的类型将取决于此子字段类型,可以使用 LatLon 字段类型的 subFieldType
或 subFieldSuffix
属性进行配置。如果您想使用数字范围查询,只需使用 TrieDoubleField
的实例即可。
例如
<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"/>
关于java - SOLR NumericRangeQuery 的空间使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9592550/