You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by dan sutton <da...@gmail.com> on 2010/09/17 15:45:04 UTC
spatial sorting
Hi,
I'm trying to filter and sort by distance with this URL:
http://localhost:8080/solr/select/?q=*:*&fq={!sfilt%20fl=loc_lat_lon}&pt=52.02694,-0.49567&d=2&sort={!func}hsin(52.02694,-0.49567,loc_lat_lon_0_d,%20loc_lat_lon_1_d,3963.205)asc
Filtering is fine but it's failing in parsing the sort with :
"The request sent by the client was syntactically incorrect (can not sort on
undefined field or function: {!func}(52.02694,-0.49567,loc_lat_lon_0_d,
loc_lat_lon_1_d, 3963.205))."*
*I'm using the solr/lucene trunk to try this out ... does anyone know what
is wrong with the syntax?
Additionally am I able to return the distance sort values e.g. with param fl
? ... else am I going to have to either write my own component (which would
also look up the filtered cached values rather than re-calculating distance)
or use an alternative like localsolr ?
Dan
Re: spatial sorting
Posted by Grant Ingersoll <gs...@apache.org>.
On Sep 17, 2010, at 9:45 AM, dan sutton wrote:
> Hi,
>
> I'm trying to filter and sort by distance with this URL:
>
> http://localhost:8080/solr/select/?q=*:*&fq={!sfilt%20fl=loc_lat_lon}&pt=52.02694,-0.49567&d=2&sort={!func}hsin(52.02694,-0.49567,loc_lat_lon_0_d,%20loc_lat_lon_1_d,3963.205)asc
>
> Filtering is fine but it's failing in parsing the sort with :
>
> "The request sent by the client was syntactically incorrect (can not sort on
> undefined field or function: {!func}(52.02694,-0.49567,loc_lat_lon_0_d,
> loc_lat_lon_1_d, 3963.205))."*
I don't see a function declared in that line, although it is in the one above. Also, you need a space between the function and asc.
Re: spatial sorting
Posted by dan sutton <da...@gmail.com>.
Hi All,
This is more of an FYI for those wanting to filter and sort by distance, and
have the values returned in the result set after determining a way to do
this with existing code.
Using solr 4.0 an example query would contain the following parameters:
/select?
q=stevenage^0.0
+_val_:"ghhsin(6371,geohash(52.0274,-0.4952),location)"^1.0
Make the boost on all parts of the query other than the ghhsin distance
value function 0 ,and 1 on the function, this is so that the score is then
equal to the distance. (52.0274,-0.4952) here is the query point and
'location' is the geohash field to search against
sort=score asc
basically sort by distance asc (closest first)
fq={!sfilt%20fl=location}&pt=52.0274,-0.4952&d=30
This is the spatial filter to limit the necessary distance calculations.
fl=*,score
Return all fields (if required) but include the score (which contains the
distance calculation)
Does anyone know if it's possible to return the distance and score
separately? I know there has been a patch to sort by value function, but
how can one return the values from this?
Cheers,
Dan
On Fri, Sep 17, 2010 at 2:45 PM, dan sutton <da...@gmail.com> wrote:
> Hi,
>
> I'm trying to filter and sort by distance with this URL:
>
>
> http://localhost:8080/solr/select/?q=*:*&fq={!sfilt%20fl=loc_lat_lon}&pt=52.02694,-0.49567&d=2&sort={!func}hsin(52.02694,-0.49567,loc_lat_lon_0_d,%20loc_lat_lon_1_d,3963.205)<http://localhost:8080/solr/select/?q=*:*&fq=%7B%21sfilt%20fl=loc_lat_lon%7D&pt=52.02694,-0.49567&d=2&sort=%7B%21func%7Dhsin%2852.02694,-0.49567,loc_lat_lon_0_d,%20loc_lat_lon_1_d,3963.205%29>asc
>
> Filtering is fine but it's failing in parsing the sort with :
>
> "The request sent by the client was syntactically incorrect (can not sort
> on undefined field or function: {!func}(52.02694,-0.49567,loc_lat_lon_0_d,
> loc_lat_lon_1_d, 3963.205))."*
>
> *I'm using the solr/lucene trunk to try this out ... does anyone know what
> is wrong with the syntax?
>
> Additionally am I able to return the distance sort values e.g. with param
> fl ? ... else am I going to have to either write my own component (which
> would also look up the filtered cached values rather than re-calculating
> distance) or use an alternative like localsolr ?
>
> Dan
>