2017-04-26 126 views
0

我是一個新手與Solr,我試圖檢索這樣的文件,按有效載荷排序。Solr獲得分數與有效載荷

{ "id": "1", "tags": ["Cat|0.8", "Dog|0.2"] }, 
{ "id": "2", "tags": ["Cat|0.4", "Dog|0.6"] } 

我試圖使用有效載荷來提高每個標記,但所有信息我發現它有點舊。 This是我發現的最新出版物。

但我發現this, too,我不知道是否有比第一種方法更新的東西。對於第二個鏈接,我認爲我可以添加到schema.xml中

<fieldType name="tags" class="solr.TextField" positionIncrementGap="100"> 
    <analyzer> 
    <tokenizer class="solr.WhitespaceTokenizerFactory"/> 
    <filter class="solr.DelimitedPayloadTokenFilterFactory" encoder="float" delimiter="|"/> 
    </analyzer> 
</fieldType> 

並且有效負載將被識別。但我不知道如何檢查,我只看到搜索「狗」的結果沒有按有效載荷排序。

{ 
    "responseHeader":{ 
    "status":0, 
    "QTime":1, 
    "params":{ 
     "q":"Dog", 
     "indent":"on", 
     "wt":"json", 
     "_":"1493191003038"}}, 
    "response":{"numFound":2,"start":0,"docs":[ 
     { 
     "id":"1", 
     "tags":["Cat|0.8", 
      "Dog|0.2"], 
     "_version_":1565724328306147328}, 
     { 
     "id":"2", 
     "tags":["Cat|0.4", 
      "Dog|0.6"], 
     "_version_":1565724328307195904}] 
    }} 

所以我不知道該怎麼辦......我應該按照第一個教程,即使我有最新的Solr版本?我的目標很簡單:通過標籤中的有效載荷對響應進行排序。

回答

0

假設可能的值或標籤被限制(不超過千),恕我直言,最簡單的路徑,你會:

  1. 按摩的數據轉換成某種格式更易於通過Solr的使用,爲例如:

    { "id": "1", "tags": ["Cat", "Dog"], "tag_Cat": "0.8", "tag_Dog":"0.2"} 
    
  2. 爲tag_類型字段,你可以定義一個dynamicField tag_ *,這將覆蓋所有的可能性,並建立索引到一個tfloat(也有可能docValues)

  3. 現在,您可以在每次需要時輕鬆地對相關字段(tag_Cat ...)進行排序(或增強)。

+0

問題是,我不能假設:(我不知道標籤的數量...... – analca3