summaryrefslogtreecommitdiff
path: root/bucky/search/lexicon.js
diff options
context:
space:
mode:
Diffstat (limited to 'bucky/search/lexicon.js')
-rw-r--r--bucky/search/lexicon.js61
1 files changed, 31 insertions, 30 deletions
diff --git a/bucky/search/lexicon.js b/bucky/search/lexicon.js
index 2b7a8a9..ffc6c06 100644
--- a/bucky/search/lexicon.js
+++ b/bucky/search/lexicon.js
@@ -50,12 +50,12 @@ function parse_threads() {
.fetchAll()
.then((threads) => {
console.log("got threads", threads.length);
- threads.forEach((thread) => {
+ for (const thread of threads) {
total += parse_terms({
string: thread.get("title"),
thread: thread.get("id"),
});
- });
+ }
});
}
function parse_comments() {
@@ -101,34 +101,35 @@ function parse_terms(opt) {
var string = opt.string;
if (!string || !thread) return 0;
var count = 0;
- var terms = string
- .replace(underscoreRegexp, " ")
- .split(spaceRegexp)
- .forEach((term) => {
- var t = parse_term(term);
- if (!term) {
- return;
- }
- var lookup = (lexicon[t] = lexicon[t] || {});
- var res = (lookup[thread] = lookup[thread] || { strength: 1 });
- res.thread = res.thread || thread;
- res.comment = res.comment || comment;
- res.file = res.file || file;
- // prioritize threads
- if (!comment && !file) {
- res.strength += 4;
- } else if (file) {
- res.strength += 1.5;
- }
- count += 1;
- lex_counts[term] = lex_counts[term] || new Set();
- try {
- lex_counts[term].add(res.thread);
- } catch (error) {
- console.error(error);
- console.log(lex_counts[term]);
- }
- });
+ var terms = string.replace(underscoreRegexp, " ").split(spaceRegexp);
+ for (const term of terms) {
+ var parsedTerm = parse_term(term);
+ if (!term || !parsedTerm) {
+ return;
+ }
+ lexicon[parsedTerm] = lexicon[parsedTerm] || {};
+ var lookup = lexicon[parsedTerm];
+
+ lookup[thread] = lookup[thread] || { strength: 1 };
+ var res = lookup[thread];
+ res.thread = res.thread || thread;
+ res.comment = res.comment || comment;
+ res.file = res.file || file;
+ // prioritize threads
+ if (!comment && !file) {
+ res.strength += 10;
+ } else {
+ res.strength += 1;
+ }
+ count += 1;
+ lex_counts[term] = lex_counts[term] || new Set();
+ try {
+ lex_counts[term].add(res.thread);
+ } catch (error) {
+ console.error(error);
+ console.log(term, lex_counts[term]);
+ }
+ }
return count || 0;
}