@matthewlam.js/json-tf-idf

1.1.0 • Public • Published

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.

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',
//   }
// ]

Package Sidebar

Install

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

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

4.68 kB

Total Files

4

Last publish

Collaborators

  • matthewlam.js