code: def test_span_near():
      ix = get_index()
      with ix.searcher() as s:
  
          def test(q):
              m = q.matcher(s)
              while m.is_active():
                  yield s.stored_fields(m.id())["text"], m.spans()
                  m.next()
  
          for orig, sps in test(
              spans.SpanNear(
                  Term("text", "alfa"),
                  Term("text", "bravo"),
                  ordered=True,
              )
          ):
              assert orig[sps[0].start] == "alfa"
              assert orig[sps[0].end] == "bravo"
  
          for orig, sps in test(
              spans.SpanNear(
                  Term("text", "alfa"),
                  Term("text", "bravo"),
                  ordered=False,
              )
          ):
              first = orig[sps[0].start]
              second = orig[sps[0].end]
              assert (first == "alfa" and second == "bravo") or (
                  first == "bravo" and second == "alfa"
              )
  
          for orig, sps in test(
              spans.SpanNear(
                  Term("text", "bravo"),
                  Term("text", "bravo"),
                  ordered=True,
              )
          ):
              text = " ".join(orig)
              assert text.find("bravo bravo") > -1
  
          q = spans.SpanNear(
              spans.SpanNear(
                  Term("text", "alfa"), Term("text", "charlie")
              ),
              Term("text", "echo"),
          )
          for orig, sps in test(q):
              text = " ".join(orig)
              assert text.find("alfa charlie echo") > -1
  
          q = spans.SpanNear(
              Or([Term("text", "alfa"), Term("text", "charlie")]),
              Term("text", "echo"),
              ordered=True,
          )
          for orig, sps in test(q):
              text = " ".join(orig)
              assert (
                  text.find("alfa echo") > -1
                  or text.find("charlie echo") > -1
              )
  
imports: from __future__ import with_statement
  from whoosh import analysis, fields, formats
  from whoosh.compat import u, xrange, permutations
  from whoosh.filedb.filestore import RamStorage
  from whoosh.query import spans
  from whoosh.query import And, Or, Term, Phrase
  from whoosh.util.testing import TempIndex
label_desc: Use image node_id 6 for calling a global function with example usage: test_span_near() without return types