42
42
import org .neo4j .graphdb .Relationship ;
43
43
import org .neo4j .graphdb .RelationshipType ;
44
44
import org .neo4j .graphdb .Transaction ;
45
+ import org .neo4j .graphdb .impl .StandardExpander ;
46
+ import org .neo4j .graphdb .traversal .BranchState ;
45
47
import org .neo4j .graphdb .traversal .Evaluation ;
46
- import org .neo4j .graphdb .traversal .Evaluator ;
47
48
import org .neo4j .graphdb .traversal .Evaluators ;
49
+ import org .neo4j .graphdb .traversal .PathEvaluator ;
48
50
import org .neo4j .graphdb .traversal .TraversalDescription ;
49
51
import org .neo4j .graphdb .traversal .Traverser ;
50
52
import org .neo4j .kernel .impl .traversal .MonoDirectionalTraversalDescription ;
@@ -754,7 +756,7 @@ public Iterable<Node> getAllIndexedNodes(Transaction tx) {
754
756
return new IndexNodeToGeometryNodeIterable (getAllIndexInternalNodes (tx ));
755
757
}
756
758
757
- private class SearchEvaluator implements Evaluator {
759
+ private class SearchEvaluator extends PathEvaluator . Adapter < SearchFilter . EnvelopFilterResult > {
758
760
759
761
private final SearchFilter filter ;
760
762
private final Transaction tx ;
@@ -765,14 +767,22 @@ public SearchEvaluator(Transaction tx, SearchFilter filter) {
765
767
}
766
768
767
769
@ Override
768
- public Evaluation evaluate (Path path ) {
770
+ public Evaluation evaluate (Path path , BranchState < SearchFilter . EnvelopFilterResult > state ) {
769
771
Relationship rel = path .lastRelationship ();
770
772
Node node = path .endNode ();
771
773
if (rel == null ) {
772
774
return Evaluation .EXCLUDE_AND_CONTINUE ;
773
775
}
774
776
if (rel .isType (RTreeRelationshipTypes .RTREE_CHILD )) {
775
- boolean shouldContinue = filter .needsToVisit (getIndexNodeEnvelope (node ));
777
+ boolean shouldContinue ;
778
+ if (state .getState () == SearchFilter .EnvelopFilterResult .INCLUDE_ALL ) {
779
+ shouldContinue = true ;
780
+ } else {
781
+ SearchFilter .EnvelopFilterResult envelopFilterResult = filter .needsToVisitExtended (
782
+ getIndexNodeEnvelope (node ));
783
+ state .setState (envelopFilterResult );
784
+ shouldContinue = envelopFilterResult != SearchFilter .EnvelopFilterResult .EXCLUDE_ALL ;
785
+ }
776
786
if (shouldContinue ) {
777
787
monitor .matchedTreeNode (path .length (), node );
778
788
}
@@ -782,7 +792,12 @@ public Evaluation evaluate(Path path) {
782
792
Evaluation .EXCLUDE_AND_PRUNE ;
783
793
}
784
794
if (rel .isType (RTreeRelationshipTypes .RTREE_REFERENCE )) {
785
- boolean found = filter .geometryMatches (tx , node );
795
+ boolean found ;
796
+ if (state .getState () == SearchFilter .EnvelopFilterResult .INCLUDE_ALL ) {
797
+ found = true ;
798
+ } else {
799
+ found = filter .geometryMatches (tx , node );
800
+ }
786
801
monitor .addCase (found ? "Geometry Matches" : "Geometry Does NOT Match" );
787
802
if (found ) {
788
803
monitor .setHeight (path .length ());
@@ -801,6 +816,7 @@ public SearchResults searchIndex(Transaction tx, SearchFilter filter) {
801
816
MonoDirectionalTraversalDescription traversal = new MonoDirectionalTraversalDescription ();
802
817
TraversalDescription td = traversal
803
818
.depthFirst ()
819
+ .expand (StandardExpander .DEFAULT , path -> SearchFilter .EnvelopFilterResult .FILTER )
804
820
.relationships (RTreeRelationshipTypes .RTREE_CHILD , Direction .OUTGOING )
805
821
.relationships (RTreeRelationshipTypes .RTREE_REFERENCE , Direction .OUTGOING )
806
822
.evaluator (searchEvaluator );
0 commit comments