-
|
Hi there, I've been experimenting with a site search box positioned on a main page of my site, as opposed to tucked away in the sidebar. The code below works where I have manually copied across the search index /dist/_observablehq/minisearch.XXXX.json from the previous build to my src folder. Does anyone have any suggestions how I might access the latest index file from the latest build in the same way as the search box in the sidebar? import MiniSearch from 'minisearch';
const texts = view(Inputs.text());
const searchIndex = await FileAttachment("path/to/minisearch.json").text();
const index = MiniSearch.loadJSON(searchIndex, { fields: ['title', 'text', 'keyword'] });Inputs.table(index.search(texts, { fuzzy: 0.1 }))Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
This comment has been hidden.
This comment has been hidden.
-
|
Thanks, then I think I will need to build the site twice, the second time after copying out the index generated in the first build |
Beta Was this translation helpful? Give feedback.
-
|
Did you try loading it the same way as the built-in search, using framework/src/client/search.js Line 11 in 5745573 |
Beta Was this translation helpful? Give feedback.
-
|
Oh perfect, exactly what I was looking for. This works to import the index const index = await fetch(import.meta.resolve("observablehq:minisearch.json")).
then((response) => {
if (!response.ok) throw new Error(`unable to load minisearch.json: ${response.status}`);
return response.json();
}).then((json) =>
MiniSearch.loadJS(json, { fields: ['title', 'text', 'keyword'] })
)which I can then use as above. Thank you both! |
Beta Was this translation helpful? Give feedback.
Oh perfect, exactly what I was looking for. This works to import the index
which I can then use as above. Thank you both!