Skip to content

Commit

Permalink
Search integrations for all substrings + don't search on description
Browse files Browse the repository at this point in the history
  • Loading branch information
kpollich committed Jul 1, 2021
1 parent 2f25c26 commit e472fe2
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
* 2.0.
*/

import { Search as LocalSearch } from 'js-search';
import { Search as LocalSearch, AllSubstringsIndexStrategy } from 'js-search';
import { useEffect, useRef } from 'react';

import type { PackageList } from '../../../types';

export const searchIdField = 'id';
export const fieldsToSearch = ['description', 'name', 'title'];
export const fieldsToSearch = ['name', 'title'];

export function useLocalSearch(packageList: PackageList) {
const localSearchRef = useRef<LocalSearch | null>(null);

useEffect(() => {
const localSearch = new LocalSearch(searchIdField);
localSearch.indexStrategy = new AllSubstringsIndexStrategy();
fieldsToSearch.forEach((field) => localSearch.addIndex(field));
localSearch.addDocuments(packageList);
localSearchRef.current = localSearch;
Expand Down

0 comments on commit e472fe2

Please sign in to comment.