简体   繁体   中英

Searching locations in Solr

I have four pieces of data that I want to make searchable.

Town, City, Postcode, Country

What is the best way that I can make these results searchable by any of the following ways:

  • London, England
  • Swindon, Wiltshire, England
  • Wiltshire, England
  • England
  • Wiltshire
  • Swindon

I could normalise the data, but then I would get duplicate results if someone searched for simply "London".

If I had only "London, England" stored, but not just "London", then if someone searched for "London" it wouldnt find any results.

Its a catch22. How should one store addresses to allow flexibility when the user is searching?

The best approach would be to use solr spatial search features http://wiki.apache.org/solr/SpatialSearch/ but that would require access to a mapping data service which could return the latitude / longitude of the location and store that with the solr record. Then do the same lookup on searching to get the latitude / longitude and you will be able to do radius searches and get much more accurate results compared to text searching on locations.

is best to follow the suggestion of the previous answer. you should add a field location and configure schema.xml

added to the section <fieldType>

 <fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>

added to the section <field>

<field name="location" type="location" indexed="true" stored="true" required="true" />

 <dynamicField name="*_coordinate"  type="tdouble" indexed="true"  stored="false"/> 

Now update your index solr/dataimport?command=delta-import

can make your query &q= : &fq={!geofilt pt=45.15,-93.85 sfield=store d=5}

http://wiki.apache.org/solr/SpatialSearch http://wiki.apache.org/solr/SpatialSearchDev

If you don't have the geospatial data available you could give Herarchical Faceting a try. It indexes the data in a specific manner, allowing queries within a hierarchy, eg:

Document: England > London > Chelsea

Index: 0/England, 1/England/London, 2 England/London/Chelsea

Query: facet.field = category, facet.prefix = 1/London, facet.mincount = 1

There is some redundancy in the index, but it should be negligable in most cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM