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

[Feature request] Support scoring arrays of strings, in addition to single strings #12

Open
vayyala opened this issue Feb 22, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@vayyala
Copy link

vayyala commented Feb 22, 2021

Hi there! Thanks for this library. I've been trying out different search libraries for a project, and have been really impressed thus far with quickscore!

One feature that would be super helpful is support for keys that reference non-string values.

Example 1: Array

const bookmarks = [
    {
        "title": "lodash documentation",
        "url": "https://lodash.com/docs",
        "labels": ["work docs", "recently added"]
    },
    {
        "title": "Supplying Images - Google Chrome",
        "url": "developer.chrome.com/webstore/images",
        "labels": ["favorites", "hobby"]
    },
    ...
];

It'd be really useful to have support for const qs = new QuickScore(bookmarks, ["title", "labels"]);.

One quick solution would be to join the array to a string, but that has some difficulties with search matches. I.e., "work added" would match the first result with a high score, when it should probably have a lower score if each label was considered separately.

Example 2: Array of objects

This would be really cool, but also handleable by pre-processing if Example 1 is supported.

const bookmarks = [
    {
        "title": "lodash documentation",
        "url": "https://lodash.com/docs",
        "labels": [{"name": "work docs", "id": 1},{"name": "recently added", "id": 2}]
    },
    {
        "title": "Supplying Images - Google Chrome",
        "url": "developer.chrome.com/webstore/images",
        "labels": [{"name": "favorites", "id": 3},{"name": "hobbies", "id": 4}]
    },
    ...
];

const qs = new QuickScore(bookmarks, ["title", "labels.name"]);

I think fuse supports both of these use cases, but haven't seen other libraries that do. Would be awesome if quickscore supported it!

@fwextensions
Copy link
Owner

fwextensions commented Feb 22, 2021

Thanks for the feedback! I was actually just thinking about matching against an array of strings, from a discussion in #11.

Would you expect the score for an array of strings to be highest score for any of the strings? The average?

Another complexity is returning which string matched. Not sure if that should be an index into the array or the actual string containing the match. It's also tricky if multiple strings have the same score.

"work added" would match the first result with a high score, when it should probably have a lower score if each label was considered separately.

Matching the "work added" query against the individual strings would actually return 0 for each one, since neither contains all of those characters.

@vayyala
Copy link
Author

vayyala commented Feb 22, 2021

Absolutely! Thanks for working on this library :)

Work you expect the score for an array of strings to be highest score for any of the strings? The average?

I think what would be ideal would be if the score matched the highest of the strings. We only use the score to sort the options, and in the case that there's a match to one of the elements in the array, we'd want to show it near the top.

Another complexity is returning which string matched. Not sure if that should be an index into the array or the actual string containing the match.

What fuse does is to return another field in the search result that corresponds to the full matched value. I guess the analogous field here would be a scoreValue field to correspond to the current scoreKey. Index would also work great for us, but I suspect the scoreValue might be more elegant for general use cases.

It's also tricky if multiple strings have the same score.

Ah yes this might be tricky. In our use case, if multiple strings have the same score, having only one of them would be more than sufficient. What's currently done today in the scoreKey field if there are multiple matches with the same score?

@fwextensions
Copy link
Owner

What's currently done today in the scoreKey field if there are multiple matches with the same score?

The first key in the keys array wins, so maybe the same could be done with an array of strings.

@fwextensions fwextensions changed the title Pass in a searchable key that maps to an array of strings [Feature request] Support scoring arrays of strings, in addition to single strings Feb 24, 2021
@fwextensions fwextensions added the enhancement New feature or request label Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants