我在rails项目中使用sunspot来支持搜索服务,但是当我搜索查询时,在项目网页中返回没有结果。 enter image description here
当我通过本地solr服务搜索时,它可以返回正确的结果。 enter image description here
我检查项目日志,我发现在搜索查询时,索引字段添加" text"后缀,为什么它添加后缀,因为太阳黑子包装??? 日志: SOLR请求(31.2ms)[path = select parameters = {fq:[" type:OpenSourceProject"," -filtration_i:0"],sort:"得分desc&#34 ;,q:" rails",fl:" *得分",qf:" name_text ^ 4.0 tags_for_search_text ^ 3.0 description_text ^ 0.5 tags_text ^ 1.0 language_text ^ 1.0" ,defType:" edismax",bf:[" log(composite_score_i)^ 1000"],start:0,rows:10}] 渲染open_source_projects / _search_bar.html.erb(1.6ms)
sunspot.yml配置:
production:
solr:
hostname: localhost
port: 8080
log_level: WARNING
path: /solr/production1
solr版本:5.2.1 gemfile:
gem 'sunspot_rails', '2.2.0'
gem 'sunspot_solr', '2.2.0'
gem 'will_paginate'
gem 'progress_bar
模型搜索块:
searchable do
text :name, :stored => false
text :tags, :stored => false
text :tags_for_search, :stored => false
text :language, :stored => false
text :description, :stored => false
integer :filtration
integer :composite_score
integer :relative_memos_num
end
控制器搜索:
search = OpenSourceProject.search do
without(:filtration,0)
all do
fulltext language do
fields(:tags)
fields(:language)
end
fulltext search_words do
#highlight(:name)
fields(:name)
fields(:tags_for_search)
fields(:description)
fields(:tags)
fields(:language)
boost_fields :name => 4.0
boost_fields :tags_for_search => 3.0
boost_fields :tags => 1.0
boost_fields :description => 0.5
boost_fields :language => 1.0
boost(function { log(:composite_score)^1000 })
end
end
if "".eql?(search_words)
order_by(:composite_score, :desc)
else
order_by(:score, :desc)
end
paginate :page => params[:page], :per_page => 10
end
per_page_option = 10
@hits = search.hits
@open_source_projects = search.results
@projects_count = search.total #get total count of search
它非常奇怪,与solr版本有关吗?有人可以解释为什么会发生这种情况以及我如何解决它。谢谢!