feat: add FTS5 search
This commit is contained in:
1 parent
c441d770e2
commit
f1624cfde2
17 files changed
+232
-26
No files matched your search
+18
-1
@@ -9,6 +9,7 @@ import threading
|
||||
import time
|
||||
import unittest
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
from http.server import ThreadingHTTPServer
|
||||
from unittest import mock
|
||||
@@ -38,6 +39,7 @@ class ApiTests(unittest.TestCase):
|
||||
db.init(cls.con)
|
||||
db.seed_moods(cls.con)
|
||||
cls._seed(cls.con)
|
||||
db.refresh_search_index(cls.con)
|
||||
cls.con.close()
|
||||
|
||||
cls.db_patch = mock.patch.object(db, "DEFAULT_DB", cls.db_path)
|
||||
@@ -103,8 +105,9 @@ class ApiTests(unittest.TestCase):
|
||||
con.commit()
|
||||
|
||||
def get(self, path, expect=200):
|
||||
url = self.base + urllib.parse.quote(path, safe="/?=&%:,")
|
||||
try:
|
||||
with urllib.request.urlopen(self.base + path, timeout=10) as resp:
|
||||
with urllib.request.urlopen(url, timeout=10) as resp:
|
||||
status = resp.status
|
||||
body = resp.read().decode("utf-8")
|
||||
except urllib.error.HTTPError as exc:
|
||||
@@ -189,6 +192,20 @@ class ApiTests(unittest.TestCase):
|
||||
self.assertEqual({g["appid"] for g in self.get("/api/games?unplayed=1")["items"]}, {2})
|
||||
self.assertEqual([g["appid"] for g in self.get("/api/games?favorite=1")["items"]], [1])
|
||||
|
||||
def test_search_by_name_description_tags_and_translation(self):
|
||||
self.assertEqual([g["appid"] for g in self.get("/api/games?q=alph")["items"]], [1])
|
||||
self.assertEqual([g["appid"] for g in self.get("/api/games?q=Short")["items"]], [1])
|
||||
self.assertEqual([g["appid"] for g in self.get("/api/games?q=About")["items"]], [1])
|
||||
self.assertEqual([g["appid"] for g in self.get("/api/games?q=Party")["items"]], [1, 2])
|
||||
self.assertEqual([g["appid"] for g in self.get("/api/games?q=Кратко")["items"]], [1])
|
||||
self.assertEqual(self.get("/api/games?q=заметка")["items"], [])
|
||||
self.assertEqual(self.get("/api/games?q=%%%")["items"], [])
|
||||
|
||||
def test_fts_query_builder(self):
|
||||
self.assertEqual(server.fts_query("Baldur's Gate"), '"baldur"* "gate"*')
|
||||
self.assertEqual(server.fts_query(" "), "")
|
||||
self.assertEqual(server.fts_query("!!! ???"), "")
|
||||
|
||||
def test_games_sort_and_pagination(self):
|
||||
self.assertEqual([g["appid"] for g in self.get("/api/games?sort=review")["items"]], [1, 2, 3])
|
||||
self.assertEqual([g["appid"] for g in self.get("/api/games?sort=hours")["items"]], [1, 3, 2])
|
||||
|
||||
Reference in new issue
Block a user