Solr Distance Filtering

扶醉桌前 提交于 2019-12-04 14:31:40

问题


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


回答1:


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}


来源:https://stackoverflow.com/questions/10867113/solr-distance-filtering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!