Add details field to apiTermsFind
This commit is contained in:
parent
7093d8f06e
commit
3a225c3f91
@ -72,9 +72,9 @@ async function apiOptionsSave(source) {
|
|||||||
backend.onOptionsUpdated(source);
|
backend.onOptionsUpdated(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function apiTermsFind(text, optionsContext) {
|
async function apiTermsFind(text, details, optionsContext) {
|
||||||
const options = await apiOptionsGet(optionsContext);
|
const options = await apiOptionsGet(optionsContext);
|
||||||
const [definitions, length] = await utilBackend().translator.findTerms(text, options);
|
const [definitions, length] = await utilBackend().translator.findTerms(text, details, options);
|
||||||
definitions.splice(options.general.maxResults);
|
definitions.splice(options.general.maxResults);
|
||||||
return {length, definitions};
|
return {length, definitions};
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ Backend.messageHandlers = {
|
|||||||
optionsGet: ({optionsContext}) => apiOptionsGet(optionsContext),
|
optionsGet: ({optionsContext}) => apiOptionsGet(optionsContext),
|
||||||
optionsSet: ({changedOptions, optionsContext, source}) => apiOptionsSet(changedOptions, optionsContext, source),
|
optionsSet: ({changedOptions, optionsContext, source}) => apiOptionsSet(changedOptions, optionsContext, source),
|
||||||
kanjiFind: ({text, optionsContext}) => apiKanjiFind(text, optionsContext),
|
kanjiFind: ({text, optionsContext}) => apiKanjiFind(text, optionsContext),
|
||||||
termsFind: ({text, optionsContext}) => apiTermsFind(text, optionsContext),
|
termsFind: ({text, details, optionsContext}) => apiTermsFind(text, details, optionsContext),
|
||||||
definitionAdd: ({definition, mode, context, optionsContext}) => apiDefinitionAdd(definition, mode, context, optionsContext),
|
definitionAdd: ({definition, mode, context, optionsContext}) => apiDefinitionAdd(definition, mode, context, optionsContext),
|
||||||
definitionsAddable: ({definitions, modes, optionsContext}) => apiDefinitionsAddable(definitions, modes, optionsContext),
|
definitionsAddable: ({definitions, modes, optionsContext}) => apiDefinitionsAddable(definitions, modes, optionsContext),
|
||||||
noteView: ({noteId}) => apiNoteView(noteId),
|
noteView: ({noteId}) => apiNoteView(noteId),
|
||||||
|
@ -207,7 +207,7 @@ class DisplaySearch extends Display {
|
|||||||
this.setIntroVisible(!valid, animate);
|
this.setIntroVisible(!valid, animate);
|
||||||
this.updateSearchButton();
|
this.updateSearchButton();
|
||||||
if (valid) {
|
if (valid) {
|
||||||
const {definitions} = await apiTermsFind(query, this.optionsContext);
|
const {definitions} = await apiTermsFind(query, {}, this.optionsContext);
|
||||||
this.setContentTerms(definitions, {
|
this.setContentTerms(definitions, {
|
||||||
focus: false,
|
focus: false,
|
||||||
sentence: null,
|
sentence: null,
|
||||||
|
@ -141,23 +141,23 @@ class Translator {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findTerms(text, options) {
|
async findTerms(text, details, options) {
|
||||||
switch (options.general.resultOutputMode) {
|
switch (options.general.resultOutputMode) {
|
||||||
case 'group':
|
case 'group':
|
||||||
return await this.findTermsGrouped(text, options);
|
return await this.findTermsGrouped(text, details, options);
|
||||||
case 'merge':
|
case 'merge':
|
||||||
return await this.findTermsMerged(text, options);
|
return await this.findTermsMerged(text, details, options);
|
||||||
case 'split':
|
case 'split':
|
||||||
return await this.findTermsSplit(text, options);
|
return await this.findTermsSplit(text, details, options);
|
||||||
default:
|
default:
|
||||||
return [[], 0];
|
return [[], 0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async findTermsGrouped(text, options) {
|
async findTermsGrouped(text, details, options) {
|
||||||
const dictionaries = dictEnabledSet(options);
|
const dictionaries = dictEnabledSet(options);
|
||||||
const titles = Object.keys(dictionaries);
|
const titles = Object.keys(dictionaries);
|
||||||
const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric);
|
const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric, details);
|
||||||
|
|
||||||
const definitionsGrouped = dictTermsGroup(definitions, dictionaries);
|
const definitionsGrouped = dictTermsGroup(definitions, dictionaries);
|
||||||
await this.buildTermFrequencies(definitionsGrouped, titles);
|
await this.buildTermFrequencies(definitionsGrouped, titles);
|
||||||
@ -171,11 +171,11 @@ class Translator {
|
|||||||
return [definitionsGrouped, length];
|
return [definitionsGrouped, length];
|
||||||
}
|
}
|
||||||
|
|
||||||
async findTermsMerged(text, options) {
|
async findTermsMerged(text, details, options) {
|
||||||
const dictionaries = dictEnabledSet(options);
|
const dictionaries = dictEnabledSet(options);
|
||||||
const secondarySearchTitles = Object.keys(options.dictionaries).filter(dict => options.dictionaries[dict].allowSecondarySearches);
|
const secondarySearchTitles = Object.keys(options.dictionaries).filter(dict => options.dictionaries[dict].allowSecondarySearches);
|
||||||
const titles = Object.keys(dictionaries);
|
const titles = Object.keys(dictionaries);
|
||||||
const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric);
|
const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric, details);
|
||||||
const {sequencedDefinitions, defaultDefinitions} = await this.getSequencedDefinitions(definitions, options.general.mainDictionary);
|
const {sequencedDefinitions, defaultDefinitions} = await this.getSequencedDefinitions(definitions, options.general.mainDictionary);
|
||||||
const definitionsMerged = [];
|
const definitionsMerged = [];
|
||||||
const mergedByTermIndices = new Set();
|
const mergedByTermIndices = new Set();
|
||||||
@ -209,17 +209,17 @@ class Translator {
|
|||||||
return [dictTermsSort(definitionsMerged), length];
|
return [dictTermsSort(definitionsMerged), length];
|
||||||
}
|
}
|
||||||
|
|
||||||
async findTermsSplit(text, options) {
|
async findTermsSplit(text, details, options) {
|
||||||
const dictionaries = dictEnabledSet(options);
|
const dictionaries = dictEnabledSet(options);
|
||||||
const titles = Object.keys(dictionaries);
|
const titles = Object.keys(dictionaries);
|
||||||
const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric);
|
const [definitions, length] = await this.findTermsInternal(text, dictionaries, options.scanning.alphanumeric, details);
|
||||||
|
|
||||||
await this.buildTermFrequencies(definitions, titles);
|
await this.buildTermFrequencies(definitions, titles);
|
||||||
|
|
||||||
return [definitions, length];
|
return [definitions, length];
|
||||||
}
|
}
|
||||||
|
|
||||||
async findTermsInternal(text, dictionaries, alphanumeric) {
|
async findTermsInternal(text, dictionaries, alphanumeric, details) {
|
||||||
if (!alphanumeric && text.length > 0) {
|
if (!alphanumeric && text.length > 0) {
|
||||||
const c = text[0];
|
const c = text[0];
|
||||||
if (!jpIsKana(c) && !jpIsKanji(c)) {
|
if (!jpIsKana(c) && !jpIsKanji(c)) {
|
||||||
|
@ -25,8 +25,8 @@ function apiOptionsSet(changedOptions, optionsContext, source) {
|
|||||||
return utilInvoke('optionsSet', {changedOptions, optionsContext, source});
|
return utilInvoke('optionsSet', {changedOptions, optionsContext, source});
|
||||||
}
|
}
|
||||||
|
|
||||||
function apiTermsFind(text, optionsContext) {
|
function apiTermsFind(text, details, optionsContext) {
|
||||||
return utilInvoke('termsFind', {text, optionsContext});
|
return utilInvoke('termsFind', {text, details, optionsContext});
|
||||||
}
|
}
|
||||||
|
|
||||||
function apiKanjiFind(text, optionsContext) {
|
function apiKanjiFind(text, optionsContext) {
|
||||||
|
@ -413,7 +413,7 @@ class Frontend {
|
|||||||
const searchText = textSource.text();
|
const searchText = textSource.text();
|
||||||
if (searchText.length === 0) { return null; }
|
if (searchText.length === 0) { return null; }
|
||||||
|
|
||||||
const {definitions, length} = await apiTermsFind(searchText, this.getOptionsContext());
|
const {definitions, length} = await apiTermsFind(searchText, {}, this.getOptionsContext());
|
||||||
if (definitions.length === 0) { return null; }
|
if (definitions.length === 0) { return null; }
|
||||||
|
|
||||||
textSource.setEndOffset(length);
|
textSource.setEndOffset(length);
|
||||||
|
@ -112,7 +112,7 @@ class Display {
|
|||||||
try {
|
try {
|
||||||
textSource.setEndOffset(this.options.scanning.length);
|
textSource.setEndOffset(this.options.scanning.length);
|
||||||
|
|
||||||
({definitions, length} = await apiTermsFind(textSource.text(), this.getOptionsContext()));
|
({definitions, length} = await apiTermsFind(textSource.text(), {}, this.getOptionsContext()));
|
||||||
if (definitions.length === 0) {
|
if (definitions.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user