The highlight module contains classes and functions for displaying short excerpts from hit documents in the search results you present to the user, with query terms highlighted.
See how to highlight terms in search results.
Simply splits the text into roughly equal sized chunks.
Parameters: |
|
---|
Breaks the text up on sentence end punctuation characters (“.”, “!”, or “?”). This object works by looking in the original text for a sentence end as the next character after each token’s ‘endchar’.
When highlighting with this fragmenter, you should use an analyzer that does NOT remove stop words, for example:
sa = StandardAnalyzer(stoplist=None)
Parameters: |
|
---|
Looks for matched terms and aggregates them with their surrounding context.
This fragmenter only yields fragments that contain matched terms.
Parameters: |
|
---|
Returns a string in which the matched terms are in UPPERCASE.
Parameters: |
|
---|
Returns a string containing HTML formatting around the matched terms.
This formatter wraps matched terms in an HTML element with two class names. The first class name (set with the constructor argument classname) is the same for each match. The second class name (set with the constructor argument termclass is different depending on which term matched. This allows you to give different formatting (for example, different background colors) to the different terms in the excerpt.
>>> hf = HtmlFormatter(tagname="span", classname="match", termclass="term")
>>> hf(mytext, myfragments)
"The <span class="match term0">template</span> <span class="match term1">geometry</span> is..."
This object maintains a dictionary mapping terms to HTML class names (e.g. term0 and term1 above), so that multiple excerpts will use the same class for the same term. If you want to re-use the same HtmlFormatter object with different searches, you should call HtmlFormatter.clear() between searches to clear the mapping.
Parameters: |
|
---|
Returns a Genshi event stream containing HTML formatting around the matched terms.
Parameters: |
|
---|
Represents a fragment (extract) from a hit document. This object is mainly used to keep track of the start and end points of the fragment; it does not contain the text of the fragment or do much else.
Parameters: |
|
---|
index after the last character of the fragment in the original
index of the first character of the fragment in the original