Skip to content

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

@vayyala

Description

@vayyala

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions