class_docstr: A query that allows you to search for "nested" documents, where you can
  index (possibly multiple levels of) "parent" and "child" documents using
  the :meth:`~whoosh.writing.IndexWriter.group` and/or
  :meth:`~whoosh.writing.IndexWriter.start_group` methods of a
  :class:`whoosh.writing.IndexWriter` to indicate that hierarchically related
  documents should be kept together::
  
      schema = fields.Schema(type=fields.ID, text=fields.TEXT(stored=True))
  
      with ix.writer() as w:
          # Say we're indexing chapters (type=chap) and each chapter has a
          # number of paragraphs (type=p)
          with w.group():
              w.add_document(type="chap", text="Chapter 1")
              w.add_document(type="p", text="Able baker")
              w.add_document(type="p", text="Bright morning")
          with w.group():
              w.add_document(type="chap", text="Chapter 2")
              w.add_document(type="p", text="Car trip")
              w.add_document(type="p", text="Dog eared")
              w.add_document(type="p", text="Every day")
          with w.group():
              w.add_document(type="chap", text="Chapter 3")
              w.add_document(type="p", text="Fine day")
  
  The ``NestedParent`` query wraps two sub-queries: the "parent query"
  matches a class of "parent documents". The "sub query" matches nested
  documents you want to find. For each "sub document" the "sub query" finds,
  this query acts as if it found the corresponding "parent document".
  
  >>> with ix.searcher() as s:
  ...   r = s.search(query.Term("text", "day"))
  ...   for hit in r:
  ...     print(hit["text"])
  ...
  Chapter 2
  Chapter 3
class_docstr_tok: ["A","query","that","allows","you","to","search","for","``","nested","''","documents",",","where","you","can","index","(","possibly","multiple","levels","of",")","``","parent","''","and","``","child","''","documents","using","the",":","meth",":","`","~whoosh.writing.IndexWriter.group","`","and\/or",":","meth",":","`","~whoosh.writing.IndexWriter.start_group","`","methods","of","a",":","class",":","`","whoosh.writing.IndexWriter","`","to","indicate","that","hierarchically","related","documents","should","be","kept","together",":",":","schema","=","fields.Schema","(","type=fields.ID",",","text=fields.TEXT","(","stored=True",")",")","with","ix.writer","(",")","as","w",":","#","Say","we","'re","indexing","chapters","(","type=chap",")","and","each","chapter","has","a","#","number","of","paragraphs","(","type=p",")","with","w.group","(",")",":","w.add_document","(","type=","''","chap","''",",","text=","''","Chapter","1","''",")","w.add_document","(","type=","''","p","''",",","text=","''","Able","baker","''",")","w.add_document","(","type=","''","p","''",",","text=","''","Bright","morning","''",")","with","w.group","(",")",":","w.add_document","(","type=","''","chap","''",",","text=","''","Chapter","2","''",")","w.add_document","(","type=","''","p","''",",","text=","''","Car","trip","''",")","w.add_document","(","type=","''","p","''",",","text=","''","Dog","eared","''",")","w.add_document","(","type=","''","p","''",",","text=","''","Every","day","''",")","with","w.group","(",")",":","w.add_document","(","type=","''","chap","''",",","text=","''","Chapter","3","''",")","w.add_document","(","type=","''","p","''",",","text=","''","Fine","day","''",")","The","``","NestedParent","``","query","wraps","two","sub-queries",":","the","``","parent","query","''","matches","a","class","of","``","parent","documents","''",".","The","``","sub","query","''","matches","nested","documents","you","want","to","find",".","For","each","``","sub","document","''","the","``","sub","query","''","finds",",","this","query","acts","as","if","it","found","the","corresponding","``","parent","document","''",".",">",">",">","with","ix.searcher","(",")","as","s",":","...","r","=","s.search","(","query.Term","(","``","text","''",",","``","day","''",")",")","...","for","hit","in","r",":","...","print","(","hit","[","``","text","''","]",")","...","Chapter","2","Chapter","3"]
docstr: :param parents: a query, DocIdSet object, or Results object
      representing the documents you want to use as the "parent"
      documents. Where the sub-query matches, the corresponding document
      in these results will be returned as the match.
  :param subq: a query matching the information you want to find.
  :param per_parent_limit: a maximum number of "sub documents" to search
      per parent. The default is None, meaning no limit.
  :param score_fn: a function to use to combine the scores of matching
      sub-documents to calculate the score returned for the parent
      document. The default is ``sum``, that is, add up the scores of the
      sub-documents.
docstr_tok: [":","param","parents",":","a","query",",","DocIdSet","object",",","or","Results","object","representing","the","documents","you","want","to","use","as","the","``","parent","''","documents",".","Where","the","sub-query","matches",",","the","corresponding","document","in","these","results","will","be","returned","as","the","match",".",":","param","subq",":","a","query","matching","the","information","you","want","to","find",".",":","param","per_parent_limit",":","a","maximum","number","of","``","sub","documents","''","to","search","per","parent",".","The","default","is","None",",","meaning","no","limit",".",":","param","score_fn",":","a","function","to","use","to","combine","the","scores","of","matching","sub-documents","to","calculate","the","score","returned","for","the","parent","document",".","The","default","is","``","sum","``",",","that","is",",","add","up","the","scores","of","the","sub-documents","."]
code: def __init__(
      self, parents, subq, per_parent_limit=None, score_fn=sum
  ):
      """
      :param parents: a query, DocIdSet object, or Results object
          representing the documents you want to use as the "parent"
          documents. Where the sub-query matches, the corresponding document
          in these results will be returned as the match.
      :param subq: a query matching the information you want to find.
      :param per_parent_limit: a maximum number of "sub documents" to search
          per parent. The default is None, meaning no limit.
      :param score_fn: a function to use to combine the scores of matching
          sub-documents to calculate the score returned for the parent
          document. The default is ``sum``, that is, add up the scores of the
          sub-documents.
      """
  
      self.parents = parents
      self.child = subq
      self.per_parent_limit = per_parent_limit
      self.score_fn = score_fn
  
file_path: whoosh/src/whoosh/query/nested.py
imports: from whoosh import matching
  from whoosh.compat import xrange
  from whoosh.query import qcore
  from whoosh.query.wrappers import WrappingQuery
label_desc: Use image node_id 1 to create a new NestedParent object from inherited base classes: WrappingQuery with example: obj = NestedParent(parents, subq, per_parent_limit, score_fn)