SOLR4 Spatial sorting and query string

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

SOLR4 Spatial sorting and query string

roySolr
Hello,

I use the following distance sorting of SOLR 4(solr.SpatialRecursivePrefixTreeFieldType):

fl=*,score&sort=score asc&q={!geofilt score=distance filter=false sfield=coords pt=54.729696,-98.525391 d=10}  

(from the tutorial on http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4)

Now i want to query on a searchstring and still want to sort on distance. How can i combine this in above solr request? When i add something to the "q=" it doesn't work. I tried _query_ subquery and other stuff but i don't get it working

I appreciate any help,
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: SOLR4 Spatial sorting and query string

David Smiley
Hi Roy.

Using the example schema and data, and copying the "store" field to "store_rpt" indexed with location_rpt field type, try this query:

http://localhost:8983/solr/select?indent=true&fl=name,store&q=*:*&sort=query%28{!geofilt%20score=distance%20filter=false%20sfield=store_rpt%20pt=45.15,-93.85%20d=0%20v=%27%27}%29%20asc

sort spec without url encoding:  query({!geofilt score=distance filter=false sfield=store_rpt d=0 v=''}) asc

One of the tricks there is that it's sorting on the query() function query, which references a query that has its score used as the result of query().  And you put a spatial query in there (note: score=distance only works with rpt), and voila.  The fact that v='' is needed appears to be a Solr bug.  I realize this is super awkward, so this approach isn't well documented if at all.  In Solr 4.5 you can simply use geodist().

Note: if you have only one point per document, I recommend sorting by LatLonType.

~ David

roySolr wrote
Hello,

I use the following distance sorting of SOLR 4(solr.SpatialRecursivePrefixTreeFieldType):

fl=*,score&sort=score asc&q={!geofilt score=distance filter=false sfield=coords pt=54.729696,-98.525391 d=10}  

(from the tutorial on http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4)

Now i want to query on a searchstring and still want to sort on distance. How can i combine this in above solr request? When i add something to the "q=" it doesn't work. I tried _query_ subquery and other stuff but i don't get it working

I appreciate any help,
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: SOLR4 Spatial sorting and query string

roySolr
This post was updated on .
Great, it works very well. I use multiple points per document so i need this solution.
In solr 4.5 i will use geodist() again!

Thanks David
Reply | Threaded
Open this post in threaded view
|

Re: SOLR4 Spatial sorting and query string

roySolr
Hello,

I have a question about performance with a lot of points and spatial search.
First i will explain my situation:

We have some products data and want to store every geo location of stores that sells this product.
I use a multivalued coordinates field with the geo data:

<arr name="store_coordinates">
 <str>lat,long</str>
 <str>lat,long</str>
 <str>lat,long</str>
 <str>lat,long</str> 
 <str>lat,long</str>
</arr>

The config:

<field name="store_coordinates" type="location_rpt" indexed="true" stored="true" multiValued="true"/>

<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType" distErrPct="0.025" maxDistErr="0.000009" units="degrees"/>


When i search for a product term i want only the products that are nearby the given location. So i used to following query:

fq=_query_:"{!geofilt sfield=store_coordinates pt=locatonlat,locationlong d=25}"

It works great but my question is: Will it work quick and smooth with +1000 stores in my store_coordinates field?

Any help is appreciated
Thanks,

Roy
Reply | Threaded
Open this post in threaded view
|

Re: SOLR4 Spatial sorting and query string

David Smiley
Roy,

How fast/slow this is is dependent on the total number of points in
documents that match the search results.  If one of those documents has
1000 points but most have a handful then it isn't such a big deal.  The
bigger problem is: https://issues.apache.org/jira/browse/LUCENE-4698

~ David

On 8/14/13 6:45 AM, "roySolr" <[hidden email]> wrote:

>Hello,
>
>I have a question about performance with a lot of points and spatial
>search.
>First i will explain my situation:
>
>We have some products data and want to store every geo location of stores
>that sells this product.
>I use a multivalued coordinates field with the geo data:
>
><arr name="store_coordinates">
> <str>lat,long</str>
> <str>lat,long</str>
> <str>lat,long</str>
> <str>lat,long</str>
> <str>lat,long</str>
></arr>
>
>The config:
>
>*<field name="store_coordinates" type="location_rpt" indexed="true"
>stored="true" multiValued="true"/>
>
><fieldType name="location_rpt"
>class="solr.SpatialRecursivePrefixTreeFieldType" distErrPct="0.025"
>maxDistErr="0.000009" units="degrees"/>*
>
>When i search for a product term i want only the products that are nearby
>the given location. So i used to following query:
>
>fq=_query_:"{!geofilt sfield=store_coordinates pt=locatonlat,locationlong
>d=25}"
>
>It works great but my question is: Will it work quick and smooth with
>+1000
>stores in my store_coordinates field?
>
>Any help is appreciated
>Thanks,
>
>Roy
>
>
>
>--
>View this message in context:
>http://lucene.472066.n3.nabble.com/SOLR4-Spatial-sorting-and-query-string-
>tp4084318p4084521.html
>Sent from the Solr - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: SOLR4 Spatial sorting and query string

