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

Results Not Sorted by Relevance for Simple Queries Using match Preset #448

Open
ChandraNakka opened this issue Aug 6, 2024 · 0 comments

Comments

@ChandraNakka
Copy link

ChandraNakka commented Aug 6, 2024

Description
When performing a search for the phrase 'cats cute' using the match preset and forward tokenization, the results are returned in the order they were added, without sorting by closest match to the search phrase.

Steps to Reproduce

  1. Initialize a FlexSearch index with the match preset and forward tokenization.
  2. Add a series of strings to the index, each progressively shorter and varying by the inclusion of additional words.
  3. Perform a search for the phrase 'cats cute'.

Expected Behavior
The search results should be sorted by relevance, with the string closest to 'cats cute' appearing first, followed by others in decreasing order of match closeness.

Actual Behavior
The search results are returned in the order of their insertion into the index, without any apparent sorting based on the query relevance.

Code to Reproduce

import FlexSearch from 'flexsearch';

const data = [
    'cats abcd efgh ijkl mnop qrst uvwx cute',
    'cats abcd efgh ijkl mnop qrst cute',
    'cats abcd efgh ijkl mnop cute',
    'cats abcd efgh ijkl cute',
    'cats abcd efgh cute',
    'cats abcd cute',
    'cats cute',
];

const index = new FlexSearch.Index({preset: 'match', tokenize: "forward"});

data.forEach((item, id) => {
    index.add(id, item);
});

index.search('cats cute').forEach(i => {
    console.log(data[i]);
});

Output

cats abcd efgh ijkl mnop qrst uvwx cute
cats abcd efgh ijkl mnop qrst cute
cats abcd efgh ijkl mnop cute
cats abcd efgh ijkl cute
cats abcd efgh cute
cats abcd cute
cats cute

Additional Information
This behavior may lead to inefficiencies and unexpected results in applications relying on relevance-based sorting for search functionality.

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

1 participant