use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class SimilarImpl method evaluate.
@Override
public boolean evaluate() {
// conditions
if (!(selector.getIndex() instanceof FulltextQueryIndex)) {
log.warn("No full-text index was found that can process the condition " + toString());
return false;
}
// verify the path is readable
PropertyValue p = pathExpression.currentValue();
String path = p.getValue(Type.STRING);
if (selector.getTree(path) == null) {
return false;
}
if (propertyName != null) {
if (selector.currentProperty(propertyName) == null) {
// property not found
return false;
}
}
// we assume the index only returns the requested entries
return true;
}
use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class SuggestImpl method restrict.
@Override
public void restrict(FilterImpl f) {
if (f.getSelector().equals(selector)) {
PropertyValue p = expression.currentValue();
String term = p.getValue(Type.STRING);
String query = SUGGEST_PREFIX + term;
PropertyValue v = PropertyValues.newString(query);
f.restrictProperty(NativeFunctionImpl.NATIVE_PREFIX + NATIVE_LUCENE_LANGUAGE, Operator.EQUAL, v);
}
}
use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class FullTextSearchImpl method getFullTextConstraint.
@Override
public FullTextExpression getFullTextConstraint(SelectorImpl s) {
if (!s.equals(selector)) {
return null;
}
PropertyValue v = fullTextSearchExpression.currentValue();
try {
String p = propertyName;
if (relativePath != null) {
if (p == null) {
p = "*";
}
p = PathUtils.concat(relativePath, p);
}
String p2 = normalizePropertyName(p);
String rawText = getRawText(v);
FullTextExpression e = FullTextParser.parse(p2, rawText);
return new FullTextContains(p2, rawText, e);
} catch (ParseException e) {
throw new IllegalArgumentException("Invalid expression: " + fullTextSearchExpression, e);
}
}
use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class UpperCaseImpl method currentProperty.
@Override
public PropertyValue currentProperty() {
PropertyValue p = operand.currentProperty();
if (p == null) {
return null;
}
// TODO what is the expected result of UPPER(x) for an array property?
// currently throws an exception
String value = p.getValue(STRING);
return PropertyValues.newString(value.toUpperCase());
}
use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.
the class PropertyIndexTest method valuePattern.
@Test
public void valuePattern() throws Exception {
NodeState root = EMPTY_NODE;
// Add index definitions
NodeBuilder builder = root.builder();
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
NodeBuilder indexDef = createIndexDefinition(index, "fooIndex", true, false, ImmutableSet.of("foo"), null);
indexDef.setProperty(IndexConstants.VALUE_PATTERN, "(a.*|b)");
NodeState before = builder.getNodeState();
// Add some content and process it through the property index hook
builder.child("a").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "a");
builder.child("a1").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "a1");
builder.child("b").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "b");
builder.child("c").setProperty(JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME).setProperty("foo", "c");
NodeState after = builder.getNodeState();
// Add an index
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
FilterImpl f = createFilter(after, NT_UNSTRUCTURED);
// Query the index
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
PropertyIndex pIndex = new PropertyIndex(Mounts.defaultMountInfoProvider());
assertEquals(ImmutableSet.of("a"), find(lookup, "foo", "a", f));
assertEquals(ImmutableSet.of("a1"), find(lookup, "foo", "a1", f));
assertEquals(ImmutableSet.of("b"), find(lookup, "foo", "b", f));
// expected: no index for "is not null"
assertTrue(pIndex.getCost(f, indexed) == Double.POSITIVE_INFINITY);
ArrayList<PropertyValue> list = new ArrayList<PropertyValue>();
list.add(PropertyValues.newString("c"));
f.restrictPropertyAsList("foo", list);
// expected: no index for value c
assertTrue(pIndex.getCost(f, indexed) == Double.POSITIVE_INFINITY);
f = createFilter(after, NT_UNSTRUCTURED);
list = new ArrayList<PropertyValue>();
list.add(PropertyValues.newString("a"));
f.restrictPropertyAsList("foo", list);
// expected: no index for value a
assertTrue(pIndex.getCost(f, indexed) < Double.POSITIVE_INFINITY);
}
Aggregations