mongoose full-text search plugin

npm install mongoose-search-plugin
2 downloads in the last day
18 downloads in the last week
100 downloads in the last month

Mongoose full-text search plugin

Simple mongoose plugin for full text search. Uses [natural] stemming and distance algorythms.


  var mongoose = require('mongoose'),
    searchPlugin = require('mongoose-search-plugin');

  var Schema = mongoose.Schema({
    title: String,
    descirption: String,
    tags: [String]

    fields: ['title', 'description', 'tags']

  var Model = mongoose.model('MySearchModel', Schema);'some query', {title: 1}, {
    conditions: {title: {$exists: true}},
    sort: {title: 1},
    limit: 10
  }, function(err, data) {
    // array of finded results
    // count of all matching objects


  $ npm install mongoose-search-plugin --save



plugin accepts options argument with following format:

  var options = {
    keywordsPath: '_keywords', // path for keywords, `_keywords` as default
    relevancePath: '_relevance', // path for relevance number, '_relevance' as default
    fields: [], // array of fields to use as keywords (can be String or [String] types),
    stemmer: 'PorterStemmer', // natural stemmer, PorterStemmer as default
    distance: 'JaroWinklerDistance' // distance algorythm, JaroWinklerDistance as default
  Schema.plugin(searchPlugin(options));, fields, options, callback) options are optional. Method will return object of the following format:

    results: [], // array of results objects
    totalCount: 0 // number of objects, that matched criteries

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.setKeywords(function(err) {
    // ...

License: MIT

npm loves you