Home

Awesome

npm version GitHub package.json version NPM monthly downloads GitHub license

ItemsJS - search engine in javascript

Extremely fast faceted search engine in JavaScript - lightweight, flexible, and simple to use. Created to perform fast search on json dataset (up to 100K items).

Demo

demo

See another demo examples

Use cases

Itemsjs is being used mostly for data classification of companies, products, publications, documents, jobs or plants

The solution has been implemented by people from Amazon, Hermes, Apple, Microsoft, James Cook University, Carnegie Mellon University and more. You can find a list of real implementations - here

Features

Getting Started

NPM

npm install itemsjs

Using CommonJS syntax

const itemsjs = require('itemsjs')(data, configuration);
const items = itemsjs.search();

Using ES Module syntax

import itemsjs from 'itemsjs';
const searchEngine = itemsjs(data, configuration);
const items = searchEngine.search();

Client side

To use as an UMD in the browser:
<!-- CDN -->
<!-- unpkg: use the latest release -->
<script src="https://unpkg.com/itemsjs@latest/dist/index.umd.js"></script>
<!-- unpkg: use a specific version -->
<script src="https://unpkg.com/itemsjs@2.1.24/dist/index.umd.js"></script>
<!-- jsdelivr: use a specific version -->
<script src="https://cdn.jsdelivr.net/npm/itemsjs@2.1.24/dist/index.umd.js"></script>
<script>
  itemsjs = itemsjs(data, configuration);
  itemsjs.search()
</script>
To use as an ES module in the browser:
<!-- Include as ES Module -->
<script type="module">
  import itemsjs from 'https://unpkg.com/itemsjs@2.1.24/dist/index.module.js';
  // Initialize and use itemsjs here
  const searchEngine = itemsjs(data, configuration);
  searchEngine.search();
</script>

Example usage

npm install itemsjs

# download json data
wget https://raw.githubusercontent.com/itemsapi/itemsapi-example-data/master/items/imdb.json -O data.json

Next, create a search.js file with the following content:

const data = require('./data.json');

const itemsjs = require('itemsjs')(data, {
  sortings: {
    name_asc: {
      field: 'name',
      order: 'asc'
    }
  },
  aggregations: {
    tags: {
      title: 'Tags',
      size: 10,
      conjunction: false
    },
    actors: {
      title: 'Actors',
      size: 10
    },
    genres: {
      title: 'Genres',
      size: 10
    }
  },
  searchableFields: ['name', 'tags']
});

/**
 * get filtered list of movies 
 */
const movies = itemsjs.search({
  per_page: 1,
  sort: 'name_asc',
  // full text search
  // query: 'forrest gump',
  filters: {
    tags: ['1980s']
  }
})
console.log(JSON.stringify(movies, null, 2));

/**
 * get list of top tags 
 */
const top_tags = itemsjs.aggregation({
  name: 'tags',
  per_page: 10
})
console.log(JSON.stringify(top_tags, null, 2));

Run your script with Node.js:

node search.js

Integrations

If native full text search is not enough then you can integrate with external full text search.

How it works:

Examples:

API

const itemsjs = ItemsJS(data, [configuration])

data

The first data argument is an array of objects.

configuration

Responsible for defining global configuration. Look for full example here - configuration

itemsjs.search(options)

options

itemsjs.aggregation(options)

It returns full list of filters for specific aggregation

options

itemsjs.similar(id, options)

It returns similar items to item for given id

options

itemsjs.reindex(data)

It's used in case you need to reindex the whole data

data

An array of objects.