search.services.index.highlighting module¶
Provide hit highlighting to the search.
Highlighting requires amendation of the query as well as post-processing of
the returned results. highlight()
adds a highlighting part to the query
in the Elasticsearch DSL. add_highlighting()
performs post-processing
of the search results. preview()
generates a TeX-safe snippet for
abridged display in the search results.
-
search.services.index.highlighting.
add_highlighting
(result, raw)[source]¶ Add hit highlighting to a search result.
Parameters: - result (dict) – Contains processed search result data destined for the caller.
- raw (
Response
) – A response from Elasticsearch.
Returns: The
result
object, updated withhighlight
andpreview
items.Return type: Return type:
-
search.services.index.highlighting.
highlight
(search)[source]¶ Apply hit highlighting to the search, before execution.
Parameters: search ( Search
) –Returns: The search object that was originally passed, updated to include requests for hit highlighting. Return type: Search
Return type: Search
-
search.services.index.highlighting.
preview
(value, fragment_size=400, start_tag='<span class="search-hit mathjax">', end_tag='</span>')[source]¶ Generate a snippet preview that doesn’t breaking TeXisms or highlighting.
Parameters: - value (str) – The full text of the field, which we assume contains TeXisms and/or hit hightlighting tags.
- fragment_size (int) – The desired size of the preview (number of characters). The actual preview may be smaller or larger than this target, depending on where the TeXisms and highlight tags are located.
- start_tag (str) – The opening tag used for hit highlighting.
- end_tag (str) – The closing tag used for hit highlighting.
Returns: A preview that is approximately
fragment_size
long.Return type: Return type: