krisk / Fuse

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

Can't exclude result using extended search #473

Closed crawazaky closed 4 years ago

crawazaky commented 4 years ago

Hello,

My list object look like this:

[
   {
      "id":1,
      "name":"test 1",
      "styles":[
         "tagA",
         "tagB"
      ]
   },
   {
      "id":2,
      "name":"placeholder 2",
       "styles":[
         "tagB",
         "tagA"
      ]
   },
   {
      "id":3,
      "name":"test 3",
      "styles":[
         "tagA"
      ]
   },
   {
      "id":4,
      "name":"placeholder 4",
      "styles":[
         "tagA"
      ]
   }
]

and my option look like this:

      searchOptions: {
          includeScore: true,
          useExtendedSearch: true,
          minMatchCharLength: 3,
          ignoreLocation: true,
          keys: ['name', 'styles']
      }

I am trying to remove from my search results the entries where the styles has certain tag(s).

I believe a search query like this test !tagA should give my no result as both items with testin their name has a tagAstyles.

But actually it will still show me id: 1as it contain tagB.. Which is not the logic I expected. I would like to totally exclude the entries when any key contain a value I excluded using !<keyword>.

My final goal is to be able to select many tags to exclude and append them to my query before running the search like this:

<keyword> !<tag1> !<tag2> !<tag3>

Is that possible or am I missing something ?

thanks a lot

crawazaky commented 4 years ago

Waiting for a proper answer, what I'm doing is using the filter() function to filter any search result entry with the styles array containing one of the tag I want to exclude.

Won't share my code as it's pretty dirty. Hopefully there is a built-in function to do the same.

github-actions[bot] commented 4 years ago

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