code: def test_sort_filter():
      schema = fields.Schema(
          group=fields.ID(stored=True), key=fields.ID(stored=True)
      )
      groups = u("alfa bravo charlie").split()
      keys = u("abcdefghijklmnopqrstuvwxyz")
      source = []
      for i in xrange(100):
          key = keys[i % len(keys)]
          group = groups[i % len(groups)]
          source.append({"key": key, "group": group})
      source.sort(key=lambda x: (x["key"], x["group"]))
  
      sample = list(source)
      random.shuffle(sample)
  
      with TempIndex(schema, "sortfilter") as ix:
          w = ix.writer()
          for i, fs in enumerate(sample):
              w.add_document(**fs)
              i += 1
              if not i % 26:
                  w.commit(merge=False)
                  w = ix.writer()
          w.commit()
  
          fq = query.Term("group", u("bravo"))
  
          with ix.searcher() as s:
              r = s.search(
                  query.Every(),
                  sortedby=("key", "group"),
                  filter=fq,
                  limit=20,
              )
              assert [h.fields() for h in r] == [
                  d for d in source if d["group"] == "bravo"
              ][:20]
  
              fq = query.Term("group", u("bravo"))
              r = s.search(
                  query.Every(),
                  sortedby=("key", "group"),
                  filter=fq,
                  limit=None,
              )
              assert [h.fields() for h in r] == [
                  d for d in source if d["group"] == "bravo"
              ]
  
          ix.optimize()
  
          with ix.searcher() as s:
              r = s.search(
                  query.Every(),
                  sortedby=("key", "group"),
                  filter=fq,
                  limit=20,
              )
              assert [h.fields() for h in r] == [
                  d for d in source if d["group"] == "bravo"
              ][:20]
  
              fq = query.Term("group", u("bravo"))
              r = s.search(
                  query.Every(),
                  sortedby=("key", "group"),
                  filter=fq,
                  limit=None,
              )
              assert [h.fields() for h in r] == [
                  d for d in source if d["group"] == "bravo"
              ]
  
imports: from __future__ import with_statement
  from datetime import datetime, timedelta
  import random
  from whoosh import fields, query, sorting, columns
  from whoosh.compat import u
  from whoosh.compat import permutations, xrange
  from whoosh.filedb.filestore import RamStorage
  from whoosh.util.testing import TempIndex
label_desc: Use image node_id 27 for calling a global function with example usage: test_sort_filter() without return types