2013-10-11 79 views

回答

7

attributesToHighlight允許檢索使用<em> html標記突出顯示的匹配單詞的完整內容屬性。

attributesToSnippet提取包含最匹配單詞的屬性部分並突出顯示它們。

例如,如果您索引對象是:

{ "question": "algolia search - attributes to highlight vs attributes to snippet"} 

如果使用attributesToHighlight,你的搜索將類似於:

search("algolia se", {"attributesToHighlight": "question"}) 

,您會收到這種形式的答案:

{ 
    "question": "algolia search - attributes to high:light vs attributes to snippet", 
    "_highlightResult": { 
    "question": { 
     "value": "<em>algolia</em> </em>se</em>arch - attributes to highlight vs attributes to snippet", 
     "matchLevel": "full", 
     "matchedWords": [ 
     "algolia", 
     "se" 
     ] 
} 

如果您使用attributesToSnippet,您的搜索將類似於:

search("algolia se", {"attributesToSnippet": "question:2"}) 

,您會收到這種形式的答案:

{ 
    "question": "algolia search - attributes to high:light vs attributes to snippet", 
    "_snippetResult": { 
    "question": { 
     "value": "<em>algolia</em> </em>se</em>arch", 
     "matchLevel": "full", 
     "matchedWords": [ 
     "algolia", 
     "se" 
     ] 
} 
+0

這是偉大的!非常感謝你的解釋 – vergilius