Class DocumentIteratorBuilderVisitor
- java.lang.Object
-
- it.unimi.di.big.mg4j.query.nodes.AbstractQueryBuilderVisitor<DocumentIterator>
-
- it.unimi.di.big.mg4j.search.DocumentIteratorBuilderVisitor
-
- All Implemented Interfaces:
QueryBuilderVisitor<DocumentIterator>,FlyweightPrototype<QueryBuilderVisitor<DocumentIterator>>
public class DocumentIteratorBuilderVisitor extends AbstractQueryBuilderVisitor<DocumentIterator>
AQueryBuilderVisitorthat builds aDocumentIteratorresolving the queries using the objects init.unimi.di.big.mg4j.search.This elementary builder visitor invokes
Index.documents(CharSequence)to build the leaf index iterators. Thus, the resultingDocumentIteratorshould be carefully disposed after usage (every index iterator may open a file or a socket).PrefixandMultiTermnodes cause the creation of aMultiTermIndexIterator, in the first case by callingIndex.documents(CharSequence,int)and in the second case by creating aMultiTermIndexIteratorwith the name and frequency equal to the maximum frequency over all terms. Other implementations might choose differently.At construction time, you must provide a map from strings to indices that will be used to resolve
Selectnodes. The map may benull, in which case such nodes will cause anIllegalArgumentException. If aSelectnode contains an index name that does not appear in the map aNoSuchElementExceptionwill be thrown instead.A production site will likely substitute this builder visitor with one that reuses index readers out of a pool.
Instances of this class may be safely reused by calling
prepare().
-
-
Field Summary
Fields Modifier and Type Field Description protected ObjectArrayList<Index>currThe stack of selected indices (changed bySelectnodes).protected IndexdefaultIndexThe default index.protected Reference2ReferenceMap<Index,Object>index2ParserA map associating an object with aparse(String)method to each payload-based index.protected Object2ReferenceMap<String,Index>indexMapA map associating a textual key to indices.protected intlimitThe limit on prefix queries provided in the constructor.protected longnumberOfDocumentsThe number of documents (fetched from the default index).protected doubleweightThe last seen, but still not consumed, weight, orDouble.NaN.protected DoubleArrayListweightsThe stack of weights.
-
Constructor Summary
Constructors Constructor Description DocumentIteratorBuilderVisitor(Object2ReferenceMap<String,Index> indexMap, Index defaultIndex, int limit)Creates a new builder visitor.DocumentIteratorBuilderVisitor(Object2ReferenceMap<String,Index> indexMap, Reference2ReferenceMap<Index,Object> index2Parser, Index defaultIndex, int limit)Creates a new builder visitor with additional parsers for payload-based indices.
-
Method Summary
Modifier and Type Method Description DocumentIteratorBuilderVisitorcopy()DocumentIterator[]newArray(int len)Builds an array of given length of typeT.DocumentIteratorBuilderVisitorprepare()No-op.protected voidpushWeight()Pushesweight, if it is notDouble.NaN, or 1, otherwise, on the stack of weights; in either case, setsweighttoDouble.NaN.DocumentIteratorvisit(False node)VisitsFalse.DocumentIteratorvisit(Prefix node)Visits aPrefix.DocumentIteratorvisit(Range node)Visits aRange.DocumentIteratorvisit(Term node)Visits aTerm.DocumentIteratorvisit(True node)VisitsTrue.DocumentIteratorvisitPost(Align node, DocumentIterator[] subNode)Visits anAlignnode after recursing into the corresponding subtree.DocumentIteratorvisitPost(And node, DocumentIterator[] subNode)Visits anAndnode after recursing into the corresponding subtree.DocumentIteratorvisitPost(Annotation node, DocumentIterator subNode)Visits aAnnotationnode after recursing into the corresponding subtree.DocumentIteratorvisitPost(Consecutive node, DocumentIterator[] subNode)Visits aConsecutivenode after recursing into the corresponding subtree.DocumentIteratorvisitPost(Containment node, DocumentIterator[] subNode)Visits anContainmentnode after recursing into the corresponding subtree.DocumentIteratorvisitPost(Difference node, DocumentIterator[] subNode)Visits aDifferencenode after recursing into the corresponding subtree.DocumentIteratorvisitPost(Inclusion node, DocumentIterator[] subNode)Visits anInclusionnode after recursing into the corresponding subtree.DocumentIteratorvisitPost(LowPass node, DocumentIterator subNode)Visits aLowPassnode after recursing into the corresponding subtree.DocumentIteratorvisitPost(MultiTerm node, DocumentIterator[] subNode)Visits aMultiTermnode after recursing into the corresponding subtree.DocumentIteratorvisitPost(Not node, DocumentIterator subNode)Visits aNotnode after recursing into the corresponding subtree.DocumentIteratorvisitPost(OrderedAnd node, DocumentIterator[] subNode)Visits anOrderedAndnode after recursing into the corresponding subtree.DocumentIteratorvisitPost(Or node, DocumentIterator[] subNode)Visits anOrnode after recursing into the corresponding subtree.DocumentIteratorvisitPost(Remap node, DocumentIterator subNode)Visits aRemapnode after recursing into the corresponding subtree.DocumentIteratorvisitPost(Select node, DocumentIterator subNode)Visits aSelectnode after recursing into the corresponding subtree.DocumentIteratorvisitPost(Weight node, DocumentIterator subNode)Visits aWeightnode after recursing into the corresponding subtree.booleanvisitPre(Align node)Visits anAlignnode before recursing into the corresponding subtree.booleanvisitPre(And node)Visits anAndnode before recursing into the corresponding subtree.booleanvisitPre(Annotation node)Visits aAnnotationnode before recursing into the corresponding subtree.booleanvisitPre(Consecutive node)Visits aConsecutivenode before recursing into the corresponding subtree.booleanvisitPre(Containment node)Visits anContainmentnode before recursing into the corresponding subtree.booleanvisitPre(Difference node)Visits aDifferencenode before recursing into the corresponding subtree.booleanvisitPre(Inclusion node)Visits anInclusionnode before recursing into the corresponding subtree.booleanvisitPre(LowPass node)Visits aLowPassnode before recursing into the corresponding subtree.booleanvisitPre(MultiTerm node)Visits aMultiTermnode before recursing into the corresponding subtree.booleanvisitPre(Not node)Visits aNotnode before recursing into the corresponding subtree.booleanvisitPre(Or node)Visits anOrnode before recursing into the corresponding subtree.booleanvisitPre(OrderedAnd node)Visits anOrderedAndnode before recursing into the corresponding subtree.booleanvisitPre(Remap node)Visits aRemapnode before recursing into the corresponding subtree.booleanvisitPre(Select node)Visits aSelectnode before recursing into the corresponding subtree.booleanvisitPre(Weight node)Visits aWeightnode before recursing into the corresponding subtree.protected doubleweight()Returnsweight, if it is notDouble.NaN, or 1, otherwise; in either case, setsweighttoDouble.NaN.
-
-
-
Field Detail
-
indexMap
protected final Object2ReferenceMap<String,Index> indexMap
A map associating a textual key to indices.
-
index2Parser
protected final Reference2ReferenceMap<Index,Object> index2Parser
A map associating an object with aparse(String)method to each payload-based index.
-
defaultIndex
protected final Index defaultIndex
The default index.
-
numberOfDocuments
protected final long numberOfDocuments
The number of documents (fetched from the default index).
-
limit
protected final int limit
The limit on prefix queries provided in the constructor.
-
curr
protected ObjectArrayList<Index> curr
The stack of selected indices (changed bySelectnodes).
-
weights
protected DoubleArrayList weights
The stack of weights.
-
weight
protected double weight
The last seen, but still not consumed, weight, orDouble.NaN.
-
-
Constructor Detail
-
DocumentIteratorBuilderVisitor
public DocumentIteratorBuilderVisitor(Object2ReferenceMap<String,Index> indexMap, Index defaultIndex, int limit)
Creates a new builder visitor.
-
DocumentIteratorBuilderVisitor
public DocumentIteratorBuilderVisitor(Object2ReferenceMap<String,Index> indexMap, Reference2ReferenceMap<Index,Object> index2Parser, Index defaultIndex, int limit)
Creates a new builder visitor with additional parsers for payload-based indices.
-
-
Method Detail
-
pushWeight
protected void pushWeight()
Pushesweight, if it is notDouble.NaN, or 1, otherwise, on the stack of weights; in either case, setsweighttoDouble.NaN.
-
weight
protected double weight()
Returnsweight, if it is notDouble.NaN, or 1, otherwise; in either case, setsweighttoDouble.NaN.- Returns:
weight, if it is notDouble.NaN, or 1, otherwise.
-
copy
public DocumentIteratorBuilderVisitor copy()
-
prepare
public DocumentIteratorBuilderVisitor prepare()
Description copied from class:AbstractQueryBuilderVisitorNo-op.- Specified by:
preparein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
preparein classAbstractQueryBuilderVisitor<DocumentIterator>- Returns:
- this visitor.
-
newArray
public DocumentIterator[] newArray(int len)
Description copied from interface:QueryBuilderVisitorBuilds an array of given length of typeT.Because of erasure, generic classes in Java cannot allocate arrays of generic types. This impossibility can be a problem if for some reason the
visitPost()methods expect an actual array of typeT. This method must provide an array of given length that is an acceptable input for allvisitPost()methods.Note that by declaring an implementing class of this interface that has a sole constructor accepting an argument of type
Class<T>, you will force the user to provide the class of the generic type, opening the way for the reflective methods inArray.- Parameters:
len- the required array length.- Returns:
- an array of type
Tof lengthlen.
-
visit
public DocumentIterator visit(Term node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aTerm.- Parameters:
node- the leaf to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visit
public DocumentIterator visit(Prefix node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aPrefix.- Parameters:
node- the leaf to be visited.- Returns:
- an appropriate return value (usually, the object built using the elements in
subNodeResult) if the visit should continue, ornull. - Throws:
QueryBuilderVisitorException
-
visit
public DocumentIterator visit(Range node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aRange.- Parameters:
node- the leaf to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPre
public boolean visitPre(And node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits anAndnode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(And node, DocumentIterator[] subNode) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits anAndnode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the array of results returned by subnodes.- Returns:
- an appropriate return value (usually, the object built using the elements in
subNodeResult) if the visit should continue, ornull. - Throws:
QueryBuilderVisitorException
-
visitPre
public boolean visitPre(Consecutive node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aConsecutivenode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(Consecutive node, DocumentIterator[] subNode) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aConsecutivenode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the array of results returned by subnodes.- Returns:
- an appropriate return value (usually, the object built using the elements in
subNodeResult) if the visit should continue, ornull. - Throws:
QueryBuilderVisitorException
-
visitPre
public boolean visitPre(LowPass node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aLowPassnode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(LowPass node, DocumentIterator subNode)
Description copied from interface:QueryBuilderVisitorVisits aLowPassnode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the of result returned by the sole subnode.- Returns:
- an appropriate return value (usually, the object built using
subNodeResult) if the visit should continue, ornull.
-
visitPre
public boolean visitPre(Annotation node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aAnnotationnode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(Annotation node, DocumentIterator subNode)
Description copied from interface:QueryBuilderVisitorVisits aAnnotationnode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the of result returned by the sole subnode.- Returns:
- an appropriate return value (usually, the object built using
subNodeResult) if the visit should continue, ornull.
-
visitPre
public boolean visitPre(Not node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aNotnode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(Not node, DocumentIterator subNode) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aNotnode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the of result returned by the sole subnode.- Returns:
- an appropriate return value (usually, the object built using
subNodeResult) if the visit should continue, ornull. - Throws:
QueryBuilderVisitorException
-
visitPre
public boolean visitPre(Or node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits anOrnode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(Or node, DocumentIterator[] subNode) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits anOrnode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.- Returns:
- an appropriate return value (usually, the object built using the elements in
subNodeResult) if the visit should continue, ornull. - Throws:
QueryBuilderVisitorException
-
visitPre
public boolean visitPre(OrderedAnd node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits anOrderedAndnode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(OrderedAnd node, DocumentIterator[] subNode) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits anOrderedAndnode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the array of results returned by subnodes.- Returns:
- an appropriate return value (usually, the object built using the elements in
subNodeResult) if the visit should continue, ornull. - Throws:
QueryBuilderVisitorException
-
visitPre
public boolean visitPre(Align node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits anAlignnode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(Align node, DocumentIterator[] subNode) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits anAlignnode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the array of results returned by subnodes.- Returns:
- an appropriate return value (usually, the object built using the elements in
subNodeResult) if the visit should continue, ornull. - Throws:
QueryBuilderVisitorException
-
visitPre
public boolean visitPre(Difference node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aDifferencenode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(Difference node, DocumentIterator[] subNode)
Description copied from interface:QueryBuilderVisitorVisits aDifferencenode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the array of results returned by subnodes.- Returns:
- an appropriate return value (usually, the object built using the elements in
subNodeResult) if the visit should continue, ornull.
-
visitPre
public boolean visitPre(Inclusion node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits anInclusionnode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(Inclusion node, DocumentIterator[] subNode)
Description copied from interface:QueryBuilderVisitorVisits anInclusionnode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the array of results returned by subnodes.- Returns:
- an appropriate return value (usually, the object built using the elements in
subNodeResult) if the visit should continue, ornull.
-
visitPre
public boolean visitPre(Containment node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits anContainmentnode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(Containment node, DocumentIterator[] subNode)
Description copied from interface:QueryBuilderVisitorVisits anContainmentnode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the array of results returned by subnodes.- Returns:
- an appropriate return value (usually, the object built using the elements in
subNodeResult) if the visit should continue, ornull.
-
visitPre
public boolean visitPre(MultiTerm node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aMultiTermnode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(MultiTerm node, DocumentIterator[] subNode) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aMultiTermnode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the of result returned by the sole subnode.- Returns:
- an appropriate return value (usually, the object built using
subNodeResult) if the visit should continue, ornull. - Throws:
QueryBuilderVisitorException
-
visitPre
public boolean visitPre(Select node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aSelectnode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(Select node, DocumentIterator subNode)
Description copied from interface:QueryBuilderVisitorVisits aSelectnode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the of result returned by the sole subnode.- Returns:
- an appropriate return value (usually, the object built using
subNodeResult) if the visit should continue, ornull.
-
visitPre
public boolean visitPre(Remap node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aRemapnode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(Remap node, DocumentIterator subNode)
Description copied from interface:QueryBuilderVisitorVisits aRemapnode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the of result returned by the sole subnode.- Returns:
- an appropriate return value (usually, the object built using
subNodeResult) if the visit should continue, ornull.
-
visitPre
public boolean visitPre(Weight node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisits aWeightnode before recursing into the corresponding subtree.- Specified by:
visitPrein interfaceQueryBuilderVisitor<DocumentIterator>- Overrides:
visitPrein classAbstractQueryBuilderVisitor<DocumentIterator>- Parameters:
node- the node to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visitPost
public DocumentIterator visitPost(Weight node, DocumentIterator subNode)
Description copied from interface:QueryBuilderVisitorVisits aWeightnode after recursing into the corresponding subtree.- Parameters:
node- the internal node to be visited.subNode- the of result returned by the sole subnode.- Returns:
- an appropriate return value (usually, the object built using
subNodeResult) if the visit should continue, ornull.
-
visit
public DocumentIterator visit(True node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisitsTrue.- Parameters:
node- the leaf to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visit
public DocumentIterator visit(False node) throws QueryBuilderVisitorException
Description copied from interface:QueryBuilderVisitorVisitsFalse.- Parameters:
node- the leaf to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
-