Example usage for org.apache.lucene.search FieldComparatorSource FieldComparatorSource

List of usage examples for org.apache.lucene.search FieldComparatorSource FieldComparatorSource

Introduction

In this page you can find the example usage for org.apache.lucene.search FieldComparatorSource FieldComparatorSource.

Prototype

FieldComparatorSource

Source Link

Usage

From source file:com.stratio.cassandra.index.ClusteringKeyMapperGeneric.java

License:Apache License

@Override
public SortField[] sortFields() {
    return new SortField[] { new SortField(FIELD_NAME, new FieldComparatorSource() {
        @Override//from  www. ja va  2 s  . co m
        public FieldComparator<?> newComparator(String field, int hits, int sort, boolean reversed)
                throws IOException {
            return new ClusteringKeySorter(ClusteringKeyMapperGeneric.this, hits, field);
        }
    }) };
}

From source file:com.stratio.cassandra.index.TokenMapperGeneric.java

License:Apache License

/** {@inheritDoc} */
@Override//from  w  ww .  j  a va  2s.com
public SortField[] sortFields() {
    return new SortField[] { new SortField(FIELD_NAME, new FieldComparatorSource() {
        @Override
        public FieldComparator<?> newComparator(String field, int hits, int sort, boolean reversed)
                throws IOException {
            return new TokenMapperGenericSorter(TokenMapperGeneric.this, hits, field);
        }
    }) };
}

From source file:com.stratio.cassandra.lucene.key.KeyMapper.java

License:Apache License

/**
 * Returns a Lucene {@link SortField} to sort documents by primary key according to Cassandra's natural order.
 *
 * @return the sort field//w  w  w  .j  a  va2s  . c om
 */
public SortField sortField() {
    return new SortField(FIELD_NAME, new FieldComparatorSource() {
        @Override
        public FieldComparator<?> newComparator(String field, int hits, int sort, boolean reversed)
                throws IOException {
            return new FieldComparator.TermValComparator(hits, field, false) {
                @Override
                public int compareValues(BytesRef val1, BytesRef val2) {
                    return entry(val1).compareTo(entry(val2));
                }
            };
        }
    });
}

From source file:com.stratio.cassandra.lucene.key.KeySort.java

License:Apache License

/**
 * Builds a new {@link KeySort} for the specified {@link KeyMapper}.
 *
 * @param mapper the primary key mapper to be used
 *///from  w  w  w.j  a v a 2s .  co  m
KeySort(KeyMapper mapper) {
    super(KeyMapper.FIELD_NAME, new FieldComparatorSource() {
        @Override
        public FieldComparator<?> newComparator(String field, int hits, int sort, boolean reversed)
                throws IOException {
            return new FieldComparator.TermValComparator(hits, field, false) {
                @Override
                public int compareValues(BytesRef val1, BytesRef val2) {
                    return mapper.entry(val1).compareTo(mapper.entry(val2));
                }
            };
        }
    });
}

From source file:com.stratio.cassandra.lucene.key.PartitionMapper.java

License:Apache License

/**
 * Returns a Lucene {@link SortField} for sorting documents/rows according to the partition key.
 *
 * @return a sort field for sorting by partition key
 *//*from  w w  w .j  a  v  a2s. c om*/
public SortField sortField() {
    return new SortField(FIELD_NAME, new FieldComparatorSource() {
        @Override
        public FieldComparator<?> newComparator(String field, int hits, int sort, boolean reversed)
                throws IOException {
            return new FieldComparator.TermValComparator(hits, field, false) {
                @Override
                public int compareValues(BytesRef val1, BytesRef val2) {
                    ByteBuffer bb1 = ByteBufferUtils.byteBuffer(val1);
                    ByteBuffer bb2 = ByteBufferUtils.byteBuffer(val2);
                    return ByteBufferUtil.compareUnsigned(bb1, bb2);
                }
            };
        }
    });
}

From source file:com.stratio.cassandra.lucene.key.PartitionSort.java

License:Apache License

/**
 * Builds a new {@link PartitionSort} for the specified {@link PartitionMapper}.
 *
 * @param mapper the partition key mapper to be used
 *///from  ww  w.  j a  va  2 s  .  c  o m
