algolia search - 要突出显示vs属性到snippet的属性

ver*_*ius 3 javascript api search algolia

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

示例会很棒!

spe*_*lue 7

attributesToHighlight允许检索具有使用<em>html标记突出显示的匹配单词的属性的完整内容.

attributesToSnippet 提取包含最匹配单词的属性部分并突出显示它们.

例如,如果索引对象是:

{ "question": "algolia search - attributes to highlight vs attributes to snippet"}
Run Code Online (Sandbox Code Playgroud)

如果您使用attributesToHighlight,您的搜索将类似于:

search("algolia se", {"attributesToHighlight": "question"})
Run Code Online (Sandbox Code Playgroud)

您将收到以下表格的答案:

{
  "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"
      ]
}
Run Code Online (Sandbox Code Playgroud)

如果您使用attributesToSnippet,您的搜索将类似于:

search("algolia se", {"attributesToSnippet": "question:2"})
Run Code Online (Sandbox Code Playgroud)

您将收到以下表格的答案:

{
  "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"
      ]
}
Run Code Online (Sandbox Code Playgroud)