如何使用SitePage查询填充搜索索引



我正试图在我的gastby博客中实现搜索。我看过很多教程和插件,但它们都使用Markdown,我的博客是用strapi构建的,页面是动态创建的。我意识到节点allSitePage可以提供搜索索引所需的所有信息,我尝试在gatsby-config.js:中的flexsearch插件中使用它

{
resolve: "gatsby-plugin-flexsearch",
options: {
languages: ["en"],
type: "allSitePage",
fields: [
{
name: "title",
indexed: true,
resolver: "fields.title",
attributes: {
encode: "balance",
tokenize: "strict",
threshold: 6,
depth: 3,
},
store: true,
},
{
name: "context",
indexed: true,
resolver: "fields.context",
attributes: {
encode: "balance",
tokenize: "strict",
threshold: 6,
depth: 3,
},
store: false,
},
{
name: "url",
indexed: false,
resolver: "fields.path",
store: true,
},
],
},
},

但是我的索引是空的。关于如何让它发挥作用或更容易的替代方案,有什么想法吗?

如果有人还在调查这个:

  • 删除";所有";在类型(因此从"allSitePage"到"SitePage"(中
  • 删除";字段"在解析器定义中(因此从"fields.title"到"title"(

更改后,OP的代码应该看起来像:

{
resolve: "gatsby-plugin-flexsearch",
options: {
languages: ["en"],
type: "SitePage",
fields: [
{
name: "title",
indexed: true,
resolver: "title",
attributes: {
encode: "balance",
tokenize: "strict",
threshold: 6,
depth: 3,
},
store: true,
},
{
name: "context",
indexed: true,
resolver: "context",
attributes: {
encode: "balance",
tokenize: "strict",
threshold: 6,
depth: 3,
},
store: false,
},
{
name: "url",
indexed: false,
resolver: "path",
store: true,
},
],
},
},

相关内容

  • 没有找到相关文章

最新更新