PartitionSort(PartitionMapper mapper) {
    super(PartitionMapper.FIELD_NAME, new FieldComparatorSource() {
        @Override
        public FieldComparator<?> newComparator(String field, int hits, int sort, boolean reversed)
                throws IOException {
            return new FieldComparator.TermValComparator(hits, field, false) {
                @Override
                public int compareValues(BytesRef val1, BytesRef val2) {
                    ByteBuffer bb1 = ByteBufferUtils.byteBuffer(val1);
                    ByteBuffer bb2 = ByteBufferUtils.byteBuffer(val2);
                    return mapper.getType().compare(bb1, bb2);
                }
            };
        }
    });
}

From source file:com.stratio.cassandra.lucene.service.ClusteringKeyMapper.java

License:Apache License

/**
 * Returns a Lucene {@link SortField} array for sorting documents/rows according to the column family name.
 *
 * @return A Lucene {@link SortField} array for sorting documents/rows according to the column family name.
 *//*from w w  w  .j ava 2 s  . c  om*/
public SortField[] sortFields() {
    return new SortField[] { new SortField(FIELD_NAME, new FieldComparatorSource() {
        @Override
        public FieldComparator<?> newComparator(String field, int hits, int sort, boolean reversed)
                throws IOException {
            return new FieldComparator.TermValComparator(hits, field, false) {
                @Override
                public int compareValues(BytesRef val1, BytesRef val2) {
                    CellName bb1 = clusteringKey(val1);
                    CellName bb2 = clusteringKey(val2);
                    return cellNameType.compare(bb1, bb2);
                }
            };
        }
    }) };
}

From source file:com.stratio.cassandra.lucene.service.TokenMapperGeneric.java

License:Apache License

/** {@inheritDoc} */
@Override/*from w  ww.ja  v  a 2s  . com*/
public SortField[] sortFields() {
    return new SortField[] { new SortField(FIELD_NAME, new FieldComparatorSource() {
        @Override
        public FieldComparator<?> newComparator(String field, int hits, int sort, boolean reversed)
                throws IOException {
            return new FieldComparator.TermValComparator(hits, field, false) {
                @Override
                public int compareValues(BytesRef val1, BytesRef val2) {
                    return token(val1).compareTo(token(val2));
                }
            };
        }
    }) };
}

From source file:io.crate.execution.engine.sort.SortSymbolVisitor.java

License:Apache License

private SortField customSortField(String name, final Symbol symbol, final SortSymbolContext context,
        final boolean missingNullValue) {
    InputFactory.Context<? extends LuceneCollectorExpression<?>> inputContext = docInputFactory.getCtx();
    final Input input = inputContext.add(symbol);
    final Collection<? extends LuceneCollectorExpression<?>> expressions = inputContext.expressions();

    return new SortField(name, new FieldComparatorSource() {
        @Override/*from ww w .  j a v a 2 s.com*/
        public FieldComparator<?> newComparator(String fieldName, int numHits, int sortPos, boolean reversed) {
            for (LuceneCollectorExpression collectorExpression : expressions) {
                collectorExpression.startCollect(context.context);
            }
            DataType dataType = symbol.valueType();
            Object missingValue = missingNullValue ? null
                    : SortSymbolVisitor.missingObject(dataType,
                            SortOrder.missing(context.reverseFlag, context.nullFirst), reversed);

            if (context.context.visitor().required()) {
                return new FieldsVisitorInputFieldComparator(numHits, context.context.visitor(), expressions,
                        input, dataType, missingValue);

            } else {
                return new InputFieldComparator(numHits, expressions, input, dataType, missingValue);
            }
        }
    }, context.reverseFlag);
}

From source file:org.drftpd.vfs.index.lucene.LuceneEngine.java

License:Open Source License

private void setSortFieldRandom() {
    SORT.setSort(new SortField("", new FieldComparatorSource() {
        @Override//from w w  w .ja  va  2 s.  c om
        public FieldComparator<Integer> newComparator(String fieldname, int numHits, int sortPos,
                boolean reversed) throws IOException {
            return new RandomOrderFieldComparator();
        }
    }));
}