lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Solr Wiki] Update of "SpatialSearch" by GrantIngersoll
Date Thu, 21 Oct 2010 18:04:57 GMT
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 GrantIngersoll.
http://wiki.apache.org/solr/SpatialSearch?action=diff&rev1=39&rev2=40

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

  <!> [[Solr4.0]]
+ 
  = Spatial Search =
  <<TableOfContents(3)>>
  
@@ -15, +16 @@

  '''NOTE: Unless otherwise specified, all units of distance are kilometers and points are
in degrees of latitude,longitude.'''
  
  = QuickStart =
- If you haven't already, get a recent nightly build of [[Solr4.0]], start the example server
and index the example data as shown in the [[http://lucene.apache.org/solr/tutorial.html|solr
tutorial]].  With the Solr server running, you should be able to
+ If you haven't already, get a recent nightly build of [[Solr4.0]], start the example server
and index the example data as shown in the [[http://lucene.apache.org/solr/tutorial.html|solr
tutorial]].  With the Solr server running, you should be able to click on the example links
and see real responses.
- click on the example links and see real responses.
  
  In the example data, certain documents have a field called "store" (with a fieldType named
"location" implemented via !LatLonType).  Some of the points in the example data are:
+ 
  {{{
  <field name="store">45.17614,-93.87341</field>  <!-- Buffalo store -->
  <field name="store">40.7143,-74.006</field>     <!-- NYC store -->
  <field name="store">37.7752,-122.4232</field>   <!-- San Francisco store
-->
  }}}
- 
  == geofilt - The distance filter ==
  Now let's assume that we are at '''45.15,-93.85''' (which happens to be 3.437 km from the
Buffalo store).  We can use a '''geofilt''' filter to find all products (documents in our
index) with the field '''store''' within '''5km''' of our position:
  
-    [[http://localhost:8983/solr/select?wt=json&indent=true&fl=name,store&q=*:*&fq={!geofilt%20pt=45.15,-93.85%20sfield=store%20d=5}|...&q=*:*&fq={!geofilt
pt=45.15,-93.85 sfield=store d=5}]]
+  . [[http://localhost:8983/solr/select?wt=json&indent=true&fl=name,store&q=*:*&fq={!geofilt%20pt=45.15,-93.85%20sfield=store%20d=5}|...&q=*:*&fq={!geofilt
pt=45.15,-93.85 sfield=store d=5}]]
  
  Sure enough, we find 8 products at the Buffalo store:
+ 
  {{{
  ...
    "response":{"numFound":8,"start":0,"docs":[
@@ -42, +43 @@

          "store":"45.17614,-93.87341"},
  ...
  }}}
- 
  == Spatial Query Parameters ==
  The main spatial search related queries, '''geofilt''', '''bbox''', and '''geodist''' default
to looking for normal request parameters, so any of '''pt''', '''sfield''', and '''dist'''
may be factored out and only specified once in a request (even if multiple spatial queries
are used).
  
  Examples:
+ 
-  *  [[http://localhost:8983/solr/select?wt=json&indent=true&fl=name,store&q=*:*&fq={!geofilt%20sfield=store}&pt=45.15,-93.85&d=5|...&q=*:*&fq={!geofilt
sfield=store}&pt=45.15,-93.85&d=5]]
+  * [[http://localhost:8983/solr/select?wt=json&indent=true&fl=name,store&q=*:*&fq={!geofilt%20sfield=store}&pt=45.15,-93.85&d=5|...&q=*:*&fq={!geofilt
sfield=store}&pt=45.15,-93.85&d=5]]
-  *  [[http://localhost:8983/solr/select?wt=json&indent=true&fl=name,store&q=*:*&fq={!geofilt}&sfield=store&pt=45.15,-93.85&d=5|...&q=*:*&fq={!geofilt}&sfield=store&pt=45.15,-93.85&d=5]]
+  * [[http://localhost:8983/solr/select?wt=json&indent=true&fl=name,store&q=*:*&fq={!geofilt}&sfield=store&pt=45.15,-93.85&d=5|...&q=*:*&fq={!geofilt}&sfield=store&pt=45.15,-93.85&d=5]]
  
  == bbox - Bounding-box filter ==
- Exact distance calculations can be somewhat expensive and it can often make sense to use
a quick approximation instead.
- The '''bbox''' filter is guaranteed to encompass all of the points of interest, but it may
also include other points that are slightly outside of the required distance.  For our standard
!LatLonType, this is implemented as a bounding box - a box made up of a range of lattitudes
and longitudes that encompasses the circle of radius '''d''' (i.e. it will select the same
or slightly more documents than '''geofilt''' will).
+ Exact distance calculations can be somewhat expensive and it can often make sense to use
a quick approximation instead. The '''bbox''' filter is guaranteed to encompass all of the
points of interest, but it may also include other points that are slightly outside of the
required distance.  For our standard !LatLonType, this is implemented as a bounding box -
a box made up of a range of lattitudes and longitudes that encompasses the circle of radius
'''d''' (i.e. it will select the same or slightly more documents than '''geofilt''' will).
  
  The parameters are exactly the same as '''geofilt''', so the following request will still
match everything in the Buffalo store:
+ 
-    [[http://localhost:8983/solr/select?wt=json&indent=true&fl=name,store&q=*:*&fq={!bbox}&sfield=store&pt=45.15,-93.85&d=5|...&q=*:*&fq={!bbox}&sfield=store&pt=45.15,-93.85&d=5]]
+  . [[http://localhost:8983/solr/select?wt=json&indent=true&fl=name,store&q=*:*&fq={!bbox}&sfield=store&pt=45.15,-93.85&d=5|...&q=*:*&fq={!bbox}&sfield=store&pt=45.15,-93.85&d=5]]
  
  Because the bounding box is less selective, if we change our distance to 3km it will still
include the Buffalo store (which is actually 3.437 km away).  If we used the more accurate
'''geofilt''' at 3km, these documents not match.  There are many scenarios when the bounding
box can make sense though - especially if you are sorting by some other criteria anyway, or
sorting by distance itself.
  
  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] ]]
+  . [[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''' 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 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]]
+  . [[http://localhost:8983/solr/select?wt=json&indent=true&fl=name,store&q=*:*&sfield=store&pt=45.15,-93.85&sort=geodist()%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:
  
-    [[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]]
+  . [[http://localhost:8983/solr/select?wt=json&indent=true&fl=name,store,score&q={!func}geodist()&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
the only scoring part of the main query.
- 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 the only scoring part of the main query.
-  
  
+ = Advanced Spatial Options - Under Development =
+ SpatialSearchDev  -- Covers things like Geohash, North/South Pole issues, other distance
functions, etc.
  
- = Further Details - Under Development =
- SpatialSearchDev
- 

Mime
View raw message