elasticlunr

elasticlunr

function
elasticlunr()

Option name Type Description
config Function

A function that will be called with the new instance of the elasticlunr.Index as both its context and first parameter. It can be used to
customize the instance of new elasticlunr.Index.

return elasticlunr.Index

Convenience function for instantiating a new elasticLunr index and configuring it
with the default pipeline functions and the passed config function.

When using this convenience function a new index will be created with the
following functions already in the pipeline:

elasticlunr.StopWordFilter - filters out any stop words before they enter the
index

elasticlunr.stemmer - stems the tokens before entering the index.

Example:

var idx = elasticLunr(function () {
  this.addField('id')
  this.addField('title')
  this.addField('body')

  //this.setRef('cid') // default ref is 'id'

  this.pipeline.add(function () {
    // some custom pipeline function
  })

})

idx.addDoc({
id: 1,
title: 'Oracle released database 12g',
body: 'Yestaday, Oracle has released their latest database, named 12g, more robust. this product will increase Oracle profit.'
});

idx.addDoc({
id: 2,
title: 'Oracle released annual profit report',
body: 'Yestaday, Oracle has released their annual profit report of 2015, total profit is 12.5 Billion.'
});

search with query-time boosting

idx.search('oracle database', {fields: {title: {boost: 2}, body: {boost: 1}}})

var elasticlunr = function (config) {
  var idx = new elasticlunr.Index;

  idx.pipeline.add(
    elasticlunr.trimmer,
    elasticlunr.stopWordFilter,
    elasticlunr.stemmer
  );

  if (config) config.call(idx, idx);

  return idx;
};

elasticlunr.version = "@VERSION";