在 Algolia 搜索中搜索 é 等单词中的特殊字符

问题描述 投票:0回答:1

正在执行一项需要在 Algolia Search 上进行搜索的任务

这对于所有字母文本都工作正常,但对于像 é 这样的特殊字符会出现错误

  const index = client.initIndex(indexName);
  return index
    .search("", {
      params: "filters=section_name:Design + Décor",
    })
    .then(({ hits }: any) => {
      console.log(hits)
    });

我收到以下错误

"filters: Unexpected token string(Décor) expected end of filter"

任何对此的指导表示赞赏

提前致谢

javascript algolia
1个回答
0
投票

您可以使用 URL 编码对特殊字符进行编码

encodeURIComponent

const index = client.initIndex(indexName);
const sectionName = encodeURIComponent("Design + Décor");
return index
  .search("", {
    params: `filters=section_name:${sectionName}`,
  })
  .then(({ hits }) => {
    console.log(hits)
  });
© www.soinside.com 2019 - 2024. All rights reserved.