question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fuzzy search same model, but different fields

See original GitHub issue

Hi.

I have and model named Article that contains the tilte and content .

let mongoose = require('mongoose');
let Schema = mongoose.Schema;  
var mongoose_fuzzy_searching = require('mongoose-fuzzy-searching');

var ArticleSchema = new Schema({
    title: {
        type: String,
    },
   content: {
        type: String,
    },
})

module.exports = mongoose.model('Article', ArticleSchema);

The model is exported and used in another .js. How can I fuzzy search the title and content separately, without declaring

ArticleSchema.plugin(mongoose_fuzzy_searching, {fields: ['title', 'content']});

in the model schema file?

I want to have 2 functions that search articles one by the title, and the other one by the content, separately.

If I put the

ArticleSchema.plugin(mongoose_fuzzy_searching, {fields: ['title', 'content']});

then my both functions will use title and content for the fuzzy search.

Can I achieve something like this?

function a() {
    ArticleSchema.plugin(mongoose_fuzzy_searching, {fields: ['title']});
    fuzzySearch();
}
function b() {
    ArticleSchema.plugin(mongoose_fuzzy_searching, {fields: ['content']});
    fuzzySearch();
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
VassilisPallascommented, Mar 11, 2020

But this is a very nice idea though, I will add it on the backlog.

0reactions
19007361commented, Feb 5, 2022

so if I have const Post = PostSchema.plugin(mongoose_fuzzy_searching, {fields: ['start', 'end']})

and then, without fuzzy search, I would search like this: Post.find({ start: "abc", end: "def, })

With this package, there will not be a way to fuzzy search different strings for each of the fields “start” and “end”?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fuzzy Matching | String-Searching Algorithms & Example
Fuzzy matching allows you to identify non-exact matches of your target item. It is the foundation stone of many search engine frameworks and ......
Read more >
Fuzzy Matching or Fuzzy Logic Algorithms Explained - Nanonets
Fuzzy Matching (also called Approximate String Matching) is a technique that helps identify two elements of text, strings, or entries that are ...
Read more >
Fuzzy Matching 101: Cleaning and Linking Messy Data
Fuzzy matching identifies the likelihood that two records are a true match based on whether they agree or disagree on the various identifiers....
Read more >
There's more to fuzzy search than correcting typos | Algolia Blog
Fuzzy search matches words even if there are typos or misspellings, and fuzzy matching finds information based on similarities.
Read more >
What is a Fuzzy Search? - TechTarget
What are the pros and cons of fuzzy matching? · It sometimes returns too many results, requiring the user to sift through all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found