Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exact match result is not the first item returned #85

Open
alex-galey opened this issue Feb 20, 2021 · 2 comments
Open

Exact match result is not the first item returned #85

alex-galey opened this issue Feb 20, 2021 · 2 comments

Comments

@alex-galey
Copy link

Do you want to request a feature, an issue, or report a bug?
Issue

What is the current behaviour?
Exact match result is not the first item returned

If the current behaviour is a bug, please provide the steps to reproduce.
This is the returned array for the query=lille with City.fuzzySearch(query).limit(5).exec() :

[
  { "nom": "Lillers",      "confidenceScore": 4.300000000000001 },
  { "nom": "Lillemer",     "confidenceScore": 4.300000000000001 },
  { "nom": "Lille",        "confidenceScore": 4.300000000000001 },
  { "nom": "Lillebonne",   "confidenceScore": 4.300000000000001 },
  { "nom": "Ille-sur-Têt", "confidenceScore": 4.2               }
]

What is the expected behaviour?
Exact match "Lille" should have a higher confidenceScore than the others

I'm using this function to bring the exact match up :

for (let i=0; i<answer.length; i++) {
    if (answer[i].nom.toLowerCase() === query) {
        answer.unshift(answer[i]);
        answer.splice(i+1,1);
    }
}

If this is a feature request, what is the motivation or use case for changing
the behaviour?

Please mention other relevant information such as Node.js and mongoose version.
node v14.4.0
mongoose 5.11.15

@coolb0y
Copy link

coolb0y commented Jan 25, 2022

You can solve this issue by sorting this array by metascore that is confidence score the top results(all having highest confidance score) by length in increating order so "Lille" will always come first . I think even if they are not sorting result I think "Lille" should still be higher than other result with same score as gramitically "Lille" will appear higher in database than other words .

@alex-galey
Copy link
Author

What I meant is confidenceScore should be influenced by the "exact matching" factor.

Don't you / doesn't anyone think it should ?

(I didn't try this again recently)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants