Download client/modules/querySuggestions.ts from abhijeetsarkargis/MiniSearch: direct link, hf CLI and curl.
- Browser
- Download file 928 Bytes
-
https://huggingface.co/spaces/abhijeetsarkargis/MiniSearch/resolve/main/client/modules/querySuggestions.ts
- Command line
-
hf download hf://spaces/abhijeetsarkargis/MiniSearch/client/modules/querySuggestions.ts
-
curl -L -o querySuggestions.ts https://huggingface.co/spaces/abhijeetsarkargis/MiniSearch/resolve/main/client/modules/querySuggestions.ts
928 Bytes
| import { addLogEntry } from "./logEntries"; | |
| import { getQuerySuggestions, updateQuerySuggestions } from "./pubSub"; | |
| export async function getRandomQuerySuggestion() { | |
| if (getQuerySuggestions().length === 0) await refillQuerySuggestions(25); | |
| const querySuggestions = getQuerySuggestions(); | |
| const randomQuerySuggestion = querySuggestions.pop() as string; | |
| updateQuerySuggestions(querySuggestions); | |
| return randomQuerySuggestion; | |
| } | |
| async function refillQuerySuggestions(limit?: number) { | |
| const querySuggestionsFileUrl = new URL( | |
| "/query-suggestions.json", | |
| self.location.origin, | |
| ); | |
| const fetchResponse = await fetch(querySuggestionsFileUrl.toString()); | |
| const querySuggestionsList: string[] = await fetchResponse.json(); | |
| updateQuerySuggestions( | |
| querySuggestionsList.sort(() => Math.random() - 0.5).slice(0, limit), | |
| ); | |
| addLogEntry(`Query suggestions refilled with ${limit} suggestions`); | |
| } | |