Solr距离过滤 [英] Solr Distance Filtering
问题描述
我知道很容易在5公里范围内搜索过滤
& q = *:*& fq = {!geofilt pt = 45.15,-93.85 sfield = store d = 5}
我所追求的是如何做同样的事情如果我在5到10公里范围内寻找,
谢谢
所以很显然,查询进入过滤器查询(fq参数),因为其目的不是修改分数。假设这些参数是在请求URL中设置的(尽管它们不必放在那里):
pt = 45.15,-93.85& sfield = store
以下是一种方法:
_query _:{!geofilt d = 10}-_query _:{!geofilt d = 5}
$ c $我使用_query_ Solr语法hack来输入一个子查询,它提供了将查询解析器从Lucene切换到地理切换的机会。
这是另一种可能最快的方法:
{! frange l = 5 u = 10} geodist()
这是一个返回距离的函数查询然后限制在期望的范围内。它可能会更快,因为它会评估每个文件一次,而不是像以前的意志一样。
您可能希望将其标记为不可缓存,并添加一个bbox过滤器,以便检查每个文档的数量少得多。 这是最后的结果(不是url转义):
pt = 45.15,-93.85& sfield = store& fq = {!frange l = 5 u = 10 cache = false cost = 100} geodist()& fq = {!bbox d = 10}
I am trying to do distance range search using Solr.
I know its very easy to do a search for filtering within the 5km range
&q=*:*&fq={!geofilt pt=45.15,-93.85 sfield=store d=5}
What I am after is how to do the same thing if I am looking in a range of say 5 to 10 km ??
Thanks
解决方案 Here are a couple ways to approach this. So clearly the query goes into a filter query ("fq" param) since the intention is not to modify the score. And lets assume the these parameters are set in the request URL (although they don't have to be placed there):
pt=45.15,-93.85&sfield=store
Here is one approach:
_query_:"{!geofilt d=10}" -_query_:"{!geofilt d=5}"
I used the _query_ Solr syntax hack to enter a sub-query which offers the opportunity to switch the query parser from the Lucene one to a geo one.
Here's another approach that is probably the fastest:
{!frange l=5 u=10}geodist()
This one is a function query returning the distance that is then limited to the desired range. It is probably faster since it will evaluate each document once each instead of twice like the previous will.
You may want to mark this as not cacheable and add a bbox filter so that far fewer then every document is examined. Here is the final result (not url escaped):
pt=45.15,-93.85&sfield=store&fq={!frange l=5 u=10 cache=false cost=100}geodist()&fq={!bbox d=10}
这篇关于Solr距离过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!