roySolr
This post was updated on .
Hello David,

The first months there will be not that many points in a doc, i will keep the topic in mind!

The next step is that i want to now which location matched my query. Example:

Product A is available in 3 stores, the doc looks like this:

<doc>
<str name="productname">Product A</str>
<arr name='store_coordinates'>
  <str>store1_geo</str>
  <str>store2_geo</str>
  <str>store3_geo</str>
</arr>
<arr name="storeinfo">
<str>London#store1_geo</str>
<str>Amsterdam#store2_geo</str>
<str>New York#store3_geo</str>
</arr>
</doc>


I query the index with my location set to Berlin and a radius of 250km. I know that this result gets back on the first place because it's close to Amsterdam(store2_geo). But normally, How can i know which one matched my query as closest point? Is it possible to get this back? I can do it in my application but with 200 stores in a doc i don't think it's the best solution.

Thanks,

Roy
Reply | Threaded
Open this post in threaded view
|

Re: SOLR4 Spatial sorting and query string

David Smiley
Hi Roy,

You'll have to calculate this client-side.  I am aware of this conundrum and I put up a TODO JIRA item for it here months ago:  https://issues.apache.org/jira/browse/SOLR-4633    It actually shouldn't be that hard to do.

~ David

roySolr wrote
Hello David,

The first months there will be not that many points in a doc, i will keep the topic in mind!

The next step is that i want to now which location matched my query. Example:

Product A is available in 3 stores, the doc looks like this:

<doc>
<str name="productname">Product A</str>
<arr name='store_coordinates'>
  <str>store1_geo</str>
  <str>store2_geo</str>
  <str>store3_geo</str>
</arr>
<arr name="storeinfo">
<str>London#store1_geo</str>
<str>Amsterdam#store2_geo</str>
<str>New York#store3_geo</str>
</arr>
</doc>


I query the index with my location set to Berlin and a radius of 250km. I know that this result gets back on the first place because it's close to Amsterdam(store2_geo). But normally, How can i know which one matched my query as closest point? Is it possible to get this back? I can do it in my application but with 200 stores in a doc i don't think it's the best solution.

Thanks,

Roy
Reply | Threaded
Open this post in threaded view
|

Re: SOLR4 Spatial sorting and query string

Billnbell
David,

We noticed in 4.5 that "sort=geodist(store_geohash) asc" does not work
anymore. It works only if we: "sfield=store_geohash&sort=geodist() asc"

Thanks.


On Thu, Aug 15, 2013 at 9:10 AM, David Smiley (@MITRE.org) <
[hidden email]> wrote:

> Hi Roy,
>
> You'll have to calculate this client-side.  I am aware of this conundrum
> and
> I put up a TODO JIRA item for it here months ago:
> https://issues.apache.org/jira/browse/SOLR-4633    It actually shouldn't
> be
> that hard to do.
>
> ~ David
>
>
> roySolr wrote
> > Hello David,
> >
> > The first months there will be not that many points in a doc, i will keep
> > the topic in mind!
> >
> > The next step is that i want to now which location matched my query.
> > Example:
> >
> > Product A is available in 3 stores, the doc looks like this:
> /
> > <doc>
> > <str name="productname">
> > Product A
> > </str>
> > <arr name='store_coordinates'>
> >
> > <str>
> > store1_geo
> > </str>
> >
> > <str>
> > store2_geo
> > </str>
> >
> > <str>
> > store3_geo
> > </str>
> > </arr>
> > <arr name="storeinfo">
> > <str>
> > London#store1_geo
> > </str>
> > <str>
> > Amsterdam#store2_geo
> > </str>
> > <str>
> > New York#store3_geo
> > </str>
> > </arr>
> > </doc>
> /
> >
> > I query the index with my location set to Berlin and a radius of 250km. I
> > know that this result gets back on the first place because it's close to
> > Amsterdam(store2_geo). But normally, How can i know which one matched my
> > query as closest point? Is it possible to get this back? I can do it in
> my
> > application but with 200 stores in a doc i don't think it's the best
> > solution.
> >
> > Thanks,
> >
> > Roy
>
>
>
>
>
> -----
>  Author:
> http://www.packtpub.com/apache-solr-3-enterprise-search-server/book
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/SOLR4-Spatial-sorting-and-query-string-tp4084318p4084816.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>



--
Bill Bell
[hidden email]
cell 720-256-8076
Reply | Threaded
Open this post in threaded view
|

Re: SOLR4 Spatial sorting and query string

David Smiley
This is a known limitation.  From CHANGES.txt:
* SOLR-2345: Enhanced geodist() to work with an RPT field, provided that the
  field is referenced via 'sfield' and the query point is constant.
  (David Smiley)

The reason why that limitation is there relates to the fact that the function query parser will attempt to resolve the field name if it's referenced as an argument, and that'll fail because you can't get a ValueSource from an RPT field because a ValueSource is a single-valued construct and RPT isn't limited in that way

~ David

Billnbell wrote
David,

We noticed in 4.5 that "sort=geodist(store_geohash) asc" does not work
anymore. It works only if we: "sfield=store_geohash&sort=geodist() asc"

Thanks.