feat(calc): add toggle to prioritize Ingglish matches to top of query results

- Add optPrioritizeIngglish option (configurable via prioritizeIngglishMatches in config.default.js and persisted in localStorage via calcOptionsArr).
- Add 'Prioritize Ingglish [...]' checkbox (chkbox_PIM / conf_PIM()) to the Options Menu and a one-click 'ING ↑' toggle button (queryIngPriorityBtn) inside the Match Results table header that re-sorts open query modals in place via refreshOpenQuery().
- Unify match sorting in calc/database.js under compareQueryMatches(a, b, searchPhrase): pins exact full or comment-stripped phrase matches first, sorts [Ingglish: ...] rows above standard entries when optPrioritizeIngglish is enabled, and preserves score ordering within each group.
This commit is contained in:
Hermes Agent committed 2026-11-04 01:03:57 +00:00
1 parent c1e6a980e0
commit 01aee23ddc
5 files changed
+71 -14

No files matched your search

+34 -14
View File
@@ -109,6 +109,31 @@ function clearDatabaseQueryTable() {
queryResultInitial = [] // clear
}
function isIngglishEntry(phr) {
return typeof phr === "string" && phr.indexOf("[Ingglish:") !== -1
}
function compareQueryMatches(a, b, searchPhrase) {
// 1. Exact phrase match (full string or stripped of [...] comment) always first
var aRaw = a[1].toLowerCase()
var bRaw = b[1].toLowerCase()
var aStripped = aRaw.replace(/\[.+\]/g, '').trim()
var bStripped = bRaw.replace(/\[.+\]/g, '').trim()
var aExact = (aRaw === searchPhrase || aStripped === searchPhrase) ? 1 : 0
var bExact = (bRaw === searchPhrase || bStripped === searchPhrase) ? 1 : 0
if (aExact !== bExact) return bExact - aExact
// 2. When optPrioritizeIngglish is enabled, sort [Ingglish: ...] matches above non-Ingglish matches
if (typeof optPrioritizeIngglish !== "undefined" && optPrioritizeIngglish) {
var aIng = isIngglishEntry(a[1]) ? 1 : 0
var bIng = isIngglishEntry(b[1]) ? 1 : 0
if (aIng !== bIng) return bIng - aIng
}
// 3. Then sort by match score descending
return b[0] - a[0]
}
function searchDBcrossCipher() { // populate "queryResult" array with matching phrases
var p, m, n
queryResult = [] // reset matching phrases
@@ -145,14 +170,10 @@ function searchDBcrossCipher() { // populate "queryResult" array with matching p
}
if (tmpArr[0] > 0) queryResult.push(tmpArr) // if total score is more than zero, add phrase to array
}
// Sort by score descending, but pin exact phrase match to top
var searchPhrase = sVal().toLowerCase()
// Sort by score descending, pinning exact match and (when enabled) [Ingglish: ...] matches to top
var searchPhrase = sVal().toLowerCase().trim()
queryResult.sort(function(a, b) {
// Exact phrase match always first
var aExact = a[1].toLowerCase() === searchPhrase ? 1 : 0
var bExact = b[1].toLowerCase() === searchPhrase ? 1 : 0
if (aExact !== bExact) return bExact - aExact
return b[0] - a[0]; // then by score descending
return compareQueryMatches(a, b, searchPhrase)
});
}
@@ -185,13 +206,10 @@ function searchDBsameCipher() { // populate "queryResult" array with matching ph
}
if (tmpArr[0] > 0) queryResult.push(tmpArr) // if total score is more than zero, add phrase to array
}
// Sort by score descending, but pin exact phrase match to top
var searchPhrase = sVal().toLowerCase()
// Sort by score descending, pinning exact match and (when enabled) [Ingglish: ...] matches to top
var searchPhrase = sVal().toLowerCase().trim()
queryResult.sort(function(a, b) {
var aExact = a[1].toLowerCase() === searchPhrase ? 1 : 0
var bExact = b[1].toLowerCase() === searchPhrase ? 1 : 0
if (aExact !== bExact) return bExact - aExact
return b[0] - a[0];
return compareQueryMatches(a, b, searchPhrase)
});
}
@@ -267,9 +285,11 @@ function updateDatabaseQueryTable(stPos = 0, dItems, scrollBarEvent = false) { /
if (firstPhrase) { // open row on the first phrase
firstPhrase = false
var ingBtnClass = (typeof optPrioritizeIngglish !== "undefined" && optPrioritizeIngglish) ? "queryPageBtn ingPriorityBtn ingPriorityOn" : "queryPageBtn ingPriorityBtn"
ms += '<tr class="cH"><td class="mPQ">'
ms += queryResult.length.toLocaleString('en')+' matches'
ms += '<br><br>'
ms += '<br><input class="'+ingBtnClass+'" id="queryIngPriorityBtn" type="button" value="ING &#8593;" title="Toggle Ingglish [...] priority sort to top" onclick="event.stopPropagation();conf_PIM()">'
ms += '<br>'
ms += '<div style="display: inline-flex;">'
ms += '<input class="queryPageBtn" id="queryPrevPageBtn" type="button" value="<" onclick="queryShowPrevPage()">'
ms += '<input id="queryPosInput" type="tel" autocomplete="off" value="'+curPos+'">'