-- TODO: Make it possible to match words that contain the
--       kanji as an infix

CREATE VIEW "KANJIDIC_ExampleEntries"("kanji", "entryId")
AS
SELECT
  "JMdict_KanjiElement"."entryId",
  "KANJIDIC_Character"."literal" AS "kanji",
  "JMdict_KanjiElement"."reading"
FROM
  "KANJIDIC_Character"
JOIN "JMdict_KanjiElementFTS"
  ON "JMdict_KanjiElementFTS"."reading" MATCH "KANJIDIC_Character"."literal" || '*'
JOIN "JMdict_KanjiElement"
  ON "JMdict_KanjiElementFTS"."entryId" = "JMdict_KanjiElement"."entryId"
    AND "JMdict_KanjiElementFTS"."reading" LIKE '%' || "JMdict_KanjiElement"."reading"
WHERE "JMdict_KanjiElement".news = 1
   OR "JMdict_KanjiElement".ichi = 1
   OR "JMdict_KanjiElement".spec = 1
   OR "JMdict_KanjiElement".gai = 1;
