bot.sphinx_search_engine Module#

The module contains the classes SphinxSearchEngine and SphinxDocEntry.

class bot.sphinx_search_engine.SphinxDocEntry(project_name, version, url, entry_type, name, display_name=None)#

Bases: object

This class represents an entry in a Sphinx documentation.

Parameters:
  • project_name (str) – Name of the project this entry belongs to.

  • version (str) – Version of the project.

  • url (str) – URL to the online documentation of the entry.

  • entry_type (str) – Which type of entry this is.

  • name (str) – Name of the entry.

  • display_name (str) – Optional. Display name for the entry.

project_name#

Name of the project this entry belongs to.

Type:

str

version#

Version of the project.

Type:

str

url#

URL to the online documentation of the entry.

Type:

str

entry_type#

Which type of entry this is.

Type:

str

name#

Name of the entry.

Type:

str

display_name#

Optional. Display name for the entry.

Type:

str

compare_to(query, processed_query)#

Compares this entry to a query.

Parameters:
Return type:

float

Returns:

The comparison score.

class bot.sphinx_search_engine.SphinxSearchEngine(url, cache_timeout)#

Bases: object

Class to handle fetching and searching Sphinx documentation.

Parameters:
  • url (str) – URL of the Sphinx documentation.

  • cache_timeout (int) – Cache timeout in minutes. Documentation will be fetched at most every cache_timeout minutes.

url#

URL of the Sphinx documentation.

Type:

str

cache_timeout#

Cache timeout as datetime.timedelta.

Type:

datetime.timedelta

async fetch_docs()#

Fetches the documentation.

Parameters:

cached – Whether to respect caching or not. Defaults to True.

Return type:

None

async initialize(application)#

Initializes the search engine by fetching the docs for the first time and scheduling a job to do so repeatedly.

Return type:

None

inline_search_results(query, page=0)#

Builds inline results from the results of search().

Parameters:
  • query (str) – The search query.

  • page (int) – The pagination index.

Return type:

typing.List[telegram._inline.inlinequeryresultarticle.InlineQueryResultArticle]

Returns:

The inline results.

multi_search_combinations(queries, results_per_query=3)#

For each query, runs search() and fetches the results_per_query most likely results. Then builds all possible combinations.

Parameters:
  • queries (typing.Tuple[str]) – The search queries.

  • results_per_query (int) – Optional. Number of results to fetch per query. Defaults to 3.

Return type:

typing.List[typing.Dict[str, bot.sphinx_search_engine.SphinxDocEntry]]

Returns:

All possible result combinations. Each list entry is a dictionary mapping each query

to the corresponding SphinxDocEntry.

static parse_query(query)#

Does some preprocessing of the query needed for comparison with the entries in the docs.

Parameters:

query (str) – The search query.

Return type:

typing.List[str]

Returns:

The query, split on ., - and /, in reversed order.

property project_description: str#

The description of this project as reported by the fetched documentation

search(query, count=None)#

Compares the query to all entries in the documentation and returns them in the order of similarity.

Parameters:
  • query (str) – The search query

  • count (int) – Optional. If passed, returns the count elements with highest comparison score.

Return type:

typing.List[bot.sphinx_search_engine.SphinxDocEntry]

Returns:

The sorted results.