-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfts_config.py
More file actions
83 lines (73 loc) · 2.02 KB
/
fts_config.py
File metadata and controls
83 lines (73 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
FTS Configuration for Stack Overflow Solutions
"""
# Database paths
MAIN_DB_PATH = "/mnt/stackoverflow_db/databases/SELF_HEALING_AGI.db"
FTS_DB_PATH = "/var/lib/stackoverflow_fts/solutions_fts.db"
# Actual columns in solutions table
SOLUTIONS_COLUMNS = [
'id',
'question_id',
'question_title',
'question_body',
'question_tags',
'answer_body',
'answer_score',
'is_accepted',
'error_pattern',
'fix_command',
'success_rate',
'created_date'
]
# Columns indexed in FTS
FTS_INDEXED_COLUMNS = [
'question_title',
'question_body',
'question_tags',
'answer_body',
'error_pattern',
'fix_command'
]
# Example search queries
def search_solutions(query, limit=10):
"""Search solutions using FTS5"""
import sqlite3
# Connect to FTS database
conn = sqlite3.connect(FTS_DB_PATH)
# Attach main database to get full record data
conn.execute(f"ATTACH DATABASE '{MAIN_DB_PATH}' AS main")
# Search with relevance ranking
results = conn.execute("""
SELECT
m.original_id,
s.id,
s.question_title,
s.answer_body,
s.answer_score,
s.is_accepted,
s.error_pattern,
s.fix_command,
bm25(fts) as rank
FROM solutions_fts fts
JOIN fts_id_mapping m ON fts.rowid = m.fts_rowid
JOIN main.solutions s ON s.id = m.original_id
WHERE solutions_fts MATCH ?
ORDER BY rank
LIMIT ?
""", (query, limit)).fetchall()
conn.close()
return results
# Test function
def test_fts():
"""Test FTS functionality"""
test_queries = [
"python error",
"javascript async",
"java nullpointerexception",
"sql join performance"
]
for query in test_queries:
results = search_solutions(query, limit=3)
print(f"\nSearch: '{query}' - Found {len(results)} results")
for r in results:
print(f" - Score: {r[4]}, Title: {r[2][:60]}...")