.oO SearXNG Developer Documentation Oo.
|
Functions | |
None | request (str query, dict[str, t.Any] params) |
tuple[list[str], set[int]] | extract_code (list[dict[str, t.Any]] code_matches) |
EngineResults | response (SXNG_Response resp) |
Variables | |
dict | about |
list | categories = ['code'] |
str | search_url = 'https://api.github.com/search/code?sort=indexed&{query}&{page}' |
str | accept_header = 'application/vnd.github.text-match+json' |
bool | paging = True |
dict | ghc_auth |
bool | ghc_highlight_matching_lines = True |
bool | ghc_strip_new_lines = True |
bool | ghc_strip_whitespace = False |
str | ghc_api_version = "2022-11-28" |
bool | ghc_insert_block_separator = False |
GitHub code search with `search syntax`_ as described in `Constructing a search query`_ in the documentation of GitHub's REST API. .. _search syntax: https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax .. _Constructing a search query: https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#constructing-a-search-query .. _Github REST API for code search: https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-code .. _Github REST API auth for code search: https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-code--fine-grained-access-tokens Configuration ============= The engine has the following mandatory setting: - :py:obj:`ghc_auth` Change the authentication method used when using the API, defaults to none. Optional settings are: - :py:obj:`ghc_highlight_matching_lines` Control the highlighting of the matched text (turns off/on). - :py:obj:`ghc_strip_new_lines` Strip new lines at the start or end of each code fragment. - :py:obj:`ghc_strip_whitespace` Strip any whitespace at the start or end of each code fragment. - :py:obj:`ghc_insert_block_separator` Add a `...` between each code fragment before merging them. .. code:: yaml - name: github code engine: github_code shortcut: ghc ghc_auth: type: "none" - name: github code engine: github_code shortcut: ghc ghc_auth: type: "personal_access_token" token: "<token>" ghc_highlight_matching_lines: true ghc_strip_whitespace: true ghc_strip_new_lines: true - name: github code engine: github_code shortcut: ghc ghc_auth: type: "bearer" token: "<token>" Implementation =============== GitHub does not return the code line indices alongside the code fragment in the search API. Since these are not super important for the user experience all the code lines are just relabeled (starting from 1) and appended (a disjoint set of code blocks in a single file might be returned from the API).
tuple[list[str], set[int]] searx.engines.github_code.extract_code | ( | list[dict[str, t.Any]] | code_matches | ) |
Iterate over multiple possible matches, for each extract a code fragment. Github additionally sends context for _word_ highlights; pygments supports highlighting lines, as such we calculate which lines to highlight while traversing the text.
Definition at line 162 of file github_code.py.
Referenced by response().
None searx.engines.github_code.request | ( | str | query, |
dict[str, t.Any] | params ) |
Definition at line 144 of file github_code.py.
EngineResults searx.engines.github_code.response | ( | SXNG_Response | resp | ) |
Definition at line 214 of file github_code.py.
References extract_code().
dict searx.engines.github_code.about |
Definition at line 77 of file github_code.py.
str searx.engines.github_code.accept_header = 'application/vnd.github.text-match+json' |
Definition at line 92 of file github_code.py.
list searx.engines.github_code.categories = ['code'] |
Definition at line 87 of file github_code.py.
str searx.engines.github_code.ghc_api_version = "2022-11-28" |
Definition at line 133 of file github_code.py.
dict searx.engines.github_code.ghc_auth |
Definition at line 95 of file github_code.py.
bool searx.engines.github_code.ghc_highlight_matching_lines = True |
Definition at line 119 of file github_code.py.
bool searx.engines.github_code.ghc_insert_block_separator = False |
Definition at line 137 of file github_code.py.
bool searx.engines.github_code.ghc_strip_new_lines = True |
Definition at line 122 of file github_code.py.
bool searx.engines.github_code.ghc_strip_whitespace = False |
Definition at line 127 of file github_code.py.
bool searx.engines.github_code.paging = True |
Definition at line 93 of file github_code.py.
str searx.engines.github_code.search_url = 'https://api.github.com/search/code?sort=indexed&{query}&{page}' |
Definition at line 90 of file github_code.py.