Solr Distance Filtering

后端 未结 1 603
甜味超标
甜味超标 2021-02-11 05:26

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,-

1条回答
  •  一生所求
    2021-02-11 05:50

    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}
    

    0 讨论(0)
提交回复
热议问题