feat: add FTS5 search
This commit is contained in:
1 parent
c441d770e2
commit
f1624cfde2
17 files changed
+232
-26
No files matched your search
@@ -65,6 +65,7 @@ class SchemaVersionTests(unittest.TestCase):
|
||||
tables = {r[0] for r in con.execute("SELECT name FROM sqlite_master WHERE type='table'")}
|
||||
self.assertIn("personal", tables)
|
||||
self.assertIn("game_translations", tables)
|
||||
self.assertIn("game_fts", tables)
|
||||
|
||||
def test_legacy_database_is_migrated_and_data_preserved(self):
|
||||
con = sqlite3.connect(self.path)
|
||||
@@ -85,6 +86,9 @@ class SchemaVersionTests(unittest.TestCase):
|
||||
details = con.execute("SELECT short_description, source_appid FROM game_details WHERE appid=100").fetchone()
|
||||
self.assertEqual(details["short_description"], "Old description")
|
||||
self.assertIsNone(details["source_appid"])
|
||||
fts_tables = {r[0] for r in con.execute(
|
||||
"SELECT name FROM sqlite_master WHERE name='game_fts'")}
|
||||
self.assertEqual(fts_tables, {"game_fts"})
|
||||
|
||||
def test_init_is_idempotent(self):
|
||||
con = db.connect(self.path)
|
||||
@@ -98,6 +102,41 @@ class SchemaVersionTests(unittest.TestCase):
|
||||
self.assertEqual(self._version(con), str(db.SCHEMA_VERSION))
|
||||
self.assertEqual(con.execute("SELECT COUNT(*) c FROM games").fetchone()["c"], 1)
|
||||
|
||||
def test_search_index_rebuild_and_single_game_refresh(self):
|
||||
con = db.connect(self.path)
|
||||
self.addCleanup(con.close)
|
||||
db.init(con)
|
||||
con.executemany(
|
||||
"INSERT INTO games (appid, name, type) VALUES (?, ?, ?)",
|
||||
[(1, "Alpha Quest", "game"), (2, "Toolbox", "tool")])
|
||||
con.execute("INSERT INTO game_details (appid, short_description, about, status) "
|
||||
"VALUES (1, 'Short', '<p>Deep dungeon</p>', 'ok')")
|
||||
con.execute("INSERT INTO game_translations (appid, lang, short_description) "
|
||||
"VALUES (1, 'ru', 'Краткое описание')")
|
||||
con.execute("INSERT INTO tag_names (tag_id, name) VALUES (10, 'RPG')")
|
||||
con.execute("INSERT INTO game_tags (appid, tag_id) VALUES (1, 10)")
|
||||
con.commit()
|
||||
|
||||
db.refresh_search_index(con)
|
||||
|
||||
def match(term):
|
||||
return [r[0] for r in con.execute(
|
||||
"SELECT appid FROM game_fts WHERE game_fts MATCH ? ORDER BY appid", (term,))]
|
||||
|
||||
self.assertEqual(match("alpha*"), [1])
|
||||
self.assertEqual(match("dungeon*"), [1])
|
||||
self.assertEqual(match("краткое*"), [1])
|
||||
self.assertEqual(match("rpg*"), [1])
|
||||
self.assertEqual(match("toolbox*"), [])
|
||||
|
||||
con.execute("INSERT INTO games (appid, name, type) VALUES (3, 'Beta Game', 'game')")
|
||||
db.refresh_search_game(con, 3)
|
||||
self.assertEqual(match("beta*"), [3])
|
||||
|
||||
con.execute("UPDATE games SET type='tool' WHERE appid=3")
|
||||
db.refresh_search_game(con, 3)
|
||||
self.assertEqual(match("beta*"), [])
|
||||
|
||||
def test_newer_database_is_rejected(self):
|
||||
con = db.connect(self.path)
|
||||
self.addCleanup(con.close)
|
||||
|
||||
Reference in new issue
Block a user