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 },
],
});
minhhien1996/mongoose-plugin-ngram-text-search
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published