3

我在 algoliasearch-client-js 中找不到这两个设置之间的区别。您能否简单解释一下如何使用这些设置,更重要的是为什么使用这些设置?

例子会很棒!

4

1 回答 1

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"
      ]
}
于 2013-10-11T10:11:34.147 回答