Skip to content

Commit f56a6d0

Browse files
committed
encode auto complete entities
1 parent 458b365 commit f56a6d0

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def auto_complete():
281281
return jsonify({'status': f'Missing mandatory parameter "prefix"'}), 400
282282

283283
# Fetch auto-completion results
284-
completions = auto_complete(repo, prefix)
284+
completions = prefix_search(repo, prefix)
285285

286286
# Create a success response
287287
response = {

code_graph/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
from .git_utils import *
55
from .code_coverage import *
66
from .analyzers.source_analyzer import *
7-
from. auto_complete import auto_complete
7+
from. auto_complete import prefix_search

code_graph/auto_complete.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .graph import Graph
33
from .entities import Function
44

5-
def auto_complete(repo: str, prefix: str) -> str:
5+
def prefix_search(repo: str, prefix: str) -> str:
66
g = Graph(repo)
77
return g.prefix_search(prefix)
88

code_graph/graph.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
from typing import Dict, List, Optional
55
from falkordb import FalkorDB, Path, Node, QueryResult
66

7+
# Configure the logger
8+
import logging
9+
logging.basicConfig(level=logging.DEBUG,
10+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
11+
logger = logging.getLogger(__name__)
12+
713
def list_repos() -> List[str]:
814
"""
915
List processed repositories
@@ -329,27 +335,16 @@ def prefix_search(self, prefix: str) -> str:
329335
CALL db.idx.fulltext.queryNodes('Searchable', $prefix)
330336
YIELD node
331337
WITH node
338+
RETURN node
332339
LIMIT 10
333-
RETURN collect(node)
334340
"""
335341

336-
try:
337-
# Execute the query using the provided graph database connection.
338-
completions = self._query(query, {'prefix': search_prefix}).result_set[0][0]
339-
340-
# Remove label Searchable from each node
341-
for node in completions:
342-
node.labels.remove('Searchable')
342+
# Execute the query using the provided graph database connection.
343+
result_set = self._query(query, {'prefix': search_prefix}).result_set
343344

344-
# Sort the results by the label for better organization.
345-
completions = sorted(completions, key=lambda x: x.labels)
345+
completions = [encode_node(row[0]) for row in result_set]
346346

347-
return completions
348-
349-
except Exception as e:
350-
# Log any errors encountered during the search and return an empty list.
351-
logging.error(f"Error while searching for entities with prefix '{prefix}': {e}")
352-
return []
347+
return completions
353348

354349

355350
def get_function(self, func_id: int) -> Optional[Function]:

0 commit comments

Comments
 (0)