Skip to content

When using Fuse's useExtendedSearch, format-fuse can return overlapping matches #42

Open
@fpintos

Description

Performing a Fuse extended search for 'sao paulo' on an item that contains the text 'SAO PAULO' yields matches for [ [ 0, 2 ], [ 1, 2 ], [ 4, 8 ] ], and format-fuse returns them as SAO, AO an PAULO. Rendering those as shown in the readme causes the UI to show "SAOAO PAULO". Ideally, the resulting value would eliminate overlapping matches.

Example:

const Fuse = require('fuse.js');
const formatFuseJs = require('format-fuse.js').default;
const util = require('util');

const r = new Fuse([{ name: 'SAO PAULO' }], {
    keys: ['name'],
    includeMatches: true,
    includeScore: true,
    useExtendedSearch: true,
})
    .search('sao paulo')
    .map(s => ({ ...s, formatted: formatFuseJs([s])[0] }));

console.log(util.inspect(r, { showHidden: false, depth: null, colors: true }));

Actual:

[
  {
    item: { name: 'SAO PAULO' },
    refIndex: 0,
    matches: [
      {
        indices: [ [ 0, 2 ], [ 1, 2 ], [ 4, 8 ] ],
        value: 'SAO PAULO',
        key: 'name'
      }
    ],
    score: 0.06403390388180329,
    formatted: {
      name: [
        { text: 'SAO', matches: true },
        { text: 'AO', matches: true },
        { text: ' ', matches: false },
        { text: 'PAULO', matches: true }
      ]
    }
  }
]

Expected:

[
  {
    item: { name: 'SAO PAULO' },
    refIndex: 0,
    matches: [
      {
        indices: [ [ 0, 2 ], [ 1, 2 ], [ 4, 8 ] ],
        value: 'SAO PAULO',
        key: 'name'
      }
    ],
    score: 0.06403390388180329,
    formatted: {
      name: [
        { text: 'SAO', matches: true },
        { text: ' ', matches: false },
        { text: 'PAULO', matches: true }
      ]
    }
  }
]

Activity

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions