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

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

Introduction

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

Prototype

public abstract FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed);

Source Link

Document

Creates a comparator for the field in the given index.

Usage

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

License:Apache License

@Test
@SuppressWarnings("unchecked")
public void testSortFields() throws IOException {
    List<SortField> sortFields = mapper.sortFields();
    assertNotNull("Sort fields should be not null", sortFields);
    assertEquals("Sort fields should contain a single element", 1, sortFields.size());
    for (SortField sortField : sortFields) {
        FieldComparatorSource comparatorSource = sortField.getComparatorSource();
        assertNotNull("Sort field comparator should be not null", comparatorSource);
        FieldComparator fieldComparator = comparatorSource.newComparator(TokenMapperGeneric.FIELD_NAME, 1, 0,
                true);/* ww  w. j  av  a 2 s .co m*/
        BytesRef value1 = mapper.bytesRef(token("k1"));
        BytesRef value2 = mapper.bytesRef(token("k2"));
        fieldComparator.compareValues(value1, value2);
    }
}