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:
objectThis 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.
- compare_to(query, processed_query)#
Compares this entry to a query.
- Parameters:
query (
str) – The query as plain string.processed_query (
typing.List[str]) – The Query, preprocessed bySphinxSearchEngine.parse_query()
- Return type:
- Returns:
The comparison score.
- class bot.sphinx_search_engine.SphinxSearchEngine(url, cache_timeout)#
Bases:
objectClass to handle fetching and searching Sphinx documentation.
- Parameters:
- cache_timeout#
Cache timeout as
datetime.timedelta.- Type:
- async fetch_docs()#
Fetches the documentation.
- 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:
- inline_search_results(query, page=0)#
Builds inline results from the results of
search().- Parameters:
- 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 theresults_per_querymost 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 to3.
- 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:
- 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:
- Return type:
- Returns:
The sorted results.