Skip to content

matthewlamdotjs/json-tf-idf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-tf-idf

An ultra lightweight NodeJS multi-keyword ranked search function for array of json objects

keys / indices

The "document" in the tf-idf algorithm is essentially the concatenation of all of the object properties of type string. There is no support for an include / exclude list of keys. For more information on the tf-idf algorithm and the theory behind it, check out http://www.tfidf.com/.

stopwords

Stopwords are removed from each query using the stopword.removeStopwords() function from the npm package "stopword".

installation

npm i @matthewlam.js/json-tf-idf

dependencies

usage

const simpleSearch = require('@matthewlam.js/json-tf-idf');

let data = [
  // note object keys need not match,
  // it will treat all string properties as the "document" in tf-idf
  {
    message: 'Why did the chicken cross the road?'
  },
  {
    name: 'Matt',
    description: 'I wrote code yesterday',
  },
  {
    username: 'Jeff',
    address: '123 sesame street',
    notes: 'coded 200 lines of code today'
  }
]

let query = 'code the line'

console.log(simpleSearch(query, data));
// OUTPUT:
// [
//   {
//     username: 'Jeff',
//     address: '123 sesame street',
//     notes: 'coded 200 lines of code today'
//   },
//   {
//     name: 'Matt',
//     description: 'I wrote code yesterday',
//   }
// ]

About

ultra lightweight front-end multi-keyword ranked search function for array of json objects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published