apache solr v4 spatial search
TRANSCRIPT
Apache Solr v4Geo Spatial Search
@mknkisk
13年7月21日日曜日
Geo Spatial Search
位置情報(緯度経度)を使った検索
店舗検索
ナビゲーションサービス
13年7月21日日曜日
Geo Spatial Search
Google MapFoursquare
13年7月21日日曜日
Solr v3 => v4
v3 でも空間検索はサポート
v4.3.1 では v3 形式もサポート
v4.3.1 時点での example の schema.xml
はまだ v3 の空間検索方式
13年7月21日日曜日
Solr v3 => v4
Solr v4 で検索/設定方法が変更
fieldType の追加 (location_rpt)
geodist() の使用を非推奨
13年7月21日日曜日
Dependency library
空間検索ロジックは OSS の spatial4j
solr.war に入ってる
ポリゴンを検索したい場合
jts.jar が必要
solr.war には入ってない
13年7月21日日曜日
Put jts.jar in solr.war
jts.jar をダウンロード
http://sourceforge.net/projects/jts-topo-suite/
solr.war を解凍
WEB-INF/lib 配下に jts.jar を配置
solr.war に再度アーカイブ
13年7月21日日曜日
Put jts.jar in solr.war
http://stackoverflow.com/questions/13282014/how-to-install-spatial4j-into-solr4
13年7月21日日曜日
MEMO
JTS The JTS Topology Suite is an API for modelling and manipulating 2-dimensional linear geometry.
WKT (Well Known Text)Well-known text (WKT) is a text markup language for representing vector geometry objects on a map, spatial reference systems of spatial objects and transformations between spatial reference systems.
13年7月21日日曜日
Example: schema.xml
<types>....
<fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType"
geo="true" distErrPct="0.025"maxDistErr="0.000009" units="degrees" />
....</types>
13年7月21日日曜日
Example: schema.xml
<fields>....<field name="store" type="location_rpt"
indexed="true" stored="true"/>....
</fields>
13年7月21日日曜日
Example: schema.xml
solr.war/example/solr/collection1/conf/schema.xml の設定
WGS84 (世界測地系)
単位: degrees (度分秒)
13年7月21日日曜日
Example: schema.xml
Solr Wiki を見てるとWGS84以外は注意点が多そう
Indexing時にWGS84に変換してやるのが良さそう
13年7月21日日曜日
Example: Indexing (Point)
金閣寺
<field name=”store”>135.729 35.039</field>
銀閣寺
<field name=”store”>135.798 35.026</field>
京都駅
<field name=”store”>135.757 34.986</field>
13年7月21日日曜日
Example: Indexing (Python)
import pysolr
def main(): solr = pysolr.Solr('http://localhost:8983/solr/', timeout=10) solr.add([ { "id": "1", "name": u"金閣寺", "store": "135.729 35.039" }, { "id": "2", "name": u"銀閣寺", "store": "135.798 35.026" }, { "id": "3", "name": u"京都駅", "store": "135.757 34.986" } ]) solr.optimize()
if __name__ == '__main__': main()
13年7月21日日曜日
Example: Searching
京都駅を中心, 周辺10km, キーワード: “寺”
http://localhost:8983/solr/collection1/select?
q={!geofilt score=distance sfield=store pt=34.986,2C135.757 d=10}&fq=name:寺&sort=score asc&fl=*,score
13年7月21日日曜日
Example: Searching
docs: [ { id: "2", store: "135.798 35.026", name: "銀閣寺",
score: 0.052228004 }, { id: "1", store: "135.729 35.039", name: "金閣寺",
score: 0.057749357 }]
score が中心点からの距離(distance)
単位は degrees
13年7月21日日曜日
Units, Conversion
距離の単位変換はSolr Wikiを参考にhttp://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4#Units.2C_Conversion
Degrees to kilometers:degrees * 111.1951
Degrees to miles:degrees * 69.09341
13年7月21日日曜日
More Information
Solr Wiki: Spatial Searchhttp://wiki.apache.org/solr/SpatialSearch
Solr Wiki: Lucene / Solr 4 Spatialhttp://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4
Github: spatial4jhttps://github.com/spatial4j/spatial4j
13年7月21日日曜日