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 Maxim Veksler <ma...@vekslers.org> on 2012/01/17 19:06:58 UTC

How to return the distance geo distance on solr 3.5 with bbox filtering

Hello,

I'm querying with bbox which should be faster then geodist, my queries are
looking like this:
http://localhost:8983/solr/select?indent=true&fq={!bbox}&sfield=loc&pt=39.738548,-73.130322&d=100&sort=geodist()%20asc&q=trafficRouteId:235

the trouble is, that with bbox solr does not return the distance of each
document, I couldn't get it to work even with tips from
http://wiki.apache.org/solr/SpatialSearch#Returning_the_distance

Something I'm missing ?

Re: How to return the distance geo distance on solr 3.5 with bbox filtering

Posted by Mikhail Khludnev <mk...@griddynamics.com>.
On Thu, Jan 19, 2012 at 8:29 PM, Maxim Veksler <ma...@vekslers.org> wrote:

> It works. The query:
>
> *
>
> http://localhost:8983/solr/select?indent=true&fq={!bbox}&sfield=loc&pt=34.0415954,-118.298797&d=1000.0&sort=score%20asc&fq=trafficRouteId:887&q={!func}geodist()&fl=*,score&rows=1
> *
>
> works perfectly, doing all the filtering needed and returning the distance
> as score. Thank you very much for this help.
>
> As a new comer to lucene/solr I must admit the the syntax is confusing.
>
> For ex. why for the "fq" parameter

http://wiki.apache.org/solr/CommonQueryParameters#fq

> the "function name"

it's QParser, common are listed here
http://wiki.apache.org/solr/SolrQuerySyntax#Other_built-in_useful_query_parsers
bbox
is http://wiki.apache.org/solr/SpatialSearch#bbox_-_Bounding-box_filter

