0
我已经添加了一个“人气”字段作为外部字段的Solr。太阳黑子Solr:如何提高人气字段
“./solr/configsets/sunspot/conf/schema.xml”
<schema name="sunspot" version="1.0">
<!-- ... -->
<types>
<fieldType name="ext_popularity_field" keyField="id" defVal="1.0" class="solr.ExternalFileField"/>
</types>
<fields>
<field name="popularity" type="ext_popularity_field" />
</fields>
<!-- ... -->
<listener event="newSearcher" class="org.apache.solr.schema.ExternalFileFieldReloader"/>
<listener event="firstSearcher" class="org.apache.solr.schema.ExternalFileFieldReloader"/>
</schema>
我已经生成的文件./solr/development/data/external_popularity.txt,我可以看到那些成绩与在Solr的仪表盘下面的查询:
http://localhost:8983/solr/development/select?q= {!func}来普及& FL = ID,得分
<?xml version="1.0" encoding="ISO-8859-1"?>
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">21</int>
</lst>
<result name="response" numFound="7626" start="0" maxScore="21.75">
<doc>
<str name="id">Item 9788770781701</str>
<float name="score">21.75</float>
</doc>
<doc>
<str name="id">Item 9781449661373</str>
<float name="score">19.0</float>
</doc>
<!-- ... -->
</result>
</response>
所以,现在的问题是,我该如何实际引用这在Rails项目中?我有一个搜索块项目类:
class Item < ActiveRecord::Base
searchable include: [:authors, :publisher, :order_temporary_stock] do
text :ean
text :full_title
text :author_names
text :publisher_name
# ...
end
end
...和典型的搜索:
Item.solr_search do
fulltext self.q do
phrase_fields full_title: 16.0 # pf: full_title_text^16.0
phrase_slop 1
boost_fields ean: 8.0 # qf: ean_text^8.0
boost_fields author_names: 2.0 # qf: author_names_text^2.0
boost_fields publisher_name: 2.0 # qf: publisher_name_text^2.0
# boost(popularity)
end
end