Skip to content

Commit 49646e2

Browse files
authored
Merge pull request #59 from data-exp-lab/fix-topic
Fix Topic Misalignment
2 parents 89bb331 + 8cbfea5 commit 49646e2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

backend/app/services/topic_service.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,16 @@ def process_topics(self, search_term: str):
5353
"cached": True
5454
}
5555

56-
# Use a more efficient query that filters early
56+
# Use exact topic matching instead of substring matching
5757
query = """
5858
WITH filtered_repos AS (
5959
SELECT DISTINCT r.nameWithOwner
6060
FROM repos r
6161
JOIN repo_topics t ON r.nameWithOwner = t.repo
62-
WHERE LOWER(t.topics) LIKE '%' || ? || '%'
62+
WHERE LOWER(t.topics) LIKE '%|' || ? || '|%'
63+
OR LOWER(t.topics) LIKE ? || '|%'
64+
OR LOWER(t.topics) LIKE '%|' || ?
65+
OR LOWER(t.topics) = ?
6366
),
6467
split_topics AS (
6568
SELECT
@@ -78,8 +81,8 @@ def process_topics(self, search_term: str):
7881
ORDER BY count DESC
7982
"""
8083

81-
# Execute query with streaming
82-
result = self.con.execute(query, [search_term, search_term]).fetchall()
84+
# Execute query with streaming - pass search_term 4 times for the 4 LIKE conditions, then once more for exclusion
85+
result = self.con.execute(query, [search_term, search_term, search_term, search_term, search_term]).fetchall()
8386

8487
# Convert results to the expected format
8588
topics = [{"name": name.lower(), "count": count} for name, count in result]

0 commit comments

Comments
 (0)