1.0.5 • Published 5 years ago

mongoose-plugin-ngram-text-search v1.0.5

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

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 },
  ],
});