/** * Returns a Lucene {@link SortField} for sorting documents/rows according * to the partition key. * * @return a sort field for sorting by partition key */ 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); } }; } }); }
private SortField(String field, boolean reverse, Type type, FieldComparatorSource fieldComparatorSource) { this.field = field; this.reverse = reverse; this.type = type; this.fieldComparatorSource = fieldComparatorSource; }
private static FieldComparatorSource createCurrentUserFirstComparator() { return new FieldComparatorSource() { @Override public FieldComparator<Integer> newComparator(final String fieldName, final int numHits, final int sortPos, boolean reversed) throws IOException { return new CustomLuceneSortComparator(numHits, fieldName, CurrentUser.getUserID()); } }; }
/** * Returns a Lucene {@link SortField} to sort documents by primary key * according to Cassandra's natural order. * * @return the sort field */ 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)); } }; } }); }
private void setSortFieldRandom() { SORT.setSort(new SortField( "", new FieldComparatorSource() { @Override public FieldComparator<Integer> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException { return new RandomOrderFieldComparator(); } } )); }
public BinarySortField(final String field, final boolean reverse) { super(field, new FieldComparatorSource() { @Override public FieldComparator.TermOrdValComparator newComparator (final String fieldname, final int numHits, final int sortPos, final boolean reversed) throws IOException { return new FieldComparator.TermOrdValComparator(numHits, fieldname); }}, reverse); }
/** * 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. */ 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 ClusteringKeySorter(ClusteringKeyMapper.this, hits, field); } })}; }
Comparator getCachedComparator(String fieldname, SortField.Type type, FieldComparatorSource factory) { Comparator comparator = null; switch (type) { case SCORE: comparator = comparatorScore(fieldname); break; case STRING: comparator = comparatorNatural(fieldname); break; case CUSTOM: if (factory instanceof MissingStringLastComparatorSource){ comparator = comparatorMissingStringLast(fieldname); } else { // TODO: support other types such as random... is there a way to // support generically? Perhaps just comparing Object comparator = comparatorNatural(fieldname); // throw new RuntimeException("Custom sort not supported factory is "+factory.getClass()); } break; case DOC: // TODO: we can support this! throw new RuntimeException("Doc sort not supported"); default: comparator = comparatorNatural(fieldname); break; } return comparator; }
Comparator getCachedComparator(String fieldname, SortField.Type type, FieldComparatorSource factory) { Comparator comparator = null; switch(type) { case SCORE: comparator = comparatorScore(fieldname); break; case STRING: comparator = comparatorNatural(fieldname); break; case CUSTOM: if(factory instanceof MissingStringLastComparatorSource) { comparator = comparatorMissingStringLast(fieldname); } else { // TODO: support other types such as random... is there a way to // support generically? Perhaps just comparing Object comparator = comparatorNatural(fieldname); // throw new RuntimeException("Custom sort not supported factory is "+factory.getClass()); } break; case DOC: // TODO: we can support this! throw new RuntimeException("Doc sort not supported"); default: comparator = comparatorNatural(fieldname); break; } return comparator; }
private Sort createSort(ResponseBuilder rb, SolrParams params) { Query query = rb.getQuery(); FeatureExtractor extractor = extractorFactory.create(params, query); Classifier classifier = classifierFactory.createClassifier(); FieldComparatorSource comparator = new RankingComparatorSource( extractor, classifier, params, query); Sort sort = new Sort(new SortField("ranking", comparator)); return sort; }
private Sort getRaningSort(Query query) { FieldComparatorSource comparator = new RankingComparatorSource( extractor, classifier, null, query); Sort sort = new Sort(new SortField[] { new SortField("ranking", comparator) }); return sort; }
public SortField(String field, FieldComparatorSource fieldComparatorSource) { this(field, false, Type.CUSTOM, fieldComparatorSource); }
public FieldComparatorSource getFieldComparatorSource() { return fieldComparatorSource; }
/** * Takes a search request and prepares a Lucene Sort object, or null if no * sorting is required. */ private Sort getSorter(Search request) { com.tle.common.searching.SortField[] sortfields = request.getSortFields(); if( sortfields != null ) { SortField[] convFields = new SortField[sortfields.length]; int i = 0; for( com.tle.common.searching.SortField sortfield : sortfields ) { FieldComparatorSource fieldComparatorSource = null; int type = SortField.STRING; switch( sortfield.getType() ) { case INT: type = SortField.INT; break; case LONG: type = SortField.LONG; break; case SCORE: type = SortField.SCORE; break; case CUSTOM: type = SortField.CUSTOM; fieldComparatorSource = sortfield.getFieldComparatorSource(); default: // Stays STRING break; } // @formatter:off SortField sortField = fieldComparatorSource != null ? new SortField(sortfield.getField(), fieldComparatorSource, request.isSortReversed()) : new SortField(sortfield.getField(), type, sortfield.isReverse() ^ request.isSortReversed()); // @formatter:on convFields[i++] = sortField; } return new Sort(convFields); } return new Sort(new SortField(null, SortField.SCORE, false)); }
@Override public FieldComparatorSource getSortComparatorSource() { return null; }