我正在尝试在我的gastby博客中实现搜索。我见过很多教程和插件,但它们都使用Markdown,我的博客是用strapi构建的,页面是动态创建的。我意识到节点allSitePage可以提供我搜索索引所需的所有信息,我尝试在flexsearch插件中使用它,比如在gatsby-config.js中:
{
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,
},
],
},
},但是我的索引是空的。有没有关于如何让它工作或更简单的替代方案的想法?
发布于 2021-03-19 05:41:31
如果有人还在调查这件事:
删除类型中的“"SitePage")
在更改之后,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,
},
],
},
},https://stackoverflow.com/questions/63355847
复制相似问题