> is *in* the {} (as
>
{it's} unique Solr only stuff http://wiki.apache.org/solr/LocalParams

> in fq={!bbox}),

yet for the "q" parameter the "name of the function" is
> outside the {} (as in q={!func}geodist()) ?
>
it's func QParser
http://lucene.apache.org/solr/api/org/apache/solr/search/FunctionQParserPlugin.html

geodist() is a
function org.apache.solr.search.function.distance.HaversineConstFunction

bbox here is a org.apache.solr.search.SpatialBoxQParserPlugin

>
> Or the parameters to the bbox search function are specified as separate
> query parameters? (the sfield and pt parameters) ?
>
"query parser" instead "search function"


> Would be happy to understand the logic behind it.
>
>
> Thank you,
> Maxim.
>
> On Wed, Jan 18, 2012 at 9:11 PM, Mikhail Khludnev <
> mkhludnev@griddynamics.com> wrote:
>
> > Can you try to specify two fqs, geodist as a function query, sort by
> score?
> >
> >
> >
> fq={!bbox}&.....&sort=score%20asc&fq=trafficRouteId:235&q={!func}geodist()&fl=*,score
> >
> > On Wed, Jan 18, 2012 at 4:46 PM, Maxim Veksler <ma...@vekslers.org>
> wrote:
> >
> > > Hello Mikhail,
> > >
> > > Please see reply inline.
> > >
> > > On Wed, Jan 18, 2012 at 11:00 AM, Mikhail Khludnev <
> > > mkhludnev@griddynamics.com> wrote:
> > >
> > > > Maxim,
> > > >
> > > > Which version of Solr you are using?
> > > >
> > >
> > > As mentioned in the title, I'm using Solr 3.5.
> > >
> >
> > I see
> >
> >
> > >
> > >
> > > > Why the second approach at the link doesn't work for you?
> > > >
> > > I'm not sure I'm following. I'm trying to use bbox instead of
> > >
> > > I use the fq fields to define the bbox filtering.
> > > I also need to query by another parameter (trafficRouteId).
> > >
> > you can put trafficRouteId as a second fq, as I did above
> >
> >
> > >
> > > I would optimally would be happy to get the distance calculation from
> > Solr
> > > but that doesn't seem to work in any format of query I tried.
> > >
> > pls try my approach above and let me know what you get.
> >
> >
> >
> > >
> > > Being new to Solr query language I'm not sure how to form the search
> > terms
> > > to combine all of this with the score.
> > >
> > >
> > >
> > > > what do you get on this case? pls provide, logs, exception, and debug
> > > > response.
> > > >
> > > > Thanks
> > > >
> > > >
> > > > On Tue, Jan 17, 2012 at 10:06 PM, Maxim Veksler <ma...@vekslers.org>
> > > > wrote:
> > > >
> > > > > Hello,
> > > > >
> > > > > I'm querying with bbox which should be faster then geodist, my
> > queries
> > > > are
> > > > > looking like this:
> > > > >
> > > > >
> > > >
> > >
> >
> http://localhost:8983/solr/select?indent=true&fq={!bbox}&sfield=loc&pt=39.738548,-73.130322&d=100&sort=geodist()%20asc&q=trafficRouteId:235
> > > > <
> > > >
> > >
> >
> http://localhost:8983/solr/select?indent=true&fq=%7B%21bbox%7D&sfield=loc&pt=39.738548,-73.130322&d=100&sort=geodist%28%29%20asc&q=trafficRouteId:235
> > > > >
> > > > >
> > > > > the trouble is, that with bbox solr does not return the distance of
> > > each
> > > > > document, I couldn't get it to work even with tips from
> > > > > http://wiki.apache.org/solr/SpatialSearch#Returning_the_distance
> > > > >
> > > > > Something I'm missing ?
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Sincerely yours
> > > > Mikhail Khludnev
> > > > Lucid Certified
> > > > Apache Lucene/Solr Developer
> > > > Grid Dynamics
> > > >
> > > > <http://www.griddynamics.com>
> > > >  <mk...@griddynamics.com>
> > > >
> > >
> >
> >
> >
> > --
> > Sincerely yours
> > Mikhail Khludnev
> > Lucid Certified
> > Apache Lucene/Solr Developer
> > Grid Dynamics
> >
> > <http://www.griddynamics.com>
> >  <mk...@griddynamics.com>
> >
>



-- 
Sincerely yours
Mikhail Khludnev
Lucid Certified
Apache Lucene/Solr Developer
Grid Dynamics

<http://www.griddynamics.com>
 <mk...@griddynamics.com>

Re: How to return the distance geo distance on solr 3.5 with bbox filtering

Posted by Maxim Veksler <ma...@vekslers.org>.
It works. The query:

*
http://localhost:8983/solr/select?indent=true&fq={!bbox}&sfield=loc&pt=34.0415954,-118.298797&d=1000.0&sort=score%20asc&fq=trafficRouteId:887&q={!func}geodist()&fl=*,score&rows=1
*

works perfectly, doing all the filtering needed and returning the distance
as score. Thank you very much for this help.

As a new comer to lucene/solr I must admit the the syntax is confusing.

For ex. why for the "fq" parameter the "function name" is *in* the {} (as
in fq={!bbox}), yet for the "q" parameter the "name of the function" is
outside the {} (as in q={!func}geodist()) ?

Or the parameters to the bbox search function are specified as separate
query parameters? (the sfield and pt parameters) ?

Would be happy to understand the logic behind it.


Thank you,
Maxim.

On Wed, Jan 18, 2012 at 9:11 PM, Mikhail Khludnev <
mkhludnev@griddynamics.com> wrote:

> Can you try to specify two fqs, geodist as a function query, sort by score?
>
>
> fq={!bbox}&.....&sort=score%20asc&fq=trafficRouteId:235&q={!func}geodist()&fl=*,score
>
> On Wed, Jan 18, 2012 at 4:46 PM, Maxim Veksler <ma...@vekslers.org> wrote:
>
> > Hello Mikhail,
> >
> > Please see reply inline.
> >
> > On Wed, Jan 18, 2012 at 11:00 AM, Mikhail Khludnev <
> > mkhludnev@griddynamics.com> wrote:
> >
> > > Maxim,
> > >
> > > Which version of Solr you are using?
> > >
> >
> > As mentioned in the title, I'm using Solr 3.5.
> >
>
> I see
>
>
> >
> >
> > > Why the second approach at the link doesn't work for you?
> > >
> > I'm not sure I'm following. I'm trying to use bbox instead of
> >
> > I use the fq fields to define the bbox filtering.
> > I also need to query by another parameter (trafficRouteId).
> >
> you can put trafficRouteId as a second fq, as I did above
>
>
> >
> > I would optimally would be happy to get the distance calculation from
> Solr
> > but that doesn't seem to work in any format of query I tried.
> >
> pls try my approach above and let me know what you get.
>
>
>
> >
> > Being new to Solr query language I'm not sure how to form the search
> terms
> > to combine all of this with the score.
> >
> >
> >
> > > what do you get on this case? pls provide, logs, exception, and debug
> > > response.
> > >
> > > Thanks
> > >
> > >
> > > On Tue, Jan 17, 2012 at 10:06 PM, Maxim Veksler <ma...@vekslers.org>
> > > wrote:
> > >
> > > > Hello,
> > > >
> > > > I'm querying with bbox which should be faster then geodist, my
> queries
> > > are
> > > > looking like this:
> > > >
> > > >
> > >
> >
> http://localhost:8983/solr/select?indent=true&fq={!bbox}&sfield=loc&pt=39.738548,-73.130322&d=100&sort=geodist()%20asc&q=trafficRouteId:235
> > > <
> > >
> >
> http://localhost:8983/solr/select?indent=true&fq=%7B%21bbox%7D&sfield=loc&pt=39.738548,-73.130322&d=100&sort=geodist%28%29%20asc&q=trafficRouteId:235
> > > >
> > > >
> > > > the trouble is, that with bbox solr does not return the distance of
> > each
> > > > document, I couldn't get it to work even with tips from
> > > > http://wiki.apache.org/solr/SpatialSearch#Returning_the_distance
> > > >
> > > > Something I'm missing ?
> > > >
> > >
> > >
> > >
> > > --
> > > Sincerely yours
> > > Mikhail Khludnev
> > > Lucid Certified
> > > Apache Lucene/Solr Developer
> > > Grid Dynamics
> > >
> > > <http://www.griddynamics.com>
> > >  <mk...@griddynamics.com>
> > >
> >
>
>
>
> --
> Sincerely yours
> Mikhail Khludnev
> Lucid Certified
> Apache Lucene/Solr Developer
> Grid Dynamics
>
> <http://www.griddynamics.com>
>  <mk...@griddynamics.com>
>

Re: How to return the distance geo distance on solr 3.5 with bbox filtering

Posted by Mikhail Khludnev <mk...@griddynamics.com>.
Can you try to specify two fqs, geodist as a function query, sort by score?

fq={!bbox}&.....&sort=score%20asc&fq=trafficRouteId:235&q={!func}geodist()&fl=*,score

On Wed, Jan 18, 2012 at 4:46 PM, Maxim Veksler <ma...@vekslers.org> wrote:

> Hello Mikhail,
>
> Please see reply inline.
>
> On Wed, Jan 18, 2012 at 11:00 AM, Mikhail Khludnev <
> mkhludnev@griddynamics.com> wrote:
>
> > Maxim,
> >
> > Which version of Solr you are using?
> >
>
> As mentioned in the title, I'm using Solr 3.5.
>

I see


>
>
> > Why the second approach at the link doesn't work for you?
> >
> I'm not sure I'm following. I'm trying to use bbox instead of
>
> I use the fq fields to define the bbox filtering.
> I also need to query by another parameter (trafficRouteId).
>
you can put trafficRouteId as a second fq, as I did above


>
> I would optimally would be happy to get the distance calculation from Solr
> but that doesn't seem to work in any format of query I tried.
>
pls try my approach above and let me know what you get.



>
> Being new to Solr query language I'm not sure how to form the search terms
> to combine all of this with the score.
>
>
>
> > what do you get on this case? pls provide, logs, exception, and debug
> > response.
> >
> > Thanks
> >
> >
> > On Tue, Jan 17, 2012 at 10:06 PM, Maxim Veksler <ma...@vekslers.org>
> > wrote:
> >
> > > Hello,
> > >
> > > I'm querying with bbox which should be faster then geodist, my queries
> > are
> > > looking like this:
> > >
> > >
> >
> http://localhost:8983/solr/select?indent=true&fq={!bbox}&sfield=loc&pt=39.738548,-73.130322&d=100&sort=geodist()%20asc&q=trafficRouteId:235
> > <
> >
> http://localhost:8983/solr/select?indent=true&fq=%7B%21bbox%7D&sfield=loc&pt=39.738548,-73.130322&d=100&sort=geodist%28%29%20asc&q=trafficRouteId:235
> > >
> > >
> > > the trouble is, that with bbox solr does not return the distance of
> each
> > > document, I couldn't get it to work even with tips from
> > > http://wiki.apache.org/solr/SpatialSearch#Returning_the_distance
> > >
> > > Something I'm missing ?
> > >
> >
> >
> >
> > --
> > Sincerely yours
> > Mikhail Khludnev
> > Lucid Certified
> > Apache Lucene/Solr Developer
> > Grid Dynamics
> >
> > <http://www.griddynamics.com>
> >  <mk...@griddynamics.com>
> >
>



-- 
Sincerely yours
Mikhail Khludnev
Lucid Certified
Apache Lucene/Solr Developer
Grid Dynamics

<http://www.griddynamics.com>
 <mk...@griddynamics.com>

Re: How to return the distance geo distance on solr 3.5 with bbox filtering

Posted by Maxim Veksler <ma...@vekslers.org>.
Hello Mikhail,

Please see reply inline.

On Wed, Jan 18, 2012 at 11:00 AM, Mikhail Khludnev <
mkhludnev@griddynamics.com> wrote:

> Maxim,
>
> Which version of Solr you are using?
>

As mentioned in the title, I'm using Solr 3.5.


> Why the second approach at the link doesn't work for you?
> just move q=trafficRouteId:235<
> http://localhost:8983/solr/select?indent=true&fq=%7B%21bbox%7D&sfield=loc&pt=39.738548,-73.130322&d=100&sort=geodist%28%29%20asc&q=trafficRouteId:235
> >to
> fq=, because it's pretty a filter, and use geodist() as a function
> query. &sort=score%20asc&q={!func}geodist()<
> http://localhost:8983/solr/select?indent=true&fl=name,store&sfield=store&pt=45.15,-93.85&sort=score%20asc&q=%7B%21func%7Dgeodist%28%29
> >
>
>
I'm not sure I'm following. I'm trying to use bbox instead of

I use the fq fields to define the bbox filtering.
I also need to query by another parameter (trafficRouteId).

I would optimally would be happy to get the distance calculation from Solr
but that doesn't seem to work in any format of query I tried.

Being new to Solr query language I'm not sure how to form the search terms
to combine all of this with the score.



> what do you get on this case? pls provide, logs, exception, and debug
> response.
>
> Thanks
>
>
> On Tue, Jan 17, 2012 at 10:06 PM, Maxim Veksler <ma...@vekslers.org>
> wrote:
>
> > Hello,
> >
> > I'm querying with bbox which should be faster then geodist, my queries
> are
> > looking like this:
> >
> >
> http://localhost:8983/solr/select?indent=true&fq={!bbox}&sfield=loc&pt=39.738548,-73.130322&d=100&sort=geodist()%20asc&q=trafficRouteId:235
> <
> http://localhost:8983/solr/select?indent=true&fq=%7B%21bbox%7D&sfield=loc&pt=39.738548,-73.130322&d=100&sort=geodist%28%29%20asc&q=trafficRouteId:235
> >
> >
> > the trouble is, that with bbox solr does not return the distance of each
> > document, I couldn't get it to work even with tips from
> > http://wiki.apache.org/solr/SpatialSearch#Returning_the_distance
> >
> > Something I'm missing ?
> >
>
>
>
> --
> Sincerely yours
> Mikhail Khludnev
> Lucid Certified
> Apache Lucene/Solr Developer
> Grid Dynamics
>
> <http://www.griddynamics.com>
>  <mk...@griddynamics.com>
>

Re: How to return the distance geo distance on solr 3.5 with bbox filtering

Posted by Mikhail Khludnev <mk...@griddynamics.com>.
Maxim,

Which version of Solr you are using?
Why the second approach at the link doesn't work for you?
just move q=trafficRouteId:235<http://localhost:8983/solr/select?indent=true&fq=%7B%21bbox%7D&sfield=loc&pt=39.738548,-73.130322&d=100&sort=geodist%28%29%20asc&q=trafficRouteId:235>to
fq=, because it's pretty a filter, and use geodist() as a function
query. &sort=score%20asc&q={!func}geodist()<http://localhost:8983/solr/select?indent=true&fl=name,store&sfield=store&pt=45.15,-93.85&sort=score%20asc&q=%7B%21func%7Dgeodist%28%29>

what do you get on this case? pls provide, logs, exception, and debug
response.

Thanks


On Tue, Jan 17, 2012 at 10:06 PM, Maxim Veksler <ma...@vekslers.org> wrote:

> Hello,
>
> I'm querying with bbox which should be faster then geodist, my queries are
> looking like this:
>
> http://localhost:8983/solr/select?indent=true&fq={!bbox}&sfield=loc&pt=39.738548,-73.130322&d=100&sort=geodist()%20asc&q=trafficRouteId:235<http://localhost:8983/solr/select?indent=true&fq=%7B%21bbox%7D&sfield=loc&pt=39.738548,-73.130322&d=100&sort=geodist%28%29%20asc&q=trafficRouteId:235>
>
> the trouble is, that with bbox solr does not return the distance of each
> document, I couldn't get it to work even with tips from
> http://wiki.apache.org/solr/SpatialSearch#Returning_the_distance
>
> Something I'm missing ?
>



-- 
Sincerely yours
Mikhail Khludnev
Lucid Certified
Apache Lucene/Solr Developer
Grid Dynamics

<http://www.griddynamics.com>
 <mk...@griddynamics.com>