forked from AdrianBZG/InterMine-Data-Browser-Tool
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: filter classes on a search query (#90)
The classes select menu did not filter when queried, and would did not update when the mine was changed. This commit fixes this by indexing the available classes on first render and each time the mine changes. Closes: #89 Squashed commits: Change available classes when the mine changes Rebuild search index when the mine changes Reset the query when the popup closes
- Loading branch information
Showing
4 changed files
with
94 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import FlexSearch from 'flexsearch' | ||
|
||
import { indexWorker } from './searchIndex' | ||
|
||
export const buildSearchIndex = async ({ docId, docField, values }) => { | ||
// The configuration *must* be the same for import and export | ||
const indexConfig = { | ||
encode: 'advanced', | ||
tokenize: 'reverse', | ||
suggest: true, | ||
cache: true, | ||
doc: { | ||
id: docId, | ||
field: docField, | ||
}, | ||
} | ||
|
||
const exportConfig = { | ||
index: true, | ||
doc: true, | ||
} | ||
|
||
// @ts-ignore | ||
const index = new FlexSearch(indexConfig) | ||
|
||
if (typeof window !== 'undefined' && window.Worker) { | ||
const serializedIndex = await indexWorker.index({ | ||
values, | ||
indexConfig, | ||
exportConfig, | ||
}) | ||
|
||
// @ts-ignore | ||
index.import(serializedIndex, exportConfig) | ||
} else { | ||
// @ts-ignore | ||
index.add(values) | ||
} | ||
|
||
return index | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters