太阳黑子solr未定义字段类型

时间:2011-08-18 08:45:33

标签: mysql ruby-on-rails solr sunspot sunspot-rails

我的太阳黑子和solr有问题。在开发过程中它的工作方式就像魅力,但在生产中我从我的rails生产日志中得到以下错误:

RSolr :: RequestError(Solr响应:未定义的字段类型):   app / controllers / search_controller.rb:7:在`index'

我想这与schema.xml有关。但我对solr很新。那么有人可以帮助我吗?

行:
控制器

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

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

模型(问题)

...

searchable do
  text :title 
  text :content
end

4 个答案:

答案 0 :(得分:6)

听起来你的生产Solr实例没有使用太阳黑子的schema.xml

type字段应在Sunspot的标准schema.xml中定义,并用于索引对象的模型名称,以便稍后用于过滤搜索。看到一条错误消息,指出type未定义,这对我来说意味着您使用的是除了太阳黑子之外的schema.xml

可能是您正在使用用于在服务器上安装Solr的方法中的一些其他示例或默认配置集。如果可以,请详细说明如何设置生产Solr服务器。

答案 1 :(得分:3)

对于Solr 4.7,将schema.xml和solrconfig.xml从your_app / solr / conf复制到/ opt / solr / solr / collection1(或者你的solr路径是什么),如果仍然无法正常工作,请确保你的config / sunspot.yml是这样的:

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

建议从solr Web界面创建另一个核心(my_core),将schema.xmlsolrconfig.xml复制到该文件夹​​,并将路径指向/ solr / my_core

答案 2 :(得分:1)

确保在schema.xml中将字段类型设置为required =“true”,否则重建索引将不包括索引数据中的“type”字段。

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

答案 3 :(得分:1)

对我来说,它是在Heroku addon Websolr仪表板中,默认配置设置为blacklight,我不得不将其更改为太阳黑子。