ChildNode childConstraint = (ChildNode)constraint;
final int locationIndex = columns.getLocationIndex(childConstraint.getSelectorName().getName());
final String parentPath = childConstraint.getParentPath();
return new ConstraintChecker() {
public boolean satisfiesConstraints( Object[] tuple ) {
Location location = (Location)tuple[locationIndex];
assert location.hasPath();
return location.getPath().getParent().equals(parentPath);
}
};
}
if (constraint instanceof DescendantNode) {
DescendantNode descendantNode = (DescendantNode)constraint;
final int locationIndex = columns.getLocationIndex(descendantNode.getSelectorName().getName());
final String ancestorPath = descendantNode.getAncestorPath();
return new ConstraintChecker() {
public boolean satisfiesConstraints( Object[] tuple ) {
Location location = (Location)tuple[locationIndex];
assert location.hasPath();
return analyzer.isDescendantOf(location, ancestorPath);
}
};
}
if (constraint instanceof SameNode) {
SameNode sameNode = (SameNode)constraint;
final int locationIndex = columns.getLocationIndex(sameNode.getSelectorName().getName());
final String path = sameNode.getPath();
if (analyzer != null) {
return new ConstraintChecker() {
public boolean satisfiesConstraints( Object[] tuple ) {
Location location = (Location)tuple[locationIndex];
return analyzer.isSameNode(location, path);
}
};
}
return new ConstraintChecker() {
public boolean satisfiesConstraints( Object[] tuple ) {
Location location = (Location)tuple[locationIndex];
assert location.hasPath();
return location.toString().equals(path);
}
};
}
if (constraint instanceof PropertyExistence) {
PropertyExistence propertyExistance = (PropertyExistence)constraint;
String selectorName = propertyExistance.getSelectorName().getName();
final String propertyName = propertyExistance.getPropertyName();
if (analyzer != null) {
final int locationIndex = columns.getLocationIndex(selectorName);
return new ConstraintChecker() {
public boolean satisfiesConstraints( Object[] tuple ) {
Location location = (Location)tuple[locationIndex];
return analyzer.hasProperty(location, propertyName);
}
};
}
final int columnIndex = columns.getColumnIndexForProperty(selectorName, propertyName);
return new ConstraintChecker() {
public boolean satisfiesConstraints( Object[] tuple ) {
return tuple[columnIndex] != null;
}
};
}
if (constraint instanceof FullTextSearch) {
if (analyzer != null) {
FullTextSearch search = (FullTextSearch)constraint;
String selectorName = search.getSelectorName().getName();
final int locationIndex = columns.getLocationIndex(selectorName);
final String expression = search.getFullTextSearchExpression();
if (expression == null) {
return new ConstraintChecker() {
public boolean satisfiesConstraints( Object[] tuple ) {
return false;
}
};
}
final String propertyName = search.getPropertyName(); // may be null
final int scoreIndex = columns.getFullTextSearchScoreIndexFor(selectorName);
assert scoreIndex >= 0 : "Columns do not have room for the search scores";
if (propertyName != null) {
return new ConstraintChecker() {
public boolean satisfiesConstraints( Object[] tuple ) {
Location location = (Location)tuple[locationIndex];
if (location == null) return false;
double score = analyzer.hasFullText(location, propertyName, expression);
// put the score on the correct tuple value ...
Double existing = (Double)tuple[scoreIndex];
if (existing != null) {
score = Math.max(existing.doubleValue(), score);
}
tuple[scoreIndex] = new Double(score);
return true;
}
};
}
return new ConstraintChecker() {
public boolean satisfiesConstraints( Object[] tuple ) {
Location location = (Location)tuple[locationIndex];
if (location == null) return false;
double score = analyzer.hasFullText(location, expression);
// put the score on the correct tuple value ...
Double existing = (Double)tuple[scoreIndex];
if (existing != null) {