Skip to content

Latest commit

 

History

History
187 lines (132 loc) · 8.19 KB

highlight-query-results.python.markdown

File metadata and controls

187 lines (132 loc) · 8.19 KB

Highlight Search Results


{NOTE: }

  • When making a Full-Text Search query,
    in addition to retrieving documents that contain the searched terms in the results,
    you can also request to get a list of text fragments that highlight the searched terms.

  • The highlighted terms can enhance user experience when searching for documents with specific content.

  • This article shows highlighting search results when making a dynamic-query.
    For highlighting search results when querying a static-index see highlight index search results.


{NOTE/}


{PANEL: Highlight - basic example}

{CODE-TABS} {CODE-TAB:python:Query highlight_1@ClientApi\Session\Querying\TextSearch\HighlightQueryResults.py /} {CODE-TAB-BLOCK:sql:RQL} from "Employees" where search(Notes, "sales") include highlight(Notes, 35, 4) {CODE-TAB-BLOCK/} {CODE-TABS/}

{CODE:python fragments_1@ClientApi\Session\Querying\TextSearch\HighlightQueryResults.py /}

{NOTE: }

Highlight tags

  • By default, the highlighted term is wrapped with the following html:
    <b style="background:yellow">term</b>

  • When requesting to highlight multiple terms,
    the background color returned for each different term will be in the following order:

    •  yellow,
    •  lawngreen,
    •  aquamarine,
    •  magenta,
    •  palegreen,
    •  coral,
    •  wheat,
    •  khaki,
    •  lime,
    •  deepskyblue,
    •  deeppink,
    •  salmon,
    •  peachpuff,
    •  violet,
    •  mediumpurple,
    •  palegoldenrod,
    •  darkkhaki,
    •  springgreen,
    •  turquoise,
    •  powderblue
  • The html tags that wrap the highlighted terms can be customized to any other tags.
    See customize tags below.

{NOTE/}

{NOTE: }

Highlight results in Studio

Figure 1. Fragments results

  1. Auto-Index
    This is the auto-index that was created by the server to serve the dynamic-query.

  2. Results tab
    The results tab contains the resulting documents that match the provided RQL query.

  3. Highlight tab
    The highlight tab shows the resulting fragments that were included in the query result.

{NOTE/}

{PANEL/}

{PANEL: Highlight - customize tags}

  • The html tags that wrap the highlighted terms can be customized to any other tags.

{CODE-TABS} {CODE-TAB:python:Query highlight_4@ClientApi\Session\Querying\TextSearch\HighlightQueryResults.py /} {CODE-TAB-BLOCK:sql:RQL} from "Employees" where (search(Notes, "sales") or search(Title, "manager")) include highlight(Notes, 35, 1, $p0), highlight(Title, 35, 1, $p1) { "p0":{"PreTags":["+++","<<<"],"PostTags":["+++",">>>"]}, "p1":{"PreTags":["+++","<<<"],"PostTags":["+++",">>>"]} } {CODE-TAB-BLOCK/} {CODE-TABS/}

{CODE:python fragments_2@ClientApi\Session\Querying\TextSearch\HighlightQueryResults.py /}

{PANEL/}

{PANEL: Highlight - projected results}

{CODE-TABS} {CODE-TAB:python:Query highlight_6@ClientApi\Session\Querying\TextSearch\HighlightQueryResults.py /} {CODE-TAB-BLOCK:sql:RQL} from "Employees" as x where search(x.Notes, "manager german") select { Name : "{0} {1}".format(x.FirstName, x.LastName), Title : x.Title } include highlight(Notes, 35, 2) {CODE-TAB-BLOCK/} {CODE-TABS/}

{CODE:python fragments_3@ClientApi\Session\Querying\TextSearch\HighlightQueryResults.py /}

{PANEL/}

{PANEL: Syntax}

{CODE:python syntax_1@ClientApi\Session\Querying\TextSearch\HighlightQueryResults.py /}

Parameter Type Description
field_name str Name of the field that contains the searched terms to highlight
fragment_length int Maximum length of a text fragment
Must be >= 18
fragment_count int Maximum number of text fragments that will be returned
highlightings_callback Callable[[Highlightings], None] A callback function to retrieve the highlighted text fragments for each returned result
options (Optional) HighlightingOptions Customizing options

Highlighting options:

{CODE:python syntax_2@ClientApi\Session\Querying\TextSearch\HighlightQueryResults.py /}

Option Type Description
group_key str Grouping key for the results.
Used when highlighting query results from a Map-Reduce index.
If None results are grouped by document ID (default).
Note: Highlighting is Not available for dynamic aggregation queries.
pre_tags List[str] Array of PRE tags used to wrap the highlighted search terms in the text fragments.
post_tags List[str] Array of POST tags used to wrap the highlighted search terms in the text fragments.

Highlightings object:

{CODE:python syntax_3@ClientApi\Session\Querying\TextSearch\HighlightQueryResults.py /}

Property Type Description
field_name str Name of the field that contains the searched terms to highlight
result_indents Set[str] The resulting keys (document IDs, or the map-reduce keys)

{CODE:python syntax_4@ClientApi\Session\Querying\TextSearch\HighlightQueryResults.py /}

Method Return Type Description
get_fragments List[str] Returns the list of the highlighted text fragments for the passed document ID, or the map-reduce key

{PANEL/}

Related articles

Session

Indexes