Skip to content

Score not showing properly #8

Description

@thencke

First of all, amazing library. But, I guess the score property of result object is always zero (even when it hasn't found any matches).

Example:

void testFuzzy() {
    final fuse = Fuzzy(
      [
        Person('John', 'Doe', 29),
        Person('Jane', 'Doe', 32),
        Person('Peter', 'Parker', 36),
        Person('Bruce', 'Wayne', 30),
        Person('Clark', 'Kent', 50),
        Person('Tony', 'Stark', 34),
        Person('Clint', 'Barton', 35),
      ],
      options: FuzzyOptions(
        keys: [WeightedKey<Person>(name: 'firstname', getter: (p) => p.firstname, weight: 1)],
        shouldNormalize: true,
        isCaseSensitive: false,
        shouldSort: false,
        findAllMatches: false,
        verbose: true,
      ),
    );

    var result = fuse.search('John');

    if (result.isNotEmpty) {
      result
          .forEach((r) => print('${r.item.firstname} ${r.item.surname} (${r.item.age}) | score: ${r.score}'));
    } else {
      print('no results');
    }
  }


class Person {
  final String firstname;
  final String surname;
  final int age;

  Person(this.firstname, this.surname, this.age);
}

output shows:

flutter: Full text: "John", score: 0.0
flutter: Score average (final): 0.0
flutter:
Check Matches: true
flutter: Full text: "Jane", score: 0.5
flutter: Score average (final): 0.5
flutter:
Check Matches: true
flutter: Full text: "Peter", score: 1.0
flutter: Score average (final): 1.0
flutter:
Check Matches: true
flutter: Full text: "Bruce", score: 1.0
flutter: Score average (final): 1.0
flutter:
Check Matches: true
flutter: Full text: "Clark", score: 1.0
flutter: Score average (final): 1.0
flutter:
Check Matches: true
flutter: Full text: "Tony", score: 0.5
flutter: Score average (final): 0.5
flutter:
Check Matches: true
flutter: Full text: "Clint", score: 1.0
flutter: Score average (final): 1.0
flutter:
Check Matches: true
flutter:
Computing score:
flutter: John Doe (29) | score: 0.0
flutter: Jane Doe (32) | score: 0.0
flutter: Tony Stark (34) | score: 0.0

We can see that on verbose output the score is taken correctly, but when printing after search, is aways zero.

I can workaround it doing:

    result.forEach((r) => r.score = r.matches[0].score);
    result.sort((a,b) => a.score.compareTo(b.score));

But I'm not happy with this approach, is there a solution for this? Or perhaps I'm doing something wrong, please help.
Thanks in advance

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions