angeloashmore / gatsby-plugin-local-search

Gatsby plugin for providing client-side search for data available in Gatsby's GraphQL layer using a variety of engines
MIT License
51 stars 29 forks source link

Support language stemmers #7

Open angeloashmore opened 5 years ago

angeloashmore commented 5 years ago

Add language support.

To support multiple engines, the best API is probably passing a language string (e.g. “en” or “de”).

Alternatively, allow passing arbitrary Stemmer configs. This would be engine-specific.

angeloashmore commented 5 years ago

FlexSearch language support: https://github.com/nextapps-de/flexsearch/blob/master/README.md#add-language-specific-stemmer-andor-filter

Lunr language support: https://lunrjs.com/guides/language_support.html

jooola commented 3 years ago

Hey, I would like to tackle this one.

I already commented here https://github.com/angeloashmore/gatsby-plugin-local-search/pull/31#issuecomment-834269604

So I would like to propose a way to hook into the plugin code to allow extended configuration of each engine.

Here is an example:

// types.ts
export type FlexSearchEngine = {
  name: 'flexsearch',
  options: FlexSearchCreateOptions
  hook?: (engine: FlexSearch) => void
}

export type LunrEngine = {
  name: 'lunr',
  options: any
  hook?: LunrConfigFunction
}

export type Engine = FlexSearchEngine | LunrEngine

// gatsby-node.ts
// ...

  // Inside createFlexSearchIndexExport
  if (engine.hook) {
    engine.hook(FlexSearch)
  }

  const index = FlexSearch.create<IndexableDocument>(engine.options)

// ...

This could allow to register new plugins/stemmers and whatever the user wants.

I don't know if you have this in mind or something less prone to mess with the engine. But I feel this could give enough power to customize each possible engine we integrate in this plugin.

Should I provide some POC ?

EDIT: Sorry I should have read all issues of this repo, and open my own, This feature could close many issue still pending.