You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by Apache Wiki <wi...@apache.org> on 2010/10/01 00:15:14 UTC

[Solr Wiki] Trivial Update of "SpatialSearch" by YonikSeeley

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.

The "SpatialSearch" page has been changed by YonikSeeley.
The comment on this change is: more geodist, returning distance.
http://wiki.apache.org/solr/SpatialSearch?action=diff&rev1=35&rev2=36

--------------------------------------------------

  Since the !LatLonType field also supports field queries and range queries, so one can manually create their own bounding box rather than using bbox:
     [[http://localhost:8983/solr/select?wt=json&indent=true&fl=name,store&q=*:*&fq=store:[45,-94%20TO%2046,-93]|...&q=*:*&fq=store:[45,-94 TO 46,-93] ]]
  
- == geodist - the distance function ==
+ == geodist - The distance function ==
  
  '''geodist''' is a function query that yields the calculated distance.  This gives the flexibility to do a number of interesting things, such as sorting by the distance (Solr can sort by any function query), or combining the distance with the relevancy score, such as boosting by the inverse of the distance.
  
- Here's an example of sorting by distance:
+ Here's an example of sorting by distance ascending:
  
     [[http://localhost:8983/solr/select?wt=json&indent=true&fl=name,store&q=*:*&sfield=store&pt=45.15,-93.85&sort=geodist%28%29%20asc|...&q=*:*&sfield=store&pt=45.15,-93.85&sort=geodist() asc]]
  
+ Or you could use the distance function as the main query (or part of it) to get the distance as the document score:
  
- = EDITING IN PROGRESS - ANYTHING BELOW THIS LINE MAY NOT BE ACCURATE =
+    [[http://localhost:8983/solr/select?wt=json&indent=true&fl=name,store,score&q={!func}geodist%28%29&sfield=store&pt=45.15,-93.85&sort=score+asc|...&q={!func}geodist()&sfield=store&pt=45.15,-93.85&sort=score asc]]
+ 
+ == Returning the distance ==
+ Returning distances (and any arbitrary function query value) is currently under development.
+ As a temporary workaround, it's possible to obtain distances by using geodist or geofilt as only scoring part of the main query.
+  
  
  
+ = Further Details - Under Development =
- = An Example =
- On https://issues.apache.org/jira/browse/SOLR-1131, the example schema was changed to provide information about what store the products were located in.
- 
- The schema changes look like:
- 
- {{{
- <fieldType name="location" class="solr.PointType" dimension="2" subFieldType="double"/>
- 
- <field name="store" type="location" indexed="true" stored="true"/>
- }}}
- In the example docs, for example: hd.xml, the document now has:
- 
- {{{
-   <field name="store">45.17614,-93.87341</field>
- }}}
- in addition to all the other fields.
- 
- Then, to query, the system can use the distance Functions in Solr, as in:
- 
- {{{
- http://localhost:8983/solr/select/?q=_val_:"recip(dist(2, store, vector(34.0232,-81.0664)),1,1,0)"&fl=*,score
- }}}
- The above computes the [[http://wiki.apache.org/solr/FunctionQuery#dist|the Euclidean distance]] from the point (34.0232,-81.0664) to the store's point, asking SOLR to [[http://wiki.apache.org/solr/FunctionQuery#recip|invert the distance]] (take 1 / the distance) in order to make longer distances come later in the result list, and finally asking SOLR to return all fields, including the relevancy score.
- 
- = Data Representation =
- One of the keys to data representation is the ability to represent points, etc. in multiple different ways.  Some times, a user may want a [[http://en.wikipedia.org/wiki/Geohash|Geohash]] and other times they may want a Latitude/Longitude (LatLonType) point or just simple point (!PointType) in an n-dimensional rectangular coordinate system.
- 
- == Points ==
- === Numerics ===
- The Trie* fields are perfect for representing lat/lon in two distinct fields.  Additionally, as of https://issues.apache.org/jira/browse/SOLR-1131, there is now a !PointType that supports transparently representing a point in n-dimensional space in a rectangular coordinate system.  Thus, the !PointType might not be appropriate if distance along a sphere or ellipse are desired.
  
  ==== Example ====
  {{{