|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface DocumentIteratorVisitor<T>
A visitor for the tree defined by a DocumentIterator
.
Implementations of this interface must be reusable. The user must
invoke prepare()
before a visit so that the internal state
of the visitor can be suitably set up.
Document-iterator visitors can optionally return values. In this case, the newArray(int)
method
must be properly implemented. Otherwise, it can safely return null
: all
implementations of DocumentIterator.accept(DocumentIteratorVisitor)
and
DocumentIterator.acceptOnTruePaths(DocumentIteratorVisitor)
must be prepared
for this to happen. (It would be of course possible to pass around empty arrays, but
visitors on document iterators usually have performance issues.)
If a document-iterator visitor does not return values, it is suggested that it is
parameterised on Boolean
and that it returns Boolean.TRUE
to denote that a visit should not end.
For maximum flexibility, there is just one type of visit method for leaves, but two visits methods for internal nodes, which should be used for preorder and postorder visits, respectively.
The visit methods for leaves are actually two, as they depend on the visited
leaf (more precisely, whether it is an IndexIterator
or a MultiTermIndexIterator
. The
reason for this choice is that in some cases the term-like nature of a MultiTermIndexIterator
makes it easier to write scorers that don't know about expansions (e.g., BM25Scorer
. On the
other hand, some scorers might want to delve into a MultiTermIndexIterator
and discover using
MultiTermIndexIterator.front(IndexIterator[])
which terms where actually found. The
visit(MultiTermIndexIterator)
makes this goal easily reachable.
Note that this visitor interface and that defined in QueryBuilderVisitor
are based on different principles: in the latter case, the action of the visitor will likely
be different for each type of internal node, so we have specific visit methods for each type of such nodes.
In our case, the visit will most likely behave differently just for internal nodes and leaves, so we
prefer a simpler interface that also let us implement more easily visitor acceptance methods
(DocumentIterator.accept(DocumentIteratorVisitor)
and DocumentIterator.acceptOnTruePaths(DocumentIteratorVisitor)
).
Method Summary | |
---|---|
T[] |
newArray(int len)
Builds an array of given length of type T . |
DocumentIteratorVisitor<T> |
prepare()
Prepares the internal state of this visitor for a(nother) visit. |
T |
visit(FalseDocumentIterator falseDocumentIterator)
Visits a FalseDocumentIterator leaf. |
T |
visit(IndexIterator indexIterator)
Visits an IndexIterator leaf. |
T |
visit(MultiTermIndexIterator multiTermIndexIterator)
Visits a MultiTermIndexIterator leaf. |
T |
visit(TrueDocumentIterator trueDocumentIterator)
Visits a TrueDocumentIterator leaf. |
T |
visitPost(DocumentIterator documentIterator,
T[] subNodeResult)
Visits an internal node after recursing into the corresponding subtree. |
boolean |
visitPre(DocumentIterator documentIterator)
Visits an internal node before recursing into the corresponding subtree. |
Method Detail |
---|
DocumentIteratorVisitor<T> prepare()
By specification, it must be safe to call this method any number of times.
T[] newArray(int len)
T
.
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
type T
. This method must provide an array of given length
that is an acceptable input for all visitPost()
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 in Array
.
len
- the required array length.
T
of length len
, or null
if
this document iterator visitor does not return values.boolean visitPre(DocumentIterator documentIterator)
documentIterator
- the internal node to be visited.
T visitPost(DocumentIterator documentIterator, T[] subNodeResult)
documentIterator
- the internal node to be visited.subNodeResult
- the array of results returned by subnodes.
subNode
) if the visit should continue, or null
.T visit(IndexIterator indexIterator) throws IOException
IndexIterator
leaf.
indexIterator
- the leaf to be visited.
null
.
IOException
T visit(MultiTermIndexIterator multiTermIndexIterator) throws IOException
MultiTermIndexIterator
leaf.
multiTermIndexIterator
- the leaf to be visited.
null
.
IOException
T visit(TrueDocumentIterator trueDocumentIterator) throws IOException
TrueDocumentIterator
leaf.
trueDocumentIterator
- the leaf to be visited.
null
.
IOException
T visit(FalseDocumentIterator falseDocumentIterator) throws IOException
FalseDocumentIterator
leaf.
falseDocumentIterator
- the leaf to be visited.
null
.
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |