Full text, faceted, dependency free search engine in javascript. Created to perform fast search on small json dataset (up to 1000 elements).
- faceted search
- full text
- pagination
- no dependencies (only javascript)
npm install itemsjsconst itemsjs = require('itemsjs')(data, configuration);
const items = itemsjs.search();or using from the client side:
npm install itemsjs<script src="/node_modules/itemsjs/dist/itemsjs.js"></script>itemsjs = itemsjs(data, configuration);
itemsjs.search()npm 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
},
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.jsThe 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.
-
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']}
It returns full list of filters for specific aggregation
-
nameaggregation name -
per_pagefilters per page -
pagepage number -
queryused for quering filters. It's not full text search
It's used in case you need to reindex the whole data
An array of objects.
- Lunr.js for providing full text search.