2016-04-14 57 views
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 

回答

0

解決上述加:推動搜索PARAMS如下:

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 
    end 

    adjust_solr_params do |params| 
    params[:boost] = "popularity_score" 
    end 
end 

結束