# Examples


# Search String Array

# Search Object Array

You can search through nested values with different ways:

  • define the path with dot notation (.)
  • define the path with array notation ([])
  • Define a per-key getFn function

IMPORTANT

The path has to eventually point to a string, otherwise you will not get any results.

You can allocate a weight to keys to give them higher (or lower) values in search results. The weight value has to be greater than 0.

# Default weight

When a weight isn't provided, it will default to 1. In the following example, while author has been given a weight of 2, title will be assigned a weight of 1.

const fuse = new Fuse(books, {
  keys: [
    'title', // will be assigned a `weight` of 1
    {
      name: 'author',
      weight: 2
    }
  ]
})

Note that internally Fuse will normalize the weights to be within 0 and 1 exclusive.

This form of advanced searching allows you to fine-tune results.

White space acts as an AND operator, while a single pipe (|) character acts as an OR operator. To escape white space, use double quote ex. ="scheme language" for exact match.

Token Match type Description
jscript fuzzy-match Items that fuzzy match jscript
=scheme exact-match Items that are scheme
'python include-match Items that include python
!ruby inverse-exact-match Items that do not include ruby
^java prefix-exact-match Items that start with java
!^earlang inverse-prefix-exact-match Items that do not start with earlang
.js$ suffix-exact-match Items that end with .js
!.go$ inverse-suffix-exact-match Items that do not end with .go

White space acts as an AND operator, while a single pipe (|) character acts as an OR operator.

Last Updated: 5/8/2022, 1:53:59 PM