fuzzy toggle

This commit is contained in:
simon 2019-11-08 16:15:10 -05:00
parent 152d2ddf8a
commit 2d7a8a2fdc
3 changed files with 21 additions and 8 deletions

File diff suppressed because one or more lines are too long

View File

@ -36,6 +36,10 @@ function toggleSearchBar() {
searchDebounced(); searchDebounced();
} }
function toggleFuzzy() {
searchDebounced();
}
$.jsonPost("i").then(resp => { $.jsonPost("i").then(resp => {
resp["indices"].forEach(idx => { resp["indices"].forEach(idx => {
const opt = $("<option>") const opt = $("<option>")
@ -223,6 +227,17 @@ function search() {
{range: {size: {gte: size_min, lte: size_max}}}, {range: {size: {gte: size_min, lte: size_max}}},
{terms: {index: selectedIndices}} {terms: {index: selectedIndices}}
]; ];
let fields = [
"name^8",
"content^3",
"album^8", "artist^8", "title^8", "genre^2", "album_artist^8",
"font_name^6"
];
if ($("#fuzzyToggle").prop("checked")) {
fields.push("content.nGram");
fields.push("name.nGram^3");
}
let path = pathBar.value.replace(/\/$/, "").toLowerCase(); //remove trailing slashes let path = pathBar.value.replace(/\/$/, "").toLowerCase(); //remove trailing slashes
if (path !== "") { if (path !== "") {
@ -243,12 +258,7 @@ function search() {
multi_match: { multi_match: {
query: query, query: query,
type: "most_fields", type: "most_fields",
fields: [ fields: fields,
"name^8", "name.nGram^3", "content^3",
"content.nGram",
"album^8", "artist^8", "title^8", "genre^2", "album_artist^8",
"font_name^6"
],
operator: "and" operator: "and"
} }
}, },

View File

@ -27,6 +27,9 @@
<span onclick="document.getElementById('barToggle').click()">Must match&nbsp</span> <span onclick="document.getElementById('barToggle').click()">Must match&nbsp</span>
<input title="Toggle between 'Should' and 'Must' match mode" type="checkbox" id="barToggle" <input title="Toggle between 'Should' and 'Must' match mode" type="checkbox" id="barToggle"
onclick="toggleSearchBar()" checked> onclick="toggleSearchBar()" checked>
<span onclick="document.getElementById('fuzzyToggle').click()">&nbsp&nbspFuzzy&nbsp</span>
<input title="Toggle fuzzy searching" type="checkbox" id="fuzzyToggle"
onclick="toggleFuzzy()" checked>
</div> </div>
</div> </div>
<input id="searchBar" type="search" class="form-control" placeholder="Search"> <input id="searchBar" type="search" class="form-control" placeholder="Search">