krisk / Fuse

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

Add an option to return the raw search data #532

Closed danitrod closed 3 years ago

danitrod commented 3 years ago

Description

I'm not sure if I'm missing something, but I would like Fuse to return the search objects for me without refIndex and the item labeling. Right now I have to loop one more time after having the search results, to have my objects again.

Describe the solution you'd like

What I have is this response:

[
  {
    "item": {
      "title": "Right Ho Jeeves",
      "author": "P.D. Mans",
      "tags": ["fiction", "war"]
    },
    "refIndex": 1
  },
  {
    "item": {
      "title": "Old Man's War fiction",
      "author": "John X",
      "tags": ["war"]
    },
    "refIndex": 0
  }
]

What I would like is this response:

[
  {
    "title": "Right Ho Jeeves",
    "author": "P.D. Mans",
    "tags": ["fiction", "war"]
  },
  {
    "title": "Old Man's War fiction",
    "author": "John X",
    "tags": ["war"]
  }
]

It would be useful when the score/refIndex are not needed.

Describe alternatives you've considered

I looked at the available options but none seem to solve this. The current workaround is to loop through and 'restore' the search results, but it's more complexity added for no reason.

danitrod commented 3 years ago

I'd be willing to add this feature if the maintainers are interested in merging this.

charliegroll commented 3 years ago

I'm curious if this is that useful to you since all that's needed is .map(r => r.item) on the results

danitrod commented 3 years ago

True. I think it would be nice to have the option to get the raw values, though. It would decrease the loading time a little bit with larger amounts of data, and it doesn't seem to have any drawbacks.

github-actions[bot] commented 3 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