首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用SitePage查询填充搜索索引?

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

Stack Overflow用户
提问于 2020-08-11 17:59:44
回答 1查看 123关注 0票数 0

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

代码语言:javascript
复制
{
      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,
          },
        ],
      },
    },

但是我的索引是空的。有没有关于如何让它工作或更简单的替代方案的想法?

EN

回答 1

Stack Overflow用户

发布于 2021-03-19 05:41:31

如果有人还在调查这件事:

删除类型中的“"SitePage")

  • remove”(因此,从“”
  • "allSitePage“到”“SitePage”)
  • remove“)。在解析器定义中(因此,从"fields.title“到"title")

在更改之后,OP的代码应该如下所示:

代码语言:javascript
复制
    {
      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,
          },
        ],
      },
    },
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63355847

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档