簡體   English   中英

在Solr上使用sunspot_rails進行搜索時,如何通過部分字匹配來提升全字匹配?

[英]While searching with sunspot_rails on Solr, how can I boost whole word matching over partial word matching?

我正在使用sunspot_railsSolr實例提交查詢。 一切正常,但我想按照以下標准訂購我的結果:我想首先獲取匹配術語顯示為單詞而不是單詞的一部分的文檔。

因此,如果我有這兩個文件:

1)使用Solr搜索Solr非常棒

2)Solr非常適合用自由文本支持搜索

我正在尋找的術語是: search ,然后

我想在結果中包含兩個文檔,但我希望文檔(2)首先出現。

我試過了order_by :score, :desc但它似乎沒有用。 除非我找到一種方法來說明如何計算“得分”。

在此先感謝Panayotis

您需要使用Solr維護兩個字段。
一個具有原始值,另一個具有分析值.eg text_org and text (which is analyzed)
然后,您可以相應地調整增強,將原始字段值提升到分析的一個,例如text_org^2 text^1
請記住,如果它與原始匹配,它也將匹配分析的文本或完全單詞匹配的效果大於正常匹配。

擴展Jayendra的答案,你應該索引到兩個單獨的字段。

這是一個示例的針對太陽黑子的schema.xml摘錄,來自我對前一個問題的回答: 如何在solr中提升更長的ngrams?

<schema>
  <types>

    <!--
      A text type with minimal text processing, for the greatest semantic
      value in a term match. Boost this field heavily.
    -->
    <fieldType name="text" class="solr.TextField" omitNorms="false">
      <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory" />
        <filter class="solr.StandardFilterFactory" />
        <filter class="solr.LowerCaseFilterFactory" />
      </analyzer>
    </fieldType>

    <!--
      Looser matches with NGram processing for substrings of terms and synonyms
    -->
    <fieldType name="text_ngram" class="solr.TextField" omitNorms="false">
      <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory" />
        <filter class="solr.StandardFilterFactory" />
        <filter class="solr.LowerCaseFilterFactory" />
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true" />
        <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="6" side="front" />
      </analyzer>
    </fieldType>

    <!-- other stuff -->

  </types>
  <fields>

    <!-- other fields; refer to *_text -->

    <dynamicField name="*_ngram" type="text_ngram" ... />

  </fields>
</schema>

searchable塊中,您可以使用:as選項指定fieldname:

searchable do 

  text :title
  text :title, :as => :title_ngram

  # ...

end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM