Remove possible error code on view search

Strip out "Search Translations" filter options
This commit is contained in:
Robbie Antenesse 2020-05-03 23:05:52 -06:00
parent 4d3132e151
commit 69c0539370
3 changed files with 3 additions and 56 deletions

View File

@ -22,7 +22,7 @@ export function getSearchFilters() {
caseSensitive: document.getElementById('searchCaseSensitive').checked, caseSensitive: document.getElementById('searchCaseSensitive').checked,
ignoreDiacritics: document.getElementById('searchIgnoreDiacritics').checked, ignoreDiacritics: document.getElementById('searchIgnoreDiacritics').checked,
exact: document.getElementById('searchExactWords').checked, exact: document.getElementById('searchExactWords').checked,
orthography: document.getElementById('searchOrthography').checked, // orthography is removed my default because it is already rendered on the backend.
name: document.getElementById('searchIncludeName').checked, name: document.getElementById('searchIncludeName').checked,
definition: document.getElementById('searchIncludeDefinition').checked, definition: document.getElementById('searchIncludeDefinition').checked,
details: document.getElementById('searchIncludeDetails').checked, details: document.getElementById('searchIncludeDetails').checked,
@ -54,13 +54,11 @@ export function getMatchingSearchWords() {
}).filter(word => { }).filter(word => {
searchTerm = filters.ignoreDiacritics ? removeDiacritics(searchTerm) : searchTerm; searchTerm = filters.ignoreDiacritics ? removeDiacritics(searchTerm) : searchTerm;
searchTerm = filters.caseSensitive ? searchTerm : searchTerm.toLowerCase(); searchTerm = filters.caseSensitive ? searchTerm : searchTerm.toLowerCase();
let name = filters.orthography ? translateOrthography(word.name) : word.name; let name = filters.ignoreDiacritics ? removeDiacritics(word.name) : word.name;
name = filters.ignoreDiacritics ? removeDiacritics(name) : name;
name = filters.caseSensitive ? name : name.toLowerCase(); name = filters.caseSensitive ? name : name.toLowerCase();
let definition = filters.ignoreDiacritics ? removeDiacritics(word.definition) : word.definition; let definition = filters.ignoreDiacritics ? removeDiacritics(word.definition) : word.definition;
definition = filters.caseSensitive ? definition : definition.toLowerCase(); definition = filters.caseSensitive ? definition : definition.toLowerCase();
let details = filters.orthography ? parseReferences(word.details) : word.details; let details = filters.ignoreDiacritics ? removeDiacritics(word.details) : word.details;
details = filters.ignoreDiacritics ? removeDiacritics(details) : details;
details = filters.caseSensitive ? details : details.toLowerCase(); details = filters.caseSensitive ? details : details.toLowerCase();
const isInName = filters.name && (filters.exact const isInName = filters.name && (filters.exact
@ -83,10 +81,6 @@ export function highlightSearchTerm(word) {
if (searchTerm) { if (searchTerm) {
const filters = getSearchFilters(); const filters = getSearchFilters();
const markedUpWord = cloneObject(word); const markedUpWord = cloneObject(word);
if (filters.orthography) {
markedUpWord.name = translateOrthography(markedUpWord.name);
markedUpWord.details = parseReferences(markedUpWord.details);
}
if (filters.ignoreDiacritics) { if (filters.ignoreDiacritics) {
const searchTermLength = searchTerm.length; const searchTermLength = searchTerm.length;
searchTerm = removeDiacritics(searchTerm); searchTerm = removeDiacritics(searchTerm);

View File

@ -1,4 +1,3 @@
import { wordExists, getHomonymnIndexes } from "./utilities";
import removeDiacritics from "../StackOverflow/removeDiacritics"; import removeDiacritics from "../StackOverflow/removeDiacritics";
export function sortWords() { export function sortWords() {
@ -10,46 +9,3 @@ export function sortWords() {
return removeDiacritics(wordA[sortBy]).toLowerCase() > removeDiacritics(wordB[sortBy]).toLowerCase() ? 1 : -1; return removeDiacritics(wordA[sortBy]).toLowerCase() > removeDiacritics(wordB[sortBy]).toLowerCase() ? 1 : -1;
}); });
} }
export function parseReferences(detailsMarkdown) {
const references = detailsMarkdown.match(/\{\{.+?\}\}/g);
if (references && Array.isArray(references)) {
new Set(references).forEach(reference => {
let wordToFind = reference.replace(/\{\{|\}\}/g, '');
let homonymn = 0;
if (wordToFind.includes(':')) {
const separator = wordToFind.indexOf(':');
homonymn = wordToFind.substr(separator + 1);
wordToFind = wordToFind.substring(0, separator);
if (homonymn && homonymn.trim()
&& !isNaN(parseInt(homonymn.trim())) && parseInt(homonymn.trim()) > 0) {
homonymn = parseInt(homonymn.trim());
} else {
homonymn = false;
}
}
let existingWordId = false;
const homonymnIndexes = getHomonymnIndexes({ name: wordToFind, wordId: -1 });
if (homonymn !== false && homonymn > 0) {
if (typeof homonymnIndexes[homonymn - 1] !== 'undefined') {
existingWordId = window.currentDictionary.words[homonymnIndexes[homonymn - 1]].wordId;
}
} else if (homonymn !== false) {
existingWordId = wordExists(wordToFind, true);
}
if (existingWordId !== false) {
if (homonymn < 1 && homonymnIndexes.length > 0) {
homonymn = 1;
}
const homonymnSubHTML = homonymn > 0 ? '<sub>' + homonymn.toString() + '</sub>' : '';
const wordMarkdownLink = `[${wordToFind}${homonymnSubHTML}](#${existingWordId})`;
detailsMarkdown = detailsMarkdown.replace(new RegExp(reference, 'g'), wordMarkdownLink);
}
});
}
return detailsMarkdown;
}

View File

@ -81,9 +81,6 @@
<label>Exact Words <label>Exact Words
<input type="checkbox" id="searchExactWords"> <input type="checkbox" id="searchExactWords">
</label> </label>
<label style="display:none;">Translations
<input type="checkbox" id="searchOrthography">
</label>
</div> </div>
</div> </div>
<div class="split"> <div class="split">