code: def get_next_match(
      result_q,
      word,
      collection,
      signature,
      cutoff=0.5,
      max_in_cursor=100,
  ):
      """Given a cursor, iterate through matches
  
      Scans a cursor for word matches below a distance threshold.
      Exhausts a cursor, possibly enqueuing many matches
      Note that placing this function outside the SignatureCollection
      class breaks encapsulation.  This is done for compatibility with
      multiprocessing.
  
      Args:
          result_q (multiprocessing.Queue): a multiprocessing queue in which to queue results
          word (dict): {word_name: word_value} dict to scan against
          collection (collection): a pymongo collection
          signature (numpy.ndarray): signature array to match against
          cutoff (Optional[float]): normalized distance limit (default 0.5)
          max_in_cursor (Optional[int]): if more than max_in_cursor matches are in the cursor,
              ignore this cursor; this column is not discriminatory (default 100)
  
      """
      curs = collection.find(
          word, projection=["_id", "signature", "path", "metadata"]
      )
  
      # if the cursor has many matches, then it's probably not a huge help. Get the next one.
      if curs.count() > max_in_cursor:
          result_q.put("STOP")
          return
  
      matches = dict()
      while True:
          try:
              rec = curs.next()
              dist = normalized_distance(
                  np.reshape(signature, (1, signature.size)),
                  np.array(rec["signature"]),
              )[0]
              if dist < cutoff:
                  matches[rec["_id"]] = {
                      "dist": dist,
                      "path": rec["path"],
                      "id": rec["_id"],
                      "metadata": rec["metadata"],
                  }
                  result_q.put(matches)
          except StopIteration:
              # do nothing...the cursor is exhausted
              break
      result_q.put("STOP")
  
file_path: image-match/image_match/mongodb_driver.py
imports: from signature_database_base import SignatureDatabaseBase
  from signature_database_base import normalized_distance
  from multiprocessing import cpu_count, Process, Queue
  from multiprocessing.managers import Queue
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: get_next_match(result_q, word, collection, signature, cutoff, max_in_cursor) without return types