Full text, faceted, dependency free search library in javascript. Created to perform fast search on json dataset (up to 100K items).
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
- faceted search
- full text
- pagination
- no dependencies (only javascript)
- working on backend and frontend
- working with custom full text search
npm install itemsjsconst itemsjs = require('itemsjs')(data, configuration);
const items = itemsjs.search();or using from the client side:
npm install itemsjs<!-- CDN -->
<!-- unpkg: use the latest release -->
<script src="https://unpkg.com/itemsjs@latest/dist/itemsjs.min.js"></script>
<!-- unpkg: use a specific version -->
<script src="https://unpkg.com/[email protected]/dist/itemsjs.min.js"></script>
<!-- jsdelivr: use a specific version -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/itemsjs.min.js"></script>
<!-- locally -->
<script src="/node_modules/itemsjs/dist/itemsjs.js"></script>itemsjs = itemsjs(data, configuration);
itemsjs.search()Gulp task:
function itemjs() {
return src('node_modules/itemsjs/dist/itemsjs.min.js')
.pipe(dest('source/javascripts/'));
}; // Will copy to source/javascripts/itemsjs.min.jsnpm install itemsjs
# download json data
wget https://raw.githubusercontent.com/itemsapi/itemsapi-example-data/master/items/movies-processed.json -O data.jsonCreate search.js:
var data = require('./data.json');
var 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
*/
var 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
*/
var top_tags = itemsjs.aggregation({
name: 'tags',
per_page: 10
})
console.log(JSON.stringify(top_tags, null, 2));Test that with :
node search.jsIf native full text search is not enough then you can integrate with external full text search.
How it works:
- each item of your data needs to have
idfield native_search_enabledoption in configuration should be disabled- index data once in your search and itemsjs
- make search in your custom search and provide
idsdata into itemsjs - done!
Examples:
The first data argument is an array of objects.
Responsible for defining global configuration. Look for full example here - configuration
-
aggregationsfilters configuration i.e. fortags,actors,colors, etc. Responsible for generating facets. -
sortingsyou can configure different sortings liketags_asc,tags_descwith options and later use it with one key. -
searchableFieldsan array of searchable fields. -
native_search_enabledif native full text search is enabled (true | false. It's enabled by default)
-
per_pageamount of items per page. -
pagepage number - used for pagination. -
queryused for full text search. -
sortused for sorting. one ofsortingskey -
filtersfiltering items based on specific aggregations i.e. {tags: ['drama' , 'historical']} -
filterfunction responsible for items filtering. The way of working is similar to js native filter function. See example -
isExactSearchset totrueif you want to always show exact search matches. See lunr stemmer and lunr stopWordFilter. -
removeStopWordFilterset totrueif you want to remove the stopWordFilter. See itemsapi#46. -
is_all_filtered_itemsset totrueif you want to return the whole filtered dataset.
It returns full list of filters for specific aggregation
nameaggregation nameper_pagefilters per pagepagepage numberqueryused for quering filters. It's not full text searchconjunctionchoose between AND, OR
It returns similar items to item for given id
fieldfield name for computing similarity (i.e. tags, actors, colors)minimumwhat is the minimum intersection between field of based item and similar item to show them in the resultper_pagefilters per pagepagepage number
It's used in case you need to reindex the whole data
An array of objects.