Solr: Spatial Search

1. schema

<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
        geo="true" distErrPct="0.025" maxDistErr="0.001"  distanceUnits="kilometers"/>
<field name="location_rpt" type="location_rpt" indexed="true" stored="true" multiValued="true"/>

data import

扫描二维码关注公众号,回复: 529594 查看本文章
select id, name, latitude, longtitude,CONCAT_WS(',',longtitude,latitude) as location_rpt, commodities, credit, created_at from seller

There is a error when import data from mysql to solr

WARN  - 2015-06-26 06:37:30.819; [   testcore2] org.apache.solr.handler.dataimport.SolrWriter; Error creating document : SolrInputDocument(fields: [id=5, name=红旗连锁, created_at=2015-06-18 15:34:34.0, longtitude=104.072276, commodities=烟、酒、饮料、零食、茶叶, latitude=30.550858, credit=90, location_rpt=104.072276,30.550858, _version_=1505021815232135168])
org.apache.solr.common.SolrException: Can't parse point '104.072276,30.550858' because: Bad Y value 104.072276 is not in boundary Rect(minX=-180.0,maxX=180.0,minY=-90.0,maxY=90.0)

solution:

select id, name, latitude, longtitude,CONCAT_WS(',',latitude,longtitude) as location_rpt, commodities, credit, created_at from seller

change latitude,longtitude two fields places to statisfy the command

Points are indexed just as they are in Solr 3 spatial:

     <field name="geo">43.17614,-90.57341</field> 

If a comma is omitted, then it is in x-y (lon-lat) order:

     <field name="geo">-90.57341 43.17614</field>

"lon lat" or "lat,lon" format     {!geofilt}&sfield=location_rpt&pt=30.55078,104.072941&d=2&sort=geodist() asc   ----------------------------- add JTS #cp jts-1.13.jar  /path/to/WEB-INF/lib #cd /path/to/WEB-INF/lib jar -uf /opt/solr/server/webapps/solr.war WEB-INF/lib/jts-1.13.jar      

http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4

猜你喜欢

转载自ylzhj02.iteye.com/blog/2222303