📜  Fuse.js CDN - Javascript (1)

📅  最后修改于: 2023-12-03 15:00:51.895000             🧑  作者: Mango

Fuse.js CDN - Javascript

Fuse.js is a lightweight and powerful fuzzy search library that enables you to build fast and responsive search interfaces. With this library, you can easily search through a large collection of data and retrieve the most relevant results based on the user's query.

Overview

Fuse.js is written in pure Javascript and can be integrated seamlessly into your web applications. It provides a variety of search algorithms and options to customize your search experience. Some key features of the library include:

  • Fuzzy searching
  • Exact matching
  • Token searching
  • Search threshold customization
  • Search result highlighting
Getting Started

To get started with Fuse.js CDN, you can simply include the following script tag in your HTML file:

<script src="https://cdn.jsdelivr.net/npm/fuse.js/dist/fuse.min.js"></script>

This will load the latest version of Fuse.js from the jsDelivr CDN.

Example Usage
// Define your data
const books = [
  {
    title: 'The Hitchhiker\'s Guide to the Galaxy',
    author: 'Douglas Adams'
  },
  {
    title: 'The Lord of the Rings',
    author: 'J.R.R. Tolkien'
  },
  {
    title: 'Harry Potter and the Sorcerer\'s Stone',
    author: 'J.K. Rowling'
  },
  {
    title: 'The Hobbit',
    author: 'J.R.R. Tolkien'
  }
];

// Initialize Fuse.js
const fuse = new Fuse(books, {
  keys: ['title', 'author']
});

// Search for books
const result = fuse.search('potter');

console.log(result);

This code defines an array of book objects and initializes a new instance of Fuse.js with the array and a configuration object specifying the keys to search. It then searches for books with a query of "potter" and logs the result to the console.

Documentation

For more information about how to use Fuse.js, check out the official documentation:

Fuse.js Documentation