Search in sources :

Example 6 with StaticOperand

use of javax.jcr.query.qom.StaticOperand in project jackrabbit by apache.

the class OperandEvaluator method getValues.

/**
     * Evaluates the given operand in the context of the given row.
     *
     * @param operand operand to be evaluated
     * @param row query result row
     * @return values of the operand at the given row
     * @throws RepositoryException if the operand can't be evaluated
     */
public Value[] getValues(Operand operand, Row row) throws RepositoryException {
    if (operand instanceof StaticOperand) {
        StaticOperand so = (StaticOperand) operand;
        return new Value[] { getValue(so) };
    } else if (operand instanceof FullTextSearchScore) {
        FullTextSearchScore ftss = (FullTextSearchScore) operand;
        double score = row.getScore(ftss.getSelectorName());
        return new Value[] { factory.createValue(score) };
    } else if (operand instanceof NodeName) {
        NodeName nn = (NodeName) operand;
        String name = row.getNode(nn.getSelectorName()).getName();
        // root node
        if ("".equals(name)) {
            return new Value[] { factory.createValue(name, PropertyType.STRING) };
        }
        return new Value[] { factory.createValue(name, PropertyType.NAME) };
    } else if (operand instanceof Length) {
        return getLengthValues((Length) operand, row);
    } else if (operand instanceof LowerCase) {
        return getLowerCaseValues((LowerCase) operand, row);
    } else if (operand instanceof UpperCase) {
        return getUpperCaseValues((UpperCase) operand, row);
    } else if (operand instanceof NodeLocalName) {
        return getNodeLocalNameValues((NodeLocalName) operand, row);
    } else if (operand instanceof PropertyValue) {
        return getPropertyValues((PropertyValue) operand, row);
    } else {
        throw new UnsupportedRepositoryOperationException("Unknown operand type: " + operand);
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) UpperCase(javax.jcr.query.qom.UpperCase) StaticOperand(javax.jcr.query.qom.StaticOperand) NodeName(javax.jcr.query.qom.NodeName) Length(javax.jcr.query.qom.Length) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue) BindVariableValue(javax.jcr.query.qom.BindVariableValue) LowerCase(javax.jcr.query.qom.LowerCase) PropertyValue(javax.jcr.query.qom.PropertyValue) FullTextSearchScore(javax.jcr.query.qom.FullTextSearchScore) NodeLocalName(javax.jcr.query.qom.NodeLocalName)

Example 7 with StaticOperand

use of javax.jcr.query.qom.StaticOperand in project jackrabbit by apache.

the class QueryObjectModelFactoryTest method testFullTextSearch.

/**
     * Test case for {@link QueryObjectModelFactory#fullTextSearch(String, String, StaticOperand)}
     */
public void testFullTextSearch() throws RepositoryException {
    FullTextSearch ftSearch = qf.fullTextSearch(SELECTOR_NAME1, propertyName1, qf.literal(vf.createValue(FULLTEXT_SEARCH_EXPR)));
    assertEquals("Wrong selector name", SELECTOR_NAME1, ftSearch.getSelectorName());
    assertEquals("Wrong propertyName", propertyName1, ftSearch.getPropertyName());
    StaticOperand op = ftSearch.getFullTextSearchExpression();
    assertNotNull(op);
    assertTrue("not a Literal", op instanceof Literal);
    Literal literal = (Literal) op;
    assertEquals(FULLTEXT_SEARCH_EXPR, literal.getLiteralValue().getString());
}
Also used : StaticOperand(javax.jcr.query.qom.StaticOperand) Literal(javax.jcr.query.qom.Literal) FullTextSearch(javax.jcr.query.qom.FullTextSearch)

Aggregations

StaticOperand (javax.jcr.query.qom.StaticOperand)7 NodeLocalName (javax.jcr.query.qom.NodeLocalName)4 NodeName (javax.jcr.query.qom.NodeName)4 Value (javax.jcr.Value)3 BindVariableValue (javax.jcr.query.qom.BindVariableValue)3 PropertyValue (javax.jcr.query.qom.PropertyValue)3 RepositoryException (javax.jcr.RepositoryException)2 FullTextSearch (javax.jcr.query.qom.FullTextSearch)2 FullTextSearchScore (javax.jcr.query.qom.FullTextSearchScore)2 Length (javax.jcr.query.qom.Length)2 Literal (javax.jcr.query.qom.Literal)2 Name (org.apache.jackrabbit.spi.Name)2 ParseException (org.apache.lucene.queryParser.ParseException)2 QueryParser (org.apache.lucene.queryParser.QueryParser)2 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1 ValueFormatException (javax.jcr.ValueFormatException)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1 Row (javax.jcr.query.Row)1 And (javax.jcr.query.qom.And)1 Comparison (javax.jcr.query.qom.Comparison)1