Spaces:
Running
Running
Commit ·
8c12cef
1
Parent(s): 7fd2d51
Fix Volume Breakdown query expansion discrepancy in SearchService
Browse files
webapp/tipitaka-api/app/services/search_service.py
CHANGED
|
@@ -343,11 +343,11 @@ class SearchService:
|
|
| 343 |
|
| 344 |
return list(dict.fromkeys(v for v in variants if v.strip()))
|
| 345 |
|
| 346 |
-
def
|
| 347 |
-
"""
|
| 348 |
thai_q = to_thai_digits(query_text).strip()
|
| 349 |
if not thai_q:
|
| 350 |
-
return
|
| 351 |
|
| 352 |
# Split into tokens by whitespace
|
| 353 |
tokens = [t.strip() for t in thai_q.split() if t.strip()]
|
|
@@ -403,7 +403,13 @@ class SearchService:
|
|
| 403 |
for t in tokens:
|
| 404 |
processed_tokens.append(f'"{t}"*')
|
| 405 |
|
| 406 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
|
| 408 |
try:
|
| 409 |
with self.db.get_connection() as conn:
|
|
@@ -623,9 +629,8 @@ class SearchService:
|
|
| 623 |
breakdown_data = {}
|
| 624 |
total_count = 0
|
| 625 |
try:
|
| 626 |
-
|
| 627 |
-
if
|
| 628 |
-
fts_q = " AND ".join(f'"{t}"*' for t in tokens)
|
| 629 |
with self.db.get_connection() as conn:
|
| 630 |
cursor = conn.cursor()
|
| 631 |
cursor.execute("""
|
|
|
|
| 343 |
|
| 344 |
return list(dict.fromkeys(v for v in variants if v.strip()))
|
| 345 |
|
| 346 |
+
def _build_fts_query(self, query_text: str) -> str:
|
| 347 |
+
"""Build expanded FTS5 query string from query_text using search rules config."""
|
| 348 |
thai_q = to_thai_digits(query_text).strip()
|
| 349 |
if not thai_q:
|
| 350 |
+
return ""
|
| 351 |
|
| 352 |
# Split into tokens by whitespace
|
| 353 |
tokens = [t.strip() for t in thai_q.split() if t.strip()]
|
|
|
|
| 403 |
for t in tokens:
|
| 404 |
processed_tokens.append(f'"{t}"*')
|
| 405 |
|
| 406 |
+
return " AND ".join(processed_tokens)
|
| 407 |
+
|
| 408 |
+
def _get_fts_results(self, query_text: str, limit: int = 50) -> List[dict]:
|
| 409 |
+
"""Run SQLite FTS5 search on query_text with prefix matching and prefix/suffix expansion."""
|
| 410 |
+
fts_query = self._build_fts_query(query_text)
|
| 411 |
+
if not fts_query:
|
| 412 |
+
return []
|
| 413 |
|
| 414 |
try:
|
| 415 |
with self.db.get_connection() as conn:
|
|
|
|
| 629 |
breakdown_data = {}
|
| 630 |
total_count = 0
|
| 631 |
try:
|
| 632 |
+
fts_q = self._build_fts_query(corrected_q)
|
| 633 |
+
if fts_q:
|
|
|
|
| 634 |
with self.db.get_connection() as conn:
|
| 635 |
cursor = conn.cursor()
|
| 636 |
cursor.execute("""
|