sunspot solr undefined field type

血红的双手。 提交于 2019-12-02 04:06:19

问题


I'm having a problem with my sunspot and solr. In development it worked like charme but in production I get the following error out of my rails production log:

RSolr::RequestError (Solr Response: undefined field type): app/controllers/search_controller.rb:7:in `index'

I guess it has something to do with the schema.xml. But I'm quite new to solr. So can anybody help me?

OK:
Controller

def index
 unless params[:q].blank?
  @search = Question.search do
    fulltext params[:q]
  end
  @results = @search.results

else
  @results = nil
end
@searchterm = params[:q]

end

model (Question)

...

searchable do
  text :title 
  text :content
end

回答1:


It sounds like your production Solr instance is not using Sunspot's schema.xml.

The type field should defined in Sunspot's standard schema.xml, and it is used to index the model name of the object, for later use in filtering your searches. Seeing an error message saying that type is undefined is what implies to me that you're using a schema.xml other than Sunspot's.

It could be that you're using some other sample or default set of configurations from the method you used to install Solr on your server. If you can, please elaborate on how you set up your production Solr server.




回答2:


For Solr 4.7, copy schema.xml and solrconfig.xml from your_app/solr/conf to /opt/solr/solr/collection1 (or whatever your solr path is) and if still not working, make sure that your config/sunspot.yml is something like:

production:
  solr:
    hostname: localhost
    port: 8983
    log_level: WARNING
    path: /solr/collection1
    # read_timeout: 2
    # open_timeout: 0.5

It is recommended to create another core (my_core) from the solr web interface, copy schema.xml and solrconfig.xml to that folder and point path to /solr/my_core




回答3:


Make sure to set the field type to required="true" in your schema.xml or reindexing will not include the field "type" in your indexed data.

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



回答4:


For me it was in Heroku addon Websolr dashboard, the default configuration was set to blacklight, and I had to change it to sunspot.



来源:https://stackoverflow.com/questions/7104673/sunspot-solr-undefined-field-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!