Search in sources :

Example 11 with PropertyValue

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;
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) FulltextQueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex.FulltextQueryIndex)

Example 12 with PropertyValue

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);
    }
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Example 13 with PropertyValue

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);
    }
}
Also used : FullTextContains(org.apache.jackrabbit.oak.query.fulltext.FullTextContains) FullTextExpression(org.apache.jackrabbit.oak.query.fulltext.FullTextExpression) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) ParseException(java.text.ParseException)

Example 14 with PropertyValue

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());
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Example 15 with PropertyValue

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);
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) ArrayList(java.util.ArrayList) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

PropertyValue (org.apache.jackrabbit.oak.api.PropertyValue)57 Test (org.junit.Test)28 ResultRow (org.apache.jackrabbit.oak.api.ResultRow)26 RemoteValue (org.apache.jackrabbit.oak.remote.RemoteValue)24 Tree (org.apache.jackrabbit.oak.api.Tree)5 ParseException (java.text.ParseException)4 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)4 ArrayList (java.util.ArrayList)3 Result (org.apache.jackrabbit.oak.api.Result)3 Date (java.util.Date)2 Blob (org.apache.jackrabbit.oak.api.Blob)2 LiteralImpl (org.apache.jackrabbit.oak.query.ast.LiteralImpl)2 StaticOperandImpl (org.apache.jackrabbit.oak.query.ast.StaticOperandImpl)2 FulltextQueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex.FulltextQueryIndex)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 BigDecimal (java.math.BigDecimal)1 Calendar (java.util.Calendar)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1