This library is a search engine implemented in javascript for local searches. It works very well with a few thousands of items but it is not intended to be used for indexing billions of content (it will work though).

To work with it, just add the following script :
<script src="/scripts/winjscontrib/mcnext.search.js"></script>


The search engine will index your content and use stemming to provide some fault tolerance. The built-in stemming pipeline is designed for english and french. Implementing one for other languages will be very easy. If you build one, do not hesitate to provide it and we will integrate it.

The engine allow for multiple indexes, and indexes could be persited on disk. An index must have a name, and a definition. The definition tell the engine wich field of an object must be indexed, and what weight you could credit this field. The weight is then used to rank the search results.

Let says that you want to index objects of this kind :
var myObject = {
	title : 'the best title ever',
	description: 'the item description'
}


Building an index is straightforward :
var myindex = new MCNEXT.Search.Index('myobjects', { fields: { "title": 10, "description": 1 } });


Now if you want to index content :
myindex.add(myObject);


You could also add multiple items at once :
myindex.addRange([myObject]);

You could persist the index, or re-hydrate it using the "save" and "load" methods

Now that you have content in your index, searching is as easy as
var result = myindex.search('title ever');


The search engine could work asynchronously through a worker thread. The worker could be used for indexing (addRangeAsync) or search (searchAsync);

If you want to partition your data in multiple indexes and search in all at once, you could use the IndexGroup object.

var indexGroup = new MCNEXT.Search.IndexGroup({ 
	myIndexName : {
		title : 'the best title ever',
		description: 'the item description'
	},
	otherIndexName : {
		title : 'the best title ever',
		description: 'the item description'
	}
});
searchIndex.indexes.myIndexName.add(myObject);
searchIndex.indexes.otherIndexName.add(myObject);
searchIndex.save();
var res = searchIndex.search('title ever');

Last edited Apr 11, 2014 at 8:24 AM by gleborgne, version 2