Skip to content

Commit

Permalink
Search engine: Prioritize high frequency (and higher Kanken grade) ka…
Browse files Browse the repository at this point in the history
…njis.
  • Loading branch information
mjuhanne committed Oct 27, 2023
1 parent 09b077a commit 4066a03
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions addon/search_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def csv_to_list(csv):
("kunyomi", j2c, None),
("nanori", j2c, None),
("meanings", j2c, None),
#("frequency_rank", _, None),
("frequency_rank", _, None),
#("grade", _, None),
#("jlpt", _, None),
#("kanken", _, None),
("kanken", _, None),
("primitives", _, None),
("primitive_of", _, None),
("primitive_keywords", j2c, None),
Expand Down Expand Up @@ -92,6 +92,7 @@ def __init__(self, db_cursor):
self.meaning_cache = dict()
self.stories_cache = dict()
self.primitive_alternative_cache = dict()
self.frequency_points = dict()

self.init_cache()

Expand Down Expand Up @@ -240,6 +241,17 @@ def update_cache(self, character=None):

self.stories_cache[c] = st

points = 0
if d['frequency_rank'] is not None and d['frequency_rank'] != '':
fr_points = (4000 - d['frequency_rank'])/400
if fr_points <= 0:
fr_points = 0
points += fr_points
if d['kanken'] is not None and d['kanken'] != '':
points += 11 - float(d['kanken'])
if points > 0:
self.frequency_points[c] = points

# create a reverse lookup table for primitive alternatives
if len(d['primitive_alternatives']) > 0:
prim_alt_list = custom_list(d['primitive_alternatives'])
Expand Down Expand Up @@ -304,6 +316,8 @@ def get_matching_characters_with_scoring(self, search_terms, pool, is_set, pool_
else:
kanji_scores[character] = pool_priority
kanji_matches[character] = {search_term}
if character in self.frequency_points:
kanji_scores[character] += self.frequency_points[character]


def get_matching_characters_from_list_of_pools(self, search_terms, pool_list, max_results):
Expand Down

0 comments on commit 4066a03

Please sign in to comment.