太阳黑子索尔:如何按人气领域提升

时间:2016-04-14 20:30:31

标签: ruby-on-rails solr sunspot

我已经增加了一个人气"将Solr作为外部字段的字段。

" ./的solr / configsets /太阳黑子/ 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项目中实际引用它?我有一个带有可搜索块的Item类:

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

1 个答案:

答案 0 :(得分:0)

通过添加以下内容解决了上述问题:对搜索参数的提升如下:

UserJobManager