summaryrefslogtreecommitdiff
path: root/ext/bg/js/database.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-09-12 18:29:16 -0700
committerAlex Yatskov <alex@foosoft.net>2017-09-12 18:29:16 -0700
commit3b29893072b89b75c7fd82b9138b09572ec6248c (patch)
treec4ce890485b434c6d4fd5c73c6eb8047317d91d8 /ext/bg/js/database.js
parent28364b97b0dcc72ecde43aad32f8c58561895382 (diff)
add frequency table support for terms
Diffstat (limited to 'ext/bg/js/database.js')
-rw-r--r--ext/bg/js/database.js34
1 files changed, 33 insertions, 1 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index 4a4f5e82..ea55416c 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -87,6 +87,21 @@ class Database {
return results;
}
+ async findTermFreq(term, titles) {
+ if (!this.db) {
+ throw 'database not initialized';
+ }
+
+ const results = [];
+ await this.db.termFreq.where('expression').equals(term).each(row => {
+ if (titles.includes(row.dictionary)) {
+ results.push({frequency: row.frequency, dictionary: row.dictionary});
+ }
+ });
+
+ return results;
+ }
+
async findKanji(kanji, titles) {
if (!this.db) {
return Promise.reject('database not initialized');
@@ -174,6 +189,23 @@ class Database {
await this.db.terms.bulkAdd(utilIsolate(rows));
};
+ const termFreqDataLoaded = async (title, entries, total, current) => {
+ if (callback) {
+ callback(total, current);
+ }
+
+ const rows = [];
+ for (const [expression, frequency] of entries) {
+ rows.push({
+ expression,
+ frequency,
+ dictionary: title
+ });
+ }
+
+ await this.db.termFreq.bulkAdd(utilIsolate(rows));
+ };
+
const kanjiDataLoaded = async (title, entries, total, current) => {
if (callback) {
callback(total, current);
@@ -219,7 +251,7 @@ class Database {
archive,
indexDataLoaded,
termDataLoaded,
- null,
+ termFreqDataLoaded,
kanjiDataLoaded,
null,
tagDataLoaded