Commits

Matt Chaput committed 6f6a763

Added docs for how to set highlighter attributes on a ResultsPage.

Comments (0)

Files changed (2)

src/whoosh/searching.py

     >>> for i, fields in enumerate(page):
     ...   print("%s. %r" % (page.offset + i + 1, fields))
     >>> mysearcher.close()
+
+    To set highlighter attributes (for example ``formatter``), access the
+    underlying :class:`Results` object::
+
+        page.results.formatter = highlight.UppercaseFormatter()
+
     """
 
     def __init__(self, results, pagenum, pagelen=10):

tests/test_results.py

         assert c[1] == "bravo"
         assert s.reader().has_word_graph("key")
         assert s.suggest("key", "brovo") == ["bravo"]
+
+
+def test_paged_highlights():
+    schema = fields.Schema(text=fields.TEXT(stored=True))
+    ix = RamStorage().create_index(schema)
+    with ix.writer() as w:
+        w.add_document(text=u("alfa bravo charlie delta echo foxtrot"))
+        w.add_document(text=u("bravo charlie delta echo foxtrot golf"))
+        w.add_document(text=u("charlie delta echo foxtrot golf hotel"))
+        w.add_document(text=u("delta echo foxtrot golf hotel india"))
+        w.add_document(text=u("echo foxtrot golf hotel india juliet"))
+        w.add_document(text=u("foxtrot golf hotel india juliet kilo"))
+
+    with ix.searcher() as s:
+        q = query.Term("text", u("alfa"))
+        page = s.search_page(q, 1, pagelen=3)
+
+        page.results.fragmenter = highlight.WholeFragmenter()
+        page.results.formatter = highlight.UppercaseFormatter()
+        hi = page[0].highlights("text")
+        assert hi == u("ALFA bravo charlie delta echo foxtrot")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.