mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
(cherry picked from commit 022e59f241
)
Co-authored-by: Mark Hopkin <mark.hopkin@elastic.co>
This commit is contained in:
parent
e73f29edfc
commit
bba1cbfa7d
1 changed files with 6 additions and 8 deletions
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import { Search as LocalSearch, PrefixIndexStrategy } from 'js-search';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useRef } from 'react';
|
||||
|
||||
import type { IntegrationCardItem } from '../../../../common/types/models';
|
||||
|
||||
|
@ -16,13 +16,11 @@ export const fieldsToSearch = ['name', 'title'];
|
|||
export function useLocalSearch(packageList: IntegrationCardItem[]) {
|
||||
const localSearchRef = useRef<LocalSearch>(new LocalSearch(searchIdField));
|
||||
|
||||
useEffect(() => {
|
||||
const localSearch = new LocalSearch(searchIdField);
|
||||
localSearch.indexStrategy = new PrefixIndexStrategy();
|
||||
fieldsToSearch.forEach((field) => localSearch.addIndex(field));
|
||||
localSearch.addDocuments(packageList);
|
||||
localSearchRef.current = localSearch;
|
||||
}, [packageList]);
|
||||
const localSearch = new LocalSearch(searchIdField);
|
||||
localSearch.indexStrategy = new PrefixIndexStrategy();
|
||||
fieldsToSearch.forEach((field) => localSearch.addIndex(field));
|
||||
localSearch.addDocuments(packageList);
|
||||
localSearchRef.current = localSearch;
|
||||
|
||||
return localSearchRef;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue