nuxt-community / lunr-module

Full-text search with pre-build indexes for Nuxt.js using lunr.js
MIT License
47 stars 8 forks source link

Adding fuzzy search #17

Open sandoche opened 3 years ago

Decipher commented 2 years ago

As a workaround, I implemented this fix by extending the LunrSearch component:

<script>
import LunrSearch from 'lunr-module/search'

export default {
  extends: LunrSearch,
  methods: {
    async search (txt) {
      if (!this.searchIndex) {
        const indexLoaded = await this.loadIndex()

        if (!indexLoaded) {
          return
        }
      }

      this.setStatus('searching')

      txt = txt + '* ' + txt
      this.searchResults = this.searchIndex.search(txt)

      if (!this.searchResults || !this.searchResults.length) {
        this.setStatus('noresults')
      } else {
        this.clearStatus()
      }

      this.openResults()
    },
  }
}
</script>