Skip to content

Commit

Permalink
Fixes and improvements to new demo
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaong committed Oct 5, 2023
1 parent e475be2 commit 56752b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
JavaScript. It is respectful of resources, and it can comfortably run both in
Node and in the browser.

Try out the [demo application](https://lucaong.github.io/minisearch/examples/).
Try out the [demo application](https://lucaong.github.io/minisearch/demo/).

Find the complete [documentation and API reference
here](https://lucaong.github.io/minisearch/classes/_minisearch_.minisearch.html),
Expand Down
10 changes: 6 additions & 4 deletions examples/plain_js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ $app.addEventListener('click', (event) => {
renderSuggestions([])
})

// Changing any advanced option recomputes the search option
// Changing any advanced option triggers a new search with the updated options
$options.addEventListener('change', (event) => {
recomputeSearchOptions()

const query = $searchInput.value
const results = getSearchResults(query)
renderSearchResults(results)
Expand All @@ -110,6 +108,7 @@ const searchOptions = {
}

const getSearchResults = (query) => {
const searchOptions = getSearchOptions()
return miniSearch.search(query, searchOptions).map(({ id }) => songsById[id])
}

Expand Down Expand Up @@ -164,8 +163,9 @@ const selectSuggestion = (direction) => {
$searchInput.value = $suggestions[nextIndex].innerText
}

const recomputeSearchOptions = () => {
const getSearchOptions = () => {
const formData = new FormData($options)
const searchOptions = {}

searchOptions.fuzzy = formData.has('fuzzy') ? 0.2 : false
searchOptions.prefix = formData.has('prefix')
Expand All @@ -179,6 +179,8 @@ const recomputeSearchOptions = () => {
year = parseInt(year, 10)
return year >= fromYear && year <= toYear
}

return searchOptions
}

const capitalize = (string) => string.replace(/(\b\w)/gi, (char) => char.toUpperCase())

0 comments on commit 56752b3

Please sign in to comment.