Search in sources :

Example 1 with NodeNameImpl

use of org.apache.jackrabbit.spi.commons.query.qom.NodeNameImpl in project jackrabbit by apache.

the class Ordering method fromQOM.

/**
 * Creates an ordering from a JCR QOM ordering.
 *
 * @param ordering   the JCR QOM ordering specification.
 * @param scs        the sort comparator source from the search index.
 * @param nsMappings the index internal namespace mappings.
 * @return an ordering.
 * @throws RepositoryException if an error occurs while translating the JCR
 *                             QOM ordering.
 */
public static Ordering fromQOM(final OrderingImpl ordering, final SharedFieldComparatorSource scs, final NamespaceMappings nsMappings) throws RepositoryException {
    final Name[] selectorName = new Name[1];
    QOMTreeVisitor visitor = new DefaultTraversingQOMTreeVisitor() {

        public Object visit(LengthImpl node, Object data) throws Exception {
            PropertyValueImpl propValue = (PropertyValueImpl) node.getPropertyValue();
            selectorName[0] = propValue.getSelectorQName();
            return new SortField(propValue.getPropertyQName().toString(), new LengthSortComparator(nsMappings), !ordering.isAscending());
        }

        public Object visit(LowerCaseImpl node, Object data) throws Exception {
            SortField sf = (SortField) ((DynamicOperandImpl) node.getOperand()).accept(this, data);
            selectorName[0] = node.getSelectorQName();
            return new SortField(sf.getField(), new LowerCaseSortComparator(sf.getComparatorSource()), !ordering.isAscending());
        }

        public Object visit(UpperCaseImpl node, Object data) throws Exception {
            SortField sf = (SortField) ((DynamicOperandImpl) node.getOperand()).accept(this, data);
            selectorName[0] = node.getSelectorQName();
            return new SortField(sf.getField(), new UpperCaseSortComparator(sf.getComparatorSource()), !ordering.isAscending());
        }

        public Object visit(FullTextSearchScoreImpl node, Object data) throws Exception {
            selectorName[0] = node.getSelectorQName();
            return new SortField(null, SortField.SCORE, !ordering.isAscending());
        }

        public Object visit(NodeLocalNameImpl node, Object data) throws Exception {
            selectorName[0] = node.getSelectorQName();
            return new SortField(FieldNames.LOCAL_NAME, SortField.STRING, !ordering.isAscending());
        }

        public Object visit(NodeNameImpl node, Object data) throws Exception {
            selectorName[0] = node.getSelectorQName();
            return new SortField(FieldNames.LABEL, SortField.STRING, !ordering.isAscending());
        }

        public Object visit(PropertyValueImpl node, Object data) throws Exception {
            selectorName[0] = node.getSelectorQName();
            return new SortField(node.getPropertyQName().toString(), scs, !ordering.isAscending());
        }

        public Object visit(OrderingImpl node, Object data) throws Exception {
            return ((DynamicOperandImpl) node.getOperand()).accept(this, data);
        }
    };
    try {
        SortField field = (SortField) ordering.accept(visitor, null);
        return new Ordering(selectorName[0], field);
    } catch (Exception e) {
        throw new RepositoryException(e);
    }
}
Also used : DynamicOperandImpl(org.apache.jackrabbit.spi.commons.query.qom.DynamicOperandImpl) DefaultTraversingQOMTreeVisitor(org.apache.jackrabbit.spi.commons.query.qom.DefaultTraversingQOMTreeVisitor) NodeLocalNameImpl(org.apache.jackrabbit.spi.commons.query.qom.NodeLocalNameImpl) OrderingImpl(org.apache.jackrabbit.spi.commons.query.qom.OrderingImpl) UpperCaseImpl(org.apache.jackrabbit.spi.commons.query.qom.UpperCaseImpl) FullTextSearchScoreImpl(org.apache.jackrabbit.spi.commons.query.qom.FullTextSearchScoreImpl) NodeNameImpl(org.apache.jackrabbit.spi.commons.query.qom.NodeNameImpl) SortField(org.apache.lucene.search.SortField) RepositoryException(javax.jcr.RepositoryException) QOMTreeVisitor(org.apache.jackrabbit.spi.commons.query.qom.QOMTreeVisitor) DefaultTraversingQOMTreeVisitor(org.apache.jackrabbit.spi.commons.query.qom.DefaultTraversingQOMTreeVisitor) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) LowerCaseImpl(org.apache.jackrabbit.spi.commons.query.qom.LowerCaseImpl) LengthImpl(org.apache.jackrabbit.spi.commons.query.qom.LengthImpl) PropertyValueImpl(org.apache.jackrabbit.spi.commons.query.qom.PropertyValueImpl)

Aggregations

RepositoryException (javax.jcr.RepositoryException)1 Name (org.apache.jackrabbit.spi.Name)1 DefaultTraversingQOMTreeVisitor (org.apache.jackrabbit.spi.commons.query.qom.DefaultTraversingQOMTreeVisitor)1 DynamicOperandImpl (org.apache.jackrabbit.spi.commons.query.qom.DynamicOperandImpl)1 FullTextSearchScoreImpl (org.apache.jackrabbit.spi.commons.query.qom.FullTextSearchScoreImpl)1 LengthImpl (org.apache.jackrabbit.spi.commons.query.qom.LengthImpl)1 LowerCaseImpl (org.apache.jackrabbit.spi.commons.query.qom.LowerCaseImpl)1 NodeLocalNameImpl (org.apache.jackrabbit.spi.commons.query.qom.NodeLocalNameImpl)1 NodeNameImpl (org.apache.jackrabbit.spi.commons.query.qom.NodeNameImpl)1 OrderingImpl (org.apache.jackrabbit.spi.commons.query.qom.OrderingImpl)1 PropertyValueImpl (org.apache.jackrabbit.spi.commons.query.qom.PropertyValueImpl)1 QOMTreeVisitor (org.apache.jackrabbit.spi.commons.query.qom.QOMTreeVisitor)1 UpperCaseImpl (org.apache.jackrabbit.spi.commons.query.qom.UpperCaseImpl)1 SortField (org.apache.lucene.search.SortField)1