krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
17.76k stars 753 forks source link

Logical query with pattern without key #736

Closed ashtraysoap closed 3 months ago

ashtraysoap commented 10 months ago

Is there an existing issue or pull request for this?

Feature description

Is there a way to perform a logical query containing a simple pattern without key speciication (e.g. { $and: [{ key1: "abc"}, "xyz"]}).

Trying the pattern from the example yields no matches even though there should be some.

Is there an altenative way to achieve this query in Fuse, or is it not supported?

Desired solution

Ideally, the pattern exemplified in { $and: [{ key1: "abc"}, "xyz"]} would work so that it would return results containing a match for "abc" in the key key1 and simultaneously a match for in xyz in any of the indexed fields (similarly to fuse.search("xyz")).

Alternatives considered

I've found no way to achieve given query in Fuse.The query pattern seems relatively orthodox (at least in my usecase), it would be helpful, if it was supported by the library.

Additional context

No response

krisk commented 8 months ago

Could you give an example list and search query to show the above? Ultimately the way logical operators work is by operating on a single list item, so the item itself would have to be match both patterns in the AND query. Perhaps I am not fully understanding the feature ask, so an example would help. Thanks! :)

github-actions[bot] commented 4 months ago

This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 30 days

ashtraysoap commented 1 week ago

Thanks for the reply, and my apologies for my delay.

Given the input data: [ { name: "Albert", city: "London", }, { name: "Albert", city: "Paris", }, { name: "Arnold", city: "Paris" }, ]

I want to achieve the following filter: match all items with Albert in name and Paris in any other field.

I would expect the query { $and: [{ name: "Albert"}, "Paris"]} to achieve this, however it does not work.

Thanks!