问题描述
我正在尝试在我的gastby博客中实施搜索。我看过很多教程和插件,但是它们都使用Markdown,我的博客是用STradi构建的,页面是动态创建的。我意识到节点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",resolver: "fields.context",store: false,{
name: "url",indexed: false,resolver: "fields.path",],
但是我的索引为空。关于如何使其工作或更简单的替代方案有什么想法?
解决方法
如果有人还在研究这个:
- 删除类型中的“all”(因此,从“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",resolver: "context",store: false,{
name: "url",indexed: false,resolver: "path",],