-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Support FlexSearch 0.7.x #44
Comments
My first thought was, "Move 'flexsearch' to peerDependencies". Unfortunately, this would result in users having to install both gatsby-plugin-local-search and flexsearch even if they are NOT using flexsearch for local search. Maybe it would be worth the effort to upgrade the library to be more modular and have the 'engines' broken out into sub-plugin? Sorta like the structure of the gatsby-transformer-remark ecosystem.
proposed gatsby-config.js: module.exports = {
plugins: [
{
resolve: "gatsby-plugin-local-search",
options: {
// engine: "flexsearch", <-- omit and rely on plugins to define engine?
name: "pages",
// new section
plugins: [
`gatsby-local-search-flexsearch`,
// OR
{
resolve: `gatsby-local-search-flexsearch`,
options: {
// ...
},
},
],
// end of new section
query: `
query {
allMarkdownRemark(sort: { fields: [frontmatter___date], order: ASC }) {
nodes {
id
fields {
slug
}
frontmatter {
date(formatString: "MMMM DD, YYYY")
title
}
rawMarkdownBody
}
}
}
`,
ref: "id",
index: ["title", "body"],
store: ["id", "title", "body", "date", "slug", "type"],
normalizer: ({ data }) =>
data.allMarkdownRemark.nodes.map(node => ({
// ... code
})),
},
},
],
} |
Hey @haysclark, this is a great recommendation. Splitting into sub-plugins also opens the system up to others search engines more easily. The Rather than use {
resolve: 'gatsby-plugin-local-search',
options: {
name: 'pages',
engine: 'gatsby-local-search-flexsearch',
query: `
query {
allMarkdownRemark(sort: { fields: [frontmatter___date], order: ASC }) {
nodes {
id
fields {
slug
}
frontmatter {
date(formatString: "MMMM DD, YYYY")
title
}
rawMarkdownBody
}
}
}
`,
index: ['title', 'body'],
store: ['id', 'title', 'body', 'date', 'slug', 'type'],
normalizer: ({ data }) =>
data.allMarkdownRemark.nodes.map((node) => ({
// ... code
}))
},
} This keeps the API similar to the existing API and allows us to migrate from
What do you think? |
@angeloashmore Awesome! Yeah that is a good point about 1:1 relationship as well at the point about backwards compatibility. Just to clarify, are you imagining we can support providing custom options to the child engines? e.g. (this is 99% what you posted, just added the options API for clarity.) {
resolve: 'gatsby-plugin-local-search',
options: {
name: 'pages',
// for legacy and when providing no custom options
engine: 'gatsby-local-search-flexsearch',
// for providing custom options
engine: {
resolve: `gatsby-local-search-flexsearch`,
options: {
// ...
},
},
query: `
query {
allMarkdownRemark(sort: { fields: [frontmatter___date], order: ASC }) {
nodes {
id
fields {
slug
}
frontmatter {
date(formatString: "MMMM DD, YYYY")
title
}
rawMarkdownBody
}
}
}
`,
index: ['title', 'body'],
store: ['id', 'title', 'body', 'date', 'slug', 'type'],
normalizer: ({ data }) =>
data.allMarkdownRemark.nodes.map((node) => ({
// ... code
}))
},
} |
Good catch on the engine options. I forgot about that part! The current API allows for an For the sake of API simplicity, I'd lean toward using the separate Do you think there would be a benefit to using the |
I don't think it is really required, I was just following the Gatsby conventions that I'm used too seeing. I like the nested structure of the |
@angeloashmore Hmm.... it looks like FlexSearch 0.7.x's import/export API's have changed quite a bit. FlexSearch 0.7.x exports to multiple data blobs that have to be imported in separate chunks. Additionally, there appears to be a flaw in the new |
is there still work being done adding 0.7 support? |
@gabrielcsapo There isn't any active development for 0.7 support, but I would be happy to review a PR. To keep the upgrade simple, we can either go the plugin route described in this issue, or we can keep the existing system while supporting 0.7. |
Hey everyone :) Does anyone have a working solution for Gatsby + Flexsearch@7+? |
A new major version of FlexSearch 0.7.0 has been released that might have some breaking changes.
The text was updated successfully, but these errors were encountered: