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 Oliver Beattie <ol...@obeattie.com> on 2009/11/20 09:15:39 UTC

Function queries question

Hi all,

I'm a relative newcomer to Solr, and I'm trying to use it in a project
of mine. I need to do a function query (I believe) to filter the
results so they are within a certain distance of a point. For this, I
understand I should use something like sqedist or hsin, and from the
documentation on the FunctionQuery page, I believe that the function
is executed on every "row" (or "record", not sure what the proper term
for this is). So, my question is threefold really; are those functions
the ones I should be using to perform a search where distance is one
of the criteria (there are others), and if so, does Solr execute the
query on every row (and again, if so, is there any way of preventing
this [like subqueries, though I know they're not supported])?

Sorry if this is a little confusing… any help would be greatly appreciated :)

Thanks,
Oliver

Re: Function queries question

Posted by Grant Ingersoll <gs...@apache.org>.
On Nov 23, 2009, at 6:54 AM, Oliver Beattie wrote:

> Thanks for getting back to me. I've added inline responses below.
> 
> 2009/11/20 Grant Ingersoll <gs...@apache.org>
>> 
>> On Nov 20, 2009, at 3:15 AM, Oliver Beattie wrote:
>> 
>>> Hi all,
>>> 
>>> I'm a relative newcomer to Solr, and I'm trying to use it in a project
>>> of mine. I need to do a function query (I believe) to filter the
>>> results so they are within a certain distance of a point. For this, I
>>> understand I should use something like sqedist or hsin, and from the
>>> documentation on the FunctionQuery page, I believe that the function
>>> is executed on every "row" (or "record", not sure what the proper term
>>> for this is). So, my question is threefold really; are those functions
>>> the ones I should be using to perform a search where distance is one
>>> of the criteria (there are others),
>> 
>> Short answer: yes.  Long answer:  I just committed those functions this week.  I believe they are good, but feedback is encouraged.
> 
> I'll be sure to let you know if I find anything report-worthy :)
> They're definitely super-useful for people doing similar things to I
> though, so great work :)
> 
>>> and if so, does Solr execute the
>>> query on every row (and again, if so, is there any way of preventing
>>> this [like subqueries, though I know they're not supported])?
>> 
>> You can use the frange capability to filter first.  See http://www.lucidimagination.com/blog/tag/frange/
> 
> Thanks for the link. I'll definitely do that. Does Solr execute the
> function on every row in the database on every query otherwise?

If the query is unrestricted by other clauses or by filters, yes it will execute over all docs in the index.


> 
>> 
>> Here's an example from a soon to be published article I'm writing:
>> http://localhost:8983/solr/select/?q=*:*&amp;fq={!frange l=0 u=400}hsin(0.57, -1.3, lat_rad, lon_rad,  3963.205)
>> 
>> This should filter out all documents that are beyond 400 miles in distance from that point on a sphere (specified in radians, see also the rads() method)
>> 
>> 
>> 
>>> 
>>> Sorry if this is a little confusing… any help would be greatly appreciated :)

Which part?  The hsin() part calculates the distance between the point 0.57, -1.3 and the values in the fields lat_rad, lon_rad and is using 3963.205 as the radius of the sphere (which is the approx. radius of the Earth in miles).  The frange stuff then filters such that it only accepts docs that have a value for hsin between 0 and 400.

-Grant


Re: Function queries question

Posted by Oliver Beattie <ol...@obeattie.com>.
Thanks for getting back to me. I've added inline responses below.

2009/11/20 Grant Ingersoll <gs...@apache.org>
>
> On Nov 20, 2009, at 3:15 AM, Oliver Beattie wrote:
>
> > Hi all,
> >
> > I'm a relative newcomer to Solr, and I'm trying to use it in a project
> > of mine. I need to do a function query (I believe) to filter the
> > results so they are within a certain distance of a point. For this, I
> > understand I should use something like sqedist or hsin, and from the
> > documentation on the FunctionQuery page, I believe that the function
> > is executed on every "row" (or "record", not sure what the proper term
> > for this is). So, my question is threefold really; are those functions
> > the ones I should be using to perform a search where distance is one
> > of the criteria (there are others),
>
> Short answer: yes.  Long answer:  I just committed those functions this week.  I believe they are good, but feedback is encouraged.

I'll be sure to let you know if I find anything report-worthy :)
They're definitely super-useful for people doing similar things to I
though, so great work :)

> > and if so, does Solr execute the
> > query on every row (and again, if so, is there any way of preventing
> > this [like subqueries, though I know they're not supported])?
>
> You can use the frange capability to filter first.  See http://www.lucidimagination.com/blog/tag/frange/

Thanks for the link. I'll definitely do that. Does Solr execute the
function on every row in the database on every query otherwise?

>
> Here's an example from a soon to be published article I'm writing:
> http://localhost:8983/solr/select/?q=*:*&amp;fq={!frange l=0 u=400}hsin(0.57, -1.3, lat_rad, lon_rad,  3963.205)
>
> This should filter out all documents that are beyond 400 miles in distance from that point on a sphere (specified in radians, see also the rads() method)
>
>
>
> >
> > Sorry if this is a little confusing… any help would be greatly appreciated :)
>
> No worries, a lot of this spatial stuff is still being ironed out.  See https://issues.apache.org/jira/browse/SOLR-773 for the issue that is tracking all of the related issues.  The pieces are starting to come together and I'm pretty excited about it b/c not only will it bring native spatial support to Solr, it will also give Solr some exciting new general capabilities (sort by function, pseudo-fields, facet by function, etc.)

Re: Function queries question

Posted by Grant Ingersoll <gs...@apache.org>.
On Nov 20, 2009, at 3:15 AM, Oliver Beattie wrote:

> Hi all,
> 
> I'm a relative newcomer to Solr, and I'm trying to use it in a project
> of mine. I need to do a function query (I believe) to filter the
> results so they are within a certain distance of a point. For this, I
> understand I should use something like sqedist or hsin, and from the
> documentation on the FunctionQuery page, I believe that the function
> is executed on every "row" (or "record", not sure what the proper term
> for this is). So, my question is threefold really; are those functions
> the ones I should be using to perform a search where distance is one
> of the criteria (there are others),

Short answer: yes.  Long answer:  I just committed those functions this week.  I believe they are good, but feedback is encouraged.

> and if so, does Solr execute the
> query on every row (and again, if so, is there any way of preventing
> this [like subqueries, though I know they're not supported])?

You can use the frange capability to filter first.  See http://www.lucidimagination.com/blog/tag/frange/

Here's an example from a soon to be published article I'm writing:
http://localhost:8983/solr/select/?q=*:*&amp;fq={!frange l=0 u=400}hsin(0.57, -1.3, lat_rad, lon_rad,  3963.205)

This should filter out all documents that are beyond 400 miles in distance from that point on a sphere (specified in radians, see also the rads() method)
          


> 
> Sorry if this is a little confusing… any help would be greatly appreciated :)

No worries, a lot of this spatial stuff is still being ironed out.  See https://issues.apache.org/jira/browse/SOLR-773 for the issue that is tracking all of the related issues.  The pieces are starting to come together and I'm pretty excited about it b/c not only will it bring native spatial support to Solr, it will also give Solr some exciting new general capabilities (sort by function, pseudo-fields, facet by function, etc.)