Skip to content

Commit 6b5295c

Browse files
author
Steve Byerly
committed
improve highlight docs for custom options
1 parent 574c1ed commit 6b5295c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/searchqueryset_api.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,23 @@ a highlighted version of the result::
235235
result = sqs[0]
236236
result.highlighted['text'][0] # u'Two computer scientists walk into a bar. The bartender says "<em>Foo</em>!".'
237237

238+
The default functionality of the highlighter may not suite your needs.
239+
You can pass additional keyword arguments to ``highlight`` that will
240+
ultimately be used to build the query for your backend. Depending on the
241+
available arguments for your backend, you may need to pass in a dictionary
242+
instead of normal keyword arguments::
243+
244+
# Solr defines the fields to higlight by the ``hl.fl`` param. If not specified, we
245+
# would only get `text` back in the ``highlighted`` dict.
246+
kwargs = {
247+
'hl.fl': 'other_field',
248+
'hl.simple.pre': '<span class="highlighted">',
249+
'hl.simple.post': '</span>'
250+
}
251+
sqs = SearchQuerySet().filter(content='foo').highlight(**kwargs)
252+
result = sqs[0]
253+
result.highlighted['other_field'][0] # u'Two computer scientists walk into a bar. The bartender says "<span class="highlighted">Foo</span>!".'
254+
238255
``models``
239256
~~~~~~~~~~
240257

0 commit comments

Comments
 (0)