Slide 1

Slide 1 text

Apache Solr v4 Geo Spatial Search @mknkisk 13೥7݄21೔೔༵೔

Slide 2

Slide 2 text

Geo Spatial Search Ґஔ৘ใ(Ң౓ܦ౓)Λ࢖ͬͨݕࡧ ళฮݕࡧ φϏήʔγϣϯαʔϏε 13೥7݄21೔೔༵೔

Slide 3

Slide 3 text

Geo Spatial Search Google Map Foursquare 13೥7݄21೔೔༵೔

Slide 4

Slide 4 text

Solr v3 => v4 v3 Ͱ΋ۭؒݕࡧ͸αϙʔτ v4.3.1 Ͱ͸ v3 ܗࣜ΋αϙʔτ v4.3.1 ࣌఺Ͱͷ example ͷ schema.xml ͸·ͩ v3 ͷۭؒݕࡧํࣜ 13೥7݄21೔೔༵೔

Slide 5

Slide 5 text

Solr v3 => v4 Solr v4 Ͱݕࡧ/ઃఆํ๏͕มߋ fieldType ͷ௥Ճ (location_rpt) geodist() ͷ࢖༻Λඇਪ঑ 13೥7݄21೔೔༵೔

Slide 6

Slide 6 text

Dependency library ۭؒݕࡧϩδοΫ͸ OSS ͷ spatial4j solr.war ʹೖͬͯΔ ϙϦΰϯΛݕࡧ͍ͨ͠৔߹ jts.jar ͕ඞཁ solr.war ʹ͸ೖͬͯͳ͍ 13೥7݄21೔೔༵೔

Slide 7

Slide 7 text

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೔೔༵೔

Slide 8

Slide 8 text

Put jts.jar in solr.war http://stackoverflow.com/questions/ 13282014/how-to-install-spatial4j-into- solr4 13೥7݄21೔೔༵೔

Slide 9

Slide 9 text

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೔೔༵೔

Slide 10

Slide 10 text

Example: schema.xml .... <fieldType name="location_rpt" class="solr.SpatialRecursivePrefixTreeFieldType" geo="true" distErrPct="0.025" maxDistErr="0.000009" units="degrees" /> .... 13೥7݄21೔೔༵೔

Slide 11

Slide 11 text

Example: schema.xml <fields> .... <field name="store" type="location_rpt" indexed="true" stored="true"/> .... fields> 13೥7݄21೔೔༵೔

Slide 12

Slide 12 text

Example: schema.xml solr.war/example/solr/collection1/conf/ schema.xml ͷઃఆ WGS84 (ੈքଌ஍ܥ) ୯Ґ: degrees (౓෼ඵ) 13೥7݄21೔೔༵೔

Slide 13

Slide 13 text

Example: schema.xml Solr Wiki ΛݟͯΔͱWGS84Ҏ֎͸஫ ҙ఺͕ଟͦ͏ Indexing࣌ʹWGS84ʹม׵ͯ͠΍Δͷ ͕ྑͦ͞͏ 13೥7݄21೔೔༵೔

Slide 14

Slide 14 text

Example: Indexing (Point) ֳۚࣉ <field name=”store”>135.729 35.039field> ֳۜࣉ <field name=”store”>135.798 35.026field> ژ౎Ӻ <field name=”store”>135.757 34.986field> 13೥7݄21೔೔༵೔

Slide 15

Slide 15 text

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೔೔༵೔

Slide 16

Slide 16 text

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೔೔༵೔

Slide 17

Slide 17 text

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೔೔༵೔

Slide 18

Slide 18 text

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೔೔༵೔

Slide 19

Slide 19 text

More Information Solr Wiki: Spatial Search http://wiki.apache.org/solr/SpatialSearch Solr Wiki: Lucene / Solr 4 Spatial http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4 Github: spatial4j https://github.com/spatial4j/spatial4j 13೥7݄21೔೔༵೔