首页 > 解决方案 > 对于使用 algolia api 的 javascript 的前端,我如何禁用荧光笔

问题描述

我在搜索时使用 Algolia API 进行搜索,它给了我结果,但它突出显示了我不想突出显示的文本

const search = instantsearch({
indexName: 'testing',
searchClient,
routing: true,
attributesToHighlight: [],
searchFunction(helper) {
    const container = document.querySelector('#hits');
    container.style.display = helper.state.query === '' ? 'none' : '';
    helper.search();
  }
});
search.addWidgets([
  instantsearch.widgets.searchBox({
    container: '#show_search_list',
    placeholder: 'Search for Email',
    showReset: false,
    templates: {
      submit: 'GO',
    }
  })
]);
search.addWidgets([
  instantsearch.widgets.hits({
    container: '#hits',
    templates: {
    item: 
    `
     <p>{{#helpers.highlight}}{ "attribute": "full_name" }{{/helpers.highlight}}</p>
    <p>{{#helpers.highlight}}{ "attribute": "email" }{{/helpers.highlight}}</p>
     `,
     empty: `We didn't find any results for the search <em>"{{query}}"</em>`,
    },
    })
   ]);

我阅读了文档,但没有找到与我的要求相关的任何内容

标签: javascriptalgolia

解决方案


我找到了它,并将此 {{#helpers.highlight}}{ "attribute": "full_name" }{{/helpers.highlight}} 更改为此 {{full_name}} 并且它的工作正常,因为 helpers.highlight 使属性突出显示。现在它对我来说很好用


推荐阅读