mongoose-plugin-ngram-text-search

README


Keywords
mongoose, text-search, fulltext, mongoose-plugin, search, text, n-gram
License
ISC
Install
npm install mongoose-plugin-ngram-text-search@1.0.5

Documentation

Usage

import nGramTextSearch from 'mongoose-plugin-ngram-text-search';

const userSchema = new mongoose.Schema({
  email: String,
  name: String,
  username: String,
  // your other fields...
});

// function used to extract to text to indexing from a field
const extractUsernameFromEmail = (str = '') => str.split('@')[0];

userSchema.plugin(nGramTextSearch, {
  nGramSizeMin: 1,
  nGramSizeMax: 8,
  edgeNGrams: true,
  fields: [
    { name: 'username' },
    { name: 'name' },
    { name: 'email', extractFn: extractUsernameFromEmail },
  ],
});