use of javax.jcr.query.qom.FullTextSearchScore in project jackrabbit by apache.
the class QueryObjectModelFactoryTest method testFullTextSearchScore.
/**
* Test case for {@link QueryObjectModelFactory#fullTextSearchScore(String)}
*/
public void testFullTextSearchScore() throws RepositoryException {
FullTextSearchScore score = qf.fullTextSearchScore(SELECTOR_NAME1);
assertEquals("Wrong selector name", SELECTOR_NAME1, score.getSelectorName());
}
use of javax.jcr.query.qom.FullTextSearchScore in project jackrabbit by apache.
the class LuceneQueryFactory method mapConstraintToQueryAndFilter.
protected Predicate mapConstraintToQueryAndFilter(QueryPair query, Constraint constraint, Map<String, NodeType> selectorMap, JackrabbitIndexSearcher searcher, IndexReader reader) throws RepositoryException, IOException {
Predicate filter = Predicate.TRUE;
if (constraint instanceof And) {
And and = (And) constraint;
filter = mapConstraintToQueryAndFilter(query, and.getConstraint1(), selectorMap, searcher, reader);
Predicate other = mapConstraintToQueryAndFilter(query, and.getConstraint2(), selectorMap, searcher, reader);
if (filter == Predicate.TRUE) {
filter = other;
} else if (other != Predicate.TRUE) {
filter = Predicates.and(filter, other);
}
} else if (constraint instanceof Comparison) {
Comparison c = (Comparison) constraint;
Transform transform = new Transform(c.getOperand1());
DynamicOperand left = transform.operand;
final String operator = c.getOperator();
StaticOperand right = c.getOperand2();
if (left instanceof Length || left instanceof FullTextSearchScore || (((!JCR_OPERATOR_EQUAL_TO.equals(operator) && !JCR_OPERATOR_LIKE.equals(operator)) || transform.transform != TRANSFORM_NONE) && (left instanceof NodeName || left instanceof NodeLocalName))) {
try {
int type = PropertyType.UNDEFINED;
if (left instanceof Length) {
type = PropertyType.LONG;
} else if (left instanceof FullTextSearchScore) {
type = PropertyType.DOUBLE;
}
final DynamicOperand operand = c.getOperand1();
final Value value = evaluator.getValue(right, type);
filter = new RowPredicate() {
@Override
protected boolean evaluate(Row row) throws RepositoryException {
return new ValueComparator().evaluate(operator, evaluator.getValue(operand, row), value);
}
};
} catch (ValueFormatException e) {
throw new InvalidQueryException(e);
}
} else {
Query cq = getComparisonQuery(left, transform.transform, operator, right, selectorMap);
query.subQuery.add(cq, MUST);
}
} else if (constraint instanceof DescendantNode) {
final DescendantNode descendantNode = (DescendantNode) constraint;
Query context = getNodeIdQuery(UUID, descendantNode.getAncestorPath());
query.mainQuery = new DescendantSelfAxisQuery(context, query.subQuery, false);
} else {
query.subQuery.add(create(constraint, selectorMap, searcher), MUST);
}
return filter;
}
use of javax.jcr.query.qom.FullTextSearchScore 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);
}
}
use of javax.jcr.query.qom.FullTextSearchScore in project jackrabbit by apache.
the class QueryObjectModelFactoryTest method testFullTextSearchScoreWithSelector.
/**
* Test case for {@link QueryObjectModelFactory#fullTextSearchScore(String)}
*/
public void testFullTextSearchScoreWithSelector() throws RepositoryException {
FullTextSearchScore score = qf.fullTextSearchScore(SELECTOR_NAME1);
assertEquals("Wrong selector name", SELECTOR_NAME1, score.getSelectorName());
}
use of javax.jcr.query.qom.FullTextSearchScore in project jackrabbit-oak by apache.
the class QomTest method fullTextSearchScore.
@Test
public void fullTextSearchScore() throws RepositoryException {
FullTextSearchScore x = f.fullTextSearchScore("selectorName");
assertEquals("selectorName", x.getSelectorName());
assertEquals("SCORE([selectorName])", x.toString());
assertEquals("SCORE()", f.fullTextSearchScore(null).toString());
}
Aggregations