comigor / fuzzy

Fuzzy search in Dart
MIT License
37 stars 20 forks source link

Result score with tokenize = true ignores token score average #17

Closed luistrivelatto closed 3 years ago

luistrivelatto commented 3 years ago

I was debugging some searches with tokenize = true and noticed that the search result score didn't seem to consider the token score average, only the mainSearchResult.score (i.e. the full text score). According to the code, it seems that, when there is a token score average, the final result score should be the average of full text score / token score:

156    var averageScore = -1;
...
...       [code that computes averageScore]
...
199    var finalScore = mainSearchResult.score;
200    if (averageScore > -1) {
201      finalScore = (finalScore + averageScore) / 2;
202    }

The problem is that the code that computes averageScore is inside a scope which declares a new averageScore variable, then the original variable never gets updated

162    if (options.tokenize) {
...
...         [code that searches through tokens]
...
193      final averageScore =    <<<<< this shouldn't be a declaration
194          scores.fold(0, (memo, score) => memo + score) / scores.length;
195
196      _log('Token score average: $averageScore');
197    }
198
199    var finalScore = mainSearchResult.score;
200    if (averageScore > -1) {
201      finalScore = (finalScore + averageScore) / 2;
202    }