WinteryFox / JibikiAPI

A fully featured Japanese-English and English-Japanese dictionary.
https://jibiki.app
7 stars 2 forks source link

Word search ordering and sorting #1

Open WinteryFox opened 4 years ago

WinteryFox commented 4 years ago

Currently, word searches are completely unsorted and will appear in a random order. I've been trying to figure out a proper way to order words (by frequency and/or relevance) however I've been unsuccessful so far. I've tried using the freq table to sort on the columns kw and value however that does not work properly. Trying to figure out a proper way to sort words is tricky and will require more attention.

Ordering by kw and value does not yield favourable results;

SELECT entries.entr
FROM (SELECT entr
      FROM kanj
      WHERE lower(txt) $equals lower(:q)
      UNION ALL
      SELECT entr
      FROM rdng
      WHERE txt $equals hiragana(:reading)
         OR txt $equals katakana(:reading)
      UNION ALL
      SELECT entr
      FROM gloss
      WHERE lower(txt) $equals lower(:q)) entries
         LEFT JOIN freq ON freq.entr = entries.entr AND freq.rdng IS NOT NULL AND freq.kanj IS NULL
ORDER BY freq.kw, freq.value
WinteryFox commented 4 years ago

I have solved this temporarily in commit 9762d91 keeping this issue open because this will need massive tweaks

saulable commented 4 years ago

Convert the characters to a char code, then sort each by that.

WinteryFox commented 4 years ago

That would be a method but not a very good one, words need to be sorted by relevancy/frequency because after all you would not want irregular words at the top of your search results.