Skip to content

Instantly share code, notes, and snippets.

@olivernn
Created January 25, 2016 21:40
Show Gist options
  • Save olivernn/b5f324528ddcb6baa942 to your computer and use it in GitHub Desktop.
Save olivernn/b5f324528ddcb6baa942 to your computer and use it in GitHub Desktop.
Lunr full text search on facets for faceted search

So many of your fields look like tags or facets, e.g. sector or market, so you full text search might not be the best way to search on these.

Instead if you had full text search on the tags themselves, e.g. full text search on all the possible values for sector or market, and then, with the resuts of this tag lookup, go and find companies that have this tag. The facted search, lookup by tags (or groups of tags) isn't really lunr's forte, but you could certainly use it for full text search of the tags.

var idx = lunr(function () {
  this.ref('id')
  this.field('name')
})
  
idx.add({id: 'internet-of-things', name: 'Internet of things'})
idx.add({id: 'cyber-security', name: 'Cyber Security'})

idx.search('security') // would give the tag 'cyber-security'

Then, somewhere else you could use that tag to get all the documents that have that tag, a simple implementation would be something like this:

tag_index = {
  'cyber-security': ['corp1', 'corp2'],
  'internet-of-things': ['corp1', 'corp3']
}

corps = {
  'corp1': {
    // details about the corperation, e.g. name or whatever else you have
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment