gatsby-plugin-local-search icon indicating copy to clipboard operation
gatsby-plugin-local-search copied to clipboard

Support language stemmers

Open angeloashmore opened this issue 5 years ago • 2 comments

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 avatar Aug 10 '19 20:08 angeloashmore

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

angeloashmore avatar Aug 10 '19 20:08 angeloashmore

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.

jooola avatar May 07 '21 11:05 jooola