-->

Sunspot geospatial search ERROR:unknown field '

2019-05-13 19:59发布

问题:

I've been trying to integrate geospatial search into my rails app for a few days now, but keep getting this error when I run rake sunspot:solr:reindex

RSolr::Error::Http - 400 Bad Request
Error: ERROR:unknown field 'location_ll'

Request Data: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><add><doc><field name=\"id\">Place 1</field><field   name=\"type\">Place</field><field name=\"type\">ActiveRecord::Base</field><field name=\"class_name\">Place</field><field name=\"location_ll\">42.348065,-71.083623</field></doc> #etc... keeps going on for all the objects/fields being indexed in the table

As far as I can tell I'm doing everything correctly as search and indexing works when I comment out the latlon(:location) line in my model, but don't know if its a bug or if I'm missing something. Below is the setup I'm currently using:

rails 3.2.1 ruby 1.9.2p318

Gems sunspot (2.0.0.pre.120417) sunspot_rails (2.0.0.pre.120417) sunspot_solr (2.0.0.pre.120417)

:latitude and :longitude are both in float format

Place model

searchable do
text :name
latlon(:location) { Sunspot::Util::Coordinates.new(self.latitude, self.longitude) }
end

I've tried variations in the Sunspot::Util::Coordinates.new, including (lat, lon) and (latitude, longitude)

I took a look at https://github.com/sunspot/sunspot/issues/203 and as per the suggestions, stopped my sunspot server, deleted the solr folder, deleted the sunspot.yml, reinstalled, and restarted, but am still getting the error. Any ideas? Thank you very much!

回答1:

Make sure schema.xml in the solr folder matches the latest one from here:

https://github.com/sunspot/sunspot/blob/master/sunspot_solr/solr/solr/conf/schema.xml

Still not working on my localhost, but it is on production



回答2:

If you're using websolr you'll need to make sure you set your index type to Sunspot 2.0 for Ruby on Rails (Solr 3). Mine was defaulted to Sunspot 1.3.x for Ruby on Rails, and this was causing the unknown field 'location_ll' error.

I'm using the Heroku addon, and for that you can set the index type by running:

$ heroku addons:open websolr 

Then clicking on your index (probably default), and selecting from the drop down and hitting change:



回答3:

Also make sure that schema.xml is loaded from your solr directory, not from default's gem's directory.