A semantic search engine for source code https://bitshift.benkurtovic.com/
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

53 строки
1.4 KiB

  1. """
  2. Module with classes and functions to handle communication with the MySQL
  3. database backend, which manages the search index.
  4. """
  5. import mmh3
  6. import oursql
  7. # from .languages import ...
  8. class Database(object):
  9. """Represents the MySQL database."""
  10. def __init__(self):
  11. self._connect()
  12. def _connect(self):
  13. """Establish a connection to the database."""
  14. self._conn = oursql.connect()
  15. def search(self, query, page=1):
  16. """
  17. Search the database for a query and return the *n*\ th page of results.
  18. :param query: The query to search for.
  19. :type query: :py:class:`~.query.tree.Tree`
  20. :param page: The result page to display.
  21. :type page: int
  22. :return: A list of search results.
  23. :rtype: list of :py:class:`.Codelet`\ s
  24. """
  25. # search for cache_hash = mmh3.hash(query.serialize() + str(page))
  26. # cache HIT:
  27. # update cache_last_used
  28. # return codelets
  29. # cache MISS:
  30. # build complex search query
  31. # fetch codelets
  32. # cache results
  33. # return codelets
  34. pass
  35. def insert(self, codelet):
  36. """
  37. Insert a codelet into the database.
  38. :param codelet: The codelet to insert.
  39. :type codelet: :py:class:`.Codelet`
  40. """
  41. # code_hash = mmh3.hash64(codelet.code.encode("utf8"))[0]
  42. pass