1

I've got a Gatsy-Sanity project that needs a search component. For this I though of using gatsby-plugin-lunr. I run into a problem that my nodes are multilingual. For example one of my fields is constructed like:

         "title": {
            "_type": "localeString",
            "nl": "Begin ",
            "en": "Home "
         },

(This parser is, in short, like following. If has key _type that starts with 'locale*', than return only value of key en or nl. This is passed by a var)

I could make a parser that splits/strips the data. I've got this sort of working (not yet succesfull) inside the component that runs the search query from the search-index. But that would mean it parses it each search. Is there a way to do this on build in gatsby-node.js with a lunr plugin? I also need this since I would need to add a language prefix on the slug/path of the result.

const SearchProcess = lunr => builder => {
  // how to pre-process data
}
Tim
  • 861
  • 1
  • 12
  • 27
  • Couldn't you do this in the resolvers section of the `gatsby-plugin-lunr` config? – ksav Apr 18 '20 at 02:03
  • @ksav, the thing is that it that each node/doc is multilingual. So there is no conditional filtering there. – Tim Apr 18 '20 at 08:14
  • I think I'm looking for something like a hook or method between data query/receipt and writing it to the index json. To intercept it and alter the results – Tim Apr 18 '20 at 08:15

1 Answers1

1

I'm going with a different gatsby plugin. gatsby-plugin-local-search This plugin is able to alter the data before saving it with normalizer Now I can call a method to conditional alter the data per language.

Tim
  • 861
  • 1
  • 12
  • 27