“Fuse.js” Kode Jawaban

Fuse.js

const Fuse = require('fuse.js') // or import Fuse from 'fuse.js'
// 1. List of items to search in
const books = [
  {
    title: "Old Man's War",
    author: {
      firstName: 'John',
      lastName: 'Scalzi'
    }
  },
  {
    title: 'The Lock Artist',
    author: {
      firstName: 'Steve',
      lastName: 'Hamilton'
    }
  }
]

// 2. Set up the Fuse instance
const fuse = new Fuse(books, {
  keys: ['title', 'author.firstName']
})

// 3. Now search!
fuse.search('jon')

// Output:
// [
//   {
//     item: {
//       title: "Old Man's War",
//       author: {
//         firstName: 'John',
//         lastName: 'Scalzi'
//       }
//     },
//     refIndex: 0
//   }
// ]
Wandering Walrus

Fuse.js

npm install fuse.js or yarn add fuse.js
Wandering Walrus

Fuse.js

const Fuse = require('fuse.js')
Wandering Walrus

Fuse.js

import Fuse from 'fuse.js'
Wandering Walrus

JavaScript Fuzzy Search

const options = {
  includeScore: true,
  // Search in `author` and in `tags` array
  keys: ['author', 'tags']
}

const fuse = new Fuse(list, options)

const result = fuse.search('tion')
The Arborist

JavaScript pencarian fuzzy

// This can be excluded when loaded via <script>import FuzzySearch from 'fuzzy-search'; // Or: var FuzzySearch = require('fuzzy-search'); const people = [{  name: {    firstName: 'Jesse',    lastName: 'Bowen',  },  state: 'Seattle',}]; const searcher = new FuzzySearch(people, ['name.firstName', 'state'], {  caseSensitive: true,});const result = searcher.search('ess');
Mysterious Mantis

Jawaban yang mirip dengan “Fuse.js”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya