solr4.7.2中TermsComponent組件使用

TermsComponent 組件說明

TermsComponent組件提供對字段中的索引詞的訪問以及與每個詞匹配的文檔數量。這對於構建 auto-suggest 功能或在 term 級別而不是搜索或文檔級別操作的任何其他功能都很有用。檢索索引順序中的 term 非常快,因爲實現直接使用 Lucene 的 TermEnum 來遍歷術語字典。從某種意義上說,這個搜索組件在整個索引上提供了快速的 field-faceting,不受基本查詢或任何過濾器的限制。返回的文檔頻率是與該詞匹配的文檔數量,包括任何已被標記爲刪除但尚未從索引中刪除的文檔。

TermsComponent 組件配置

在solrconfig.xml進行了配置定義Term搜索組件

<searchComponent name="terms" class="solr.TermsComponent"/>

在請求處理程序中使用TermsComponent組件

<requestHandler name="/terms" class="solr.SearchHandler" startup="lazy">

    <lst name="defaults">

        <bool name="terms">true</bool>

        <bool name="distrib">false</bool>

    </lst>

    <arr name="components">

        <str>terms</str>

    </arr>

</requestHandler>

TermsComponent 組件包含在 Solr 的現成的請求處理程序中的 /terms 請求處理程序中 - 請參閱 RequestHandlers 。 您也可以將這個組件添加到另一個處理程序中,並且在 HTTP 請求中傳遞 “terms = true” 以獲得條件。如果僅在單獨的處理程序中定義它,則在查詢時必須使用該處理程序,以獲取條件而不是將常規文檔作爲結果。
請注意,此請求處理程序的默認值將參數 “terms” 設置爲 true,這允許根據請求返回條件。

參數 “distrib” 被設置爲 false,這使得這個處理程序只能在一個 Solr 內核上使用。

參數“distrib” 被設置爲 true,這使得這個處理程序支持分佈式索引。

TermsComponent 也支持分佈式索引。對於 /terms 請求處理程序,您必須提供以下兩個參數:

1)shards 參數
   指定分佈式索引配置中的分片。有關分佈式索引的更多信息,請參見使用索引分片的分佈式搜索。

2)shards.qt 參數
   指定 Solr 用於請求分片的請求處理程序。

 

TermsComponent 組件參數

  • terms 參數

    如果設置爲true,則啓用條款組件。默認情況下,條款組件處於關閉狀態(false)。例: terms=true

  • terms.fl 參數

    指定從中檢索 term 的字段。如果terms=true,則該參數是必需的。例: terms.fl=title

  • terms.list 參數

    獲取逗號分隔的 term 列表的文檔頻率。詞總是以索引順序返回。如果terms.ttf設置爲 true,則返回它們的總詞頻。如果定義了多個terms.fl,那麼這些統計數據將在每個請求的字段中爲每個詞返回。

    例: terms.list=termA,termB,termC

  • terms.limit 參數

    指定要返回的最大 term 數。默認是10。如果限制設置爲小於0的數字,則不執行最大限制。雖然這不是必需的,但是這個參數或者terms.upper必須被定義。

    例: terms.limit=20

  • terms.lower 參數

    指定開始的 term。如果未指定,則使用空字符串,從而導致 Solr 從字段的開始處開始。

    例: terms.lower=orange

  • terms.lower.incl 參數

    如果設置爲 true,則包含下限項(在結果中指定terms.lower)。

    例: terms.lower.incl=false

  • terms.mincount 參數

    指定要返回的最小文檔頻率,以便將術語包含在查詢響應中。結果包括小數(即 >= mincount)。

    例: terms.mincount=5

  • terms.maxcount 參數

    指定一個 term,爲了包含在查詢響應中而必須具有的最大文檔頻率。默認設置是-1,它不設置上限。結果包含 maxcount(即<= maxcount)。 

    例: terms.maxcount=25

  • terms.prefix 參數

    限制匹配以指定字符串開頭的 term。

    例: terms.prefix=inter

  • terms.raw 參數

    如果設置爲 true,則返回索引項的原始字符,而不管其是否可讀。例如,索引形式的數字是不可讀的。

    例: terms.raw=true

  • terms.regex 參數

    限制符合正則表達式的條件。

    例: terms.regex=.*pedist

  • terms.regex.flag 參數

    定義一個 Java 正則表達式標誌,用於計算terms.regex定義的表達式。有關每個標誌的詳細信息,請參見:http://docs.oracle.com/javase/tutorial/essential/regex/pattern.html。有效的選項是: 

    • case_insensitive

    • comments

    • multiline

    • literal

    • dotall

    • unicode_case

    • canon_eq

    • unix_lines

      例: terms.regex.flag=case_insensitive

  • terms.stats 參數

    在結果中包含索引統計信息。目前只返回一個集合的 numDocs。當與terms.list結合時它提供足夠的信息來計算術語列表的逆文件頻率(IDF)。

  • terms.sort 參數

    定義如何對返回的條件進行排序。有效選項count按頻率排序,首先選擇最高頻率,或index按索引順序排序。 

    例: terms.sort=index

  • terms.ttf 參數

    如果設置爲 true,那麼同時返回df(docFreq)和ttf(totalTermFreq)統計信息,在terms.list請求 term 中。在這種情況下,響應格式是:

    <lst name="terms">
      <lst name="field">
        <lst name="termA">
          <long name="df">22</long>
          <long name="ttf">73</long>
        </lst>
      </lst>
    </lst>
  • terms.upper 參數

    指定要停止的術語。雖然此參數不是必需的,但是該參數或terms.limit必須定義。

    例: terms.upper=plum

  • terms.upper.incl 參數

    如果設置爲 true,則結果集合中將包含上限項目。默認值是 false。

    例: terms.upper.incl=true

對 term 請求的迴應是 term 及其文檔頻率值的列表。

單機查詢示例

關鍵參數:

  • terms=true
  • distrib=true

http://localhost:8891/solr/testindex/terms?q=*%3A*&wt=json&indent=true&distrib=false&terms=true&terms.fl=sname&terms.limit=-1&terms.sort=index

分佈式查詢

關鍵參數:

  • terms=true
  • distrib=true
  • shards=localhost:8891/solr/testindex,localhost:8892/solr/testindex
  • shards.qt=/terms

http://localhost:8891/solr/testindex/terms?q=*%3A*&wt=json&indent=true&distrib=true&terms=true&terms.fl=sname&terms.limit=-1&terms.sort=index&shards=localhost:8891/solr/testindex,localhost:8892/solr/testindex&shards.qt=/terms

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章