List of usage examples for org.apache.lucene.search FieldComparator compareValues
@SuppressWarnings("unchecked") public int compareValues(T first, T second)
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);/* www. j a v a 2 s . c o m*/ BytesRef value1 = mapper.bytesRef(token("k1")); BytesRef value2 = mapper.bytesRef(token("k2")); fieldComparator.compareValues(value1, value2); } }
From source file:org.apache.solr.handler.component.ShardFieldSortedHitQueue.java
License:Apache License
Comparator<ShardDoc> comparatorFieldComparator(SortField sortField) {
final FieldComparator fieldComparator = sortField.getComparator(0, 0);
return new ShardComparator(sortField) {
// Since the PriorityQueue keeps the biggest elements by default,
// we need to reverse the field compare ordering so that the
// smallest elements are kept instead of the largest... hence
// the negative sign.
@Override//from www . ja v a 2s .c o m
public int compare(final ShardDoc o1, final ShardDoc o2) {
//noinspection unchecked
return -fieldComparator.compareValues(sortVal(o1), sortVal(o2));
}
};
}
From source file:org.apache.solr.search.federated.ShardFieldSortedHitQueue.java
License:Apache License
@SuppressWarnings("rawtypes") Comparator<ShardDoc> comparatorFieldComparator(SortField sortField) { final FieldComparator fieldComparator; try {/* ww w. j a va 2s . c om*/ fieldComparator = sortField.getComparator(0, 0); } catch (IOException e) { throw new RuntimeException("Unable to get FieldComparator for sortField " + sortField); } return new ShardComparator(sortField) { // Since the PriorityQueue keeps the biggest elements by default, // we need to reverse the field compare ordering so that the // smallest elements are kept instead of the largest... hence // the negative sign. @Override @SuppressWarnings("unchecked") public int compare(final ShardDoc o1, final ShardDoc o2) { // noinspection unchecked return -fieldComparator.compareValues(sortVal(o1), sortVal(o2)); } }; }