Mongoose full-text search plugin
Simple mongoose plugin for full text search. Uses natural stemming and distance algorythms.
Example
var mongoose =searchPlugin = ;var Schema = mongoose;Schema;var Model = mongoose;Model;
Installation
$ npm install mongoose-search-plugin --save
Usage
Initialization
plugin
accepts options argument with following format:
var options =keywordsPath: '_keywords' // path for keywords, `_keywords` as defaultrelevancePath: '_relevance' // path for relevance number, '_relevance' as defaultfields: // array of fields to use as keywords (can be String or [String] types),stemmer: 'PorterStemmer' // natural stemmer, PorterStemmer as defaultdistance: 'JaroWinklerDistance' // distance algorythm, JaroWinklerDistance as default;Schema;
Search
Model.search(query, fields, options, callback)
options are optional.
Method will return object of the following format:
results: // array of results objectstotalCount: 0 // number of objects, that matched criteries
Options has following format:
conditions: {} // criteria for query sort: {} // sorting parameters populate: path: '' fields: '' // array of paths to populate ... and other options of Modelfind method
By default results sorts by relevance field, that defined in relevancePath
plugin option.
Set keywords
If You start using plugin on existing database to initialize keywords field in object
use setKeywords
method.
Model;