plugin-search icon indicating copy to clipboard operation
plugin-search copied to clipboard

refactor: support Fuse.js 6.x.x

Open cuebit opened this issue 5 years ago • 1 comments

Type of PR:

  • [ ] Bugfix
  • [x] Feature
  • [ ] Code style update
  • [x] Refactor
  • [x] Build-related changes
  • [x] Documentation
  • [x] Other, please describe:
    • Depedency upgrade (Fuse.js)

Breaking changes:

  • [ ] No
  • [x] Yes (allegedly)

Details

This PR brings the plugin to a much needed alignment with the latest version of Fuse.js (v6 at time of writing). As of v6, the lib has improved significantly concerning performance and additions for extensive search capability.

Breaking Changes

Fuse v6 does introduces breaking changes, most notably the formatting of search results which now incorporate a search score, character matches, etc.

// Example of the library output:
type SearchResult = {
  item: Model
  refIndex: number
  score?: number
  matches?: Array<{
    indices: Array<[number, number]>
    key?: string
    refIndex?: number
    value?: string
  }>
}

We can alleviate these by continuing to return a model collection. That being said, the raw search results are still accessible, should they be needed for the additional metadata, on the query instance the search modifier was applied:

const query = Model.query().search(...)
const results = query.get()

console.log(query.searchResults)

To mitigate any migration complications, much of the refactoring takes legacy input into consideration. For example, array inputs are still a valid form of expression:

Model.query().search('vuex orm')
// is the equivalent of
Model.query().search(['vuex', 'orm'])

Various options have been removed including, but not limited to, tokenization options, maxPatternLength, matchAllTokens and id. These aren't considering breaking changes per-se, but can have an impact on expectations.

See the library CHANGELOG for more information.

TODO

  • [ ] Update documentation

cuebit avatar Sep 03 '20 02:09 cuebit

Codecov Report

Merging #15 into dev will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##               dev       #15   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines           35        41    +6     
  Branches         5         5           
=========================================
+ Hits            35        41    +6     
Impacted Files Coverage Δ
src/VuexORMSearch.ts 100.00% <ø> (ø)
src/config/DefaultOptions.ts 100.00% <100.00%> (ø)
src/index.ts 100.00% <100.00%> (ø)
src/mixins/Query.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 76a1d41...fc7499a. Read the comment docs.

codecov[bot] avatar Sep 03 '20 02:09 codecov[bot]