Skip to content

Commit 6b0a2e2

Browse files
committed
align the topics
1 parent 5319c1e commit 6b0a2e2

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

backend/app/main.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,17 +474,19 @@ def get_unique_repos():
474474
topics_lower = [t.lower() for t in topics]
475475
placeholders = ",".join(["?"] * len(topics_lower))
476476

477-
# Query to get unique repositories that have ANY of the given topics
478-
# Create a single search pattern that matches any of the topics
479-
search_pattern = '%' + '%'.join(topics_lower) + '%'
480-
query = """
477+
# Query to get unique repositories that have ANY of the given topics using exact matching
478+
conditions = []
479+
for topic in topics_lower:
480+
conditions.append(f"LOWER(t.topics) LIKE '%|{topic}|%' OR LOWER(t.topics) LIKE '{topic}|%' OR LOWER(t.topics) LIKE '%|{topic}' OR LOWER(t.topics) = '{topic}'")
481+
482+
query = f"""
481483
SELECT COUNT(DISTINCT r.nameWithOwner) as count
482484
FROM repos r
483485
JOIN repo_topics t ON r.nameWithOwner = t.repo
484-
WHERE LOWER(t.topics) LIKE ?
486+
WHERE ({" OR ".join(conditions)})
485487
"""
486488

487-
result = topic_service.con.execute(query, [search_pattern]).fetchone()
489+
result = topic_service.con.execute(query).fetchone()
488490
count = result[0] if result else 0
489491

490492
return jsonify({

backend/app/services/edge_generation_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ def _get_repos_for_topics(self, topics: List[str]) -> List[Dict]:
212212
topics_lower = [t.lower() for t in topics]
213213
placeholders = ",".join(["?"] * len(topics_lower))
214214

215-
# Create a more flexible search pattern using OR conditions
215+
# Create exact topic matching conditions
216216
conditions = []
217217
for topic in topics_lower:
218-
conditions.append(f"LOWER(t.topics) LIKE '%{topic}%'")
218+
conditions.append(f"LOWER(t.topics) LIKE '%|{topic}|%' OR LOWER(t.topics) LIKE '{topic}|%' OR LOWER(t.topics) LIKE '%|{topic}' OR LOWER(t.topics) = '{topic}'")
219219

220220
query = f"""
221221
WITH matching_repos AS (

backend/app/services/gexf_node_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ def generate_gexf_nodes_for_topics(self, topics):
7777
WHERE (
7878
"""
7979

80-
# Add each topic as a separate OR condition
80+
# Add each topic as a separate OR condition with exact matching
8181
conditions = []
8282
for topic in topics_lower:
83-
conditions.append(f"LOWER(t.topics) LIKE '%{topic}%'")
83+
conditions.append(f"LOWER(t.topics) LIKE '%|{topic}|%' OR LOWER(t.topics) LIKE '{topic}|%' OR LOWER(t.topics) LIKE '%|{topic}' OR LOWER(t.topics) = '{topic}'")
8484

8585
temp_table_query += " OR ".join(conditions) + ");"
8686
self.con.execute(temp_table_query)

0 commit comments

Comments
 (0)