From d606f729cfbdf2a5f4eb5e5a7903b9854097f359 Mon Sep 17 00:00:00 2001 From: stephenmk Date: Mon, 23 Jan 2023 14:13:22 -0600 Subject: [PATCH] Use secondary frequency tags in term score calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a term has a frequency tag, it should return higher in search results than a match which does not have a tag. For example, a search for 素性 should return すじょう rather than そせい, because the former has a "news" frequency tag. --- jmdictHeadword.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/jmdictHeadword.go b/jmdictHeadword.go index a1a75cb..4ead44c 100644 --- a/jmdictHeadword.go +++ b/jmdictHeadword.go @@ -16,6 +16,7 @@ type headword struct { TermTags []string Index int IsPriority bool + IsFrequent bool IsIrregular bool IsOutdated bool IsRareKanji bool @@ -69,6 +70,9 @@ func (h *headword) Score() int { if h.IsPriority { score += 1 } + if h.IsFrequent { + score += 1 + } if h.IsIrregular { score -= 5 } @@ -109,6 +113,9 @@ func (h *headword) SetFlags(infoTags, freqTags []string) { break } } + if len(freqTags) > 1 { + h.IsFrequent = true + } for _, infoTag := range infoTags { switch infoTag { case "iK", "ik", "io":