New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-search-plugin

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-search-plugin

mongoose full-text search plugin

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29
increased by163.64%
Maintainers
1
Weekly downloads
 
Created
Source

Mongoose full-text search plugin

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

Example

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

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

  Schema.plugin(searchPlugin, {
    fields: ['title', 'description', 'tags']
  });

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

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 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));

Model.search(query, 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
  }

Options has following format:

  {
    conditions: {}, // criteria for query
    sort: {} // sorting parameters
    populate: [{path: '', fields: ''}], // array of paths to populate
    ... and other options of Model.find 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.setKeywords(function(err) {
    // ...
  });

License: MIT

Keywords

FAQs

Package last updated on 22 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc