Create common function for creating term object

This commit is contained in:
toasted-nutbread 2019-08-30 19:26:58 -04:00
parent 64eed33e88
commit a4f8a459de

View File

@ -68,18 +68,7 @@ class Database {
const results = []; const results = [];
await this.db.terms.where('expression').equals(term).or('reading').equals(term).each(row => { await this.db.terms.where('expression').equals(term).or('reading').equals(term).each(row => {
if (titles.includes(row.dictionary)) { if (titles.includes(row.dictionary)) {
results.push({ results.push(Database.createTerm(row));
expression: row.expression,
reading: row.reading,
definitionTags: dictFieldSplit(row.definitionTags || row.tags || ''),
termTags: dictFieldSplit(row.termTags || ''),
rules: dictFieldSplit(row.rules),
glossary: row.glossary,
score: row.score,
dictionary: row.dictionary,
id: row.id,
sequence: typeof row.sequence === 'undefined' ? -1 : row.sequence
});
} }
}); });
@ -94,18 +83,7 @@ class Database {
const results = []; const results = [];
await this.db.terms.where('expression').equals(term).each(row => { await this.db.terms.where('expression').equals(term).each(row => {
if (row.reading === reading && titles.includes(row.dictionary)) { if (row.reading === reading && titles.includes(row.dictionary)) {
results.push({ results.push(Database.createTerm(row));
expression: row.expression,
reading: row.reading,
definitionTags: dictFieldSplit(row.definitionTags || row.tags || ''),
termTags: dictFieldSplit(row.termTags || ''),
rules: dictFieldSplit(row.rules),
glossary: row.glossary,
score: row.score,
dictionary: row.dictionary,
id: row.id,
sequence: typeof row.sequence === 'undefined' ? -1 : row.sequence
});
} }
}); });
@ -120,18 +98,7 @@ class Database {
const results = []; const results = [];
await this.db.terms.where('sequence').equals(sequence).each(row => { await this.db.terms.where('sequence').equals(sequence).each(row => {
if (row.dictionary === mainDictionary) { if (row.dictionary === mainDictionary) {
results.push({ results.push(Database.createTerm(row));
expression: row.expression,
reading: row.reading,
definitionTags: dictFieldSplit(row.definitionTags || row.tags || ''),
termTags: dictFieldSplit(row.termTags || ''),
rules: dictFieldSplit(row.rules),
glossary: row.glossary,
score: row.score,
dictionary: row.dictionary,
id: row.id,
sequence: typeof row.sequence === 'undefined' ? -1 : row.sequence
});
} }
}); });
@ -489,4 +456,19 @@ class Database {
return summary; return summary;
} }
static createTerm(row) {
return {
expression: row.expression,
reading: row.reading,
definitionTags: dictFieldSplit(row.definitionTags || row.tags || ''),
termTags: dictFieldSplit(row.termTags || ''),
rules: dictFieldSplit(row.rules),
glossary: row.glossary,
score: row.score,
dictionary: row.dictionary,
id: row.id,
sequence: typeof row.sequence === 'undefined' ? -1 : row.sequence
};
}
} }