lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Grant Ingersoll <>
Subject Re: Function queries question
Date Mon, 23 Nov 2009 13:48:10 GMT

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


View raw message