praveenn77 / docusaurus-lunr-search

Local / Offline Search for docusaurus
https://praveenn77.github.io/docusaurus-lunr-search-demo/
MIT License
493 stars 79 forks source link

Help adjusting stopwords #109

Closed cassieevans closed 1 year ago

cassieevans commented 1 year ago

Hi there - Firstly thank you for this search option. It's incredibly helpful.

This isn't an issue, I'm just looking for a little help/guidance. I need to adjust the stopwords for my project as we have two important methods called 'from' and 'to' which are currently not showing in the search.

I looked up stopwords on the lunr repo and the following solution seemed so simple, but I just can't get it to work.

https://github.com/olivernn/lunr.js/issues/201

If you really need to search for words that are stop words you can remove the stop word filter like so:

index.pipeline.remove(lunr.stopWordFilter) Alternatively you can generate your own stop word filter that is more specific to your use case:

var myStopWordFilter = lunr.generateStopWordFilter(['your', 'stop', 'words', 'here'])
index.pipeline.before(lunr.stopWordFilter, myStopWordFilter)
index.pipeline.remove(lunr.stopWordFilter)

I assumed I could just pop it here in the lunr-search.js? But no luck. I've tried a few different ways and exhausted all the links I can find.

constructor(searchDocs, searchIndex, baseUrl = "/") {
    this.searchDocs = searchDocs;
    this.lunrIndex = lunr.Index.load(searchIndex);
    this.baseUrl = baseUrl;

    const myStopWordFilter = lunr.generateStopWordFilter(['my', 'stop', 'words', 'here']);

    this.lunrIndex.pipeline.before(lunr.stopWordFilter, myStopWordFilter);
    this.lunrIndex.pipeline.remove(lunr.stopWordFilter);
  }

Any help would be hugely appreciated. Happy to swing you over a fee for assistance.

Thanks for reading.

praveenn77 commented 1 year ago

Adding an option for it.

praveenn77 commented 1 year ago

stopWords option addded, check readme