本文整理汇总了Java中org.apache.lucene.search.FieldComparator类的典型用法代码示例。如果您正苦于以下问题:Java FieldComparator类的具体用法?Java FieldComparator怎么用?Java FieldComparator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FieldComparator类属于org.apache.lucene.search包,在下文中一共展示了FieldComparator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newComparator
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) {
assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldName());
final Long dMissingValue = (Long) missingObject(missingValue, reversed);
// NOTE: it's important to pass null as a missing value in the constructor so that
// the comparator doesn't check docsWithField since we replace missing values in select()
return new FieldComparator.LongComparator(numHits, null, null) {
@Override
protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
final SortedNumericDocValues values = indexFieldData.load(context).getLongValues();
final NumericDocValues selectedValues;
if (nested == null) {
selectedValues = sortMode.select(values, dMissingValue);
} else {
final BitSet rootDocs = nested.rootDocs(context);
final DocIdSetIterator innerDocs = nested.innerDocs(context);
selectedValues = sortMode.select(values, dMissingValue, rootDocs, innerDocs, context.reader().maxDoc());
}
return selectedValues;
}
};
}
示例2: newComparator
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) {
assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldName());
final float dMissingValue = (Float) missingObject(missingValue, reversed);
// NOTE: it's important to pass null as a missing value in the constructor so that
// the comparator doesn't check docsWithField since we replace missing values in select()
return new FieldComparator.FloatComparator(numHits, null, null) {
@Override
protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
final SortedNumericDoubleValues values = indexFieldData.load(context).getDoubleValues();
final NumericDoubleValues selectedValues;
if (nested == null) {
selectedValues = sortMode.select(values, dMissingValue);
} else {
final BitSet rootDocs = nested.rootDocs(context);
final DocIdSetIterator innerDocs = nested.innerDocs(context);
selectedValues = sortMode.select(values, dMissingValue, rootDocs, innerDocs, context.reader().maxDoc());
}
return selectedValues.getRawFloatValues();
}
};
}
示例3: newComparator
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
return new FieldComparator<Object>() {
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
return LEAF_FIELD_COMPARATOR;
}
@Override
public int compare(int slot1, int slot2) {
return 0;
}
@Override
public void setTopValue(Object value) {
}
@Override
public Object value(int slot) {
return missingValue;
}
};
}
示例4: newComparator
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldNames().indexName());
final Long dMissingValue = (Long) missingObject(missingValue, reversed);
// NOTE: it's important to pass null as a missing value in the constructor so that
// the comparator doesn't check docsWithField since we replace missing values in select()
return new FieldComparator.LongComparator(numHits, null, null) {
@Override
protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
final SortedNumericDocValues values = indexFieldData.load(context).getLongValues();
final NumericDocValues selectedValues;
if (nested == null) {
selectedValues = sortMode.select(values, dMissingValue);
} else {
final BitSet rootDocs = nested.rootDocs(context);
final DocIdSetIterator innerDocs = nested.innerDocs(context);
selectedValues = sortMode.select(values, dMissingValue, rootDocs, innerDocs, context.reader().maxDoc());
}
return selectedValues;
}
};
}
示例5: newComparator
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldNames().indexName());
final float dMissingValue = (Float) missingObject(missingValue, reversed);
// NOTE: it's important to pass null as a missing value in the constructor so that
// the comparator doesn't check docsWithField since we replace missing values in select()
return new FieldComparator.FloatComparator(numHits, null, null) {
@Override
protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
final SortedNumericDoubleValues values = indexFieldData.load(context).getDoubleValues();
final NumericDoubleValues selectedValues;
if (nested == null) {
selectedValues = sortMode.select(values, dMissingValue);
} else {
final BitSet rootDocs = nested.rootDocs(context);
final DocIdSetIterator innerDocs = nested.innerDocs(context);
selectedValues = sortMode.select(values, dMissingValue, rootDocs, innerDocs, context.reader().maxDoc());
}
return selectedValues.getRawFloatValues();
}
};
}
示例6: sortField
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
/**
* 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);
}
};
}
});
}
示例7: comparatorFieldComparator
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
Comparator<ShardDoc> comparatorFieldComparator(SortField sortField) {
final FieldComparator fieldComparator;
try {
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
public int compare(final ShardDoc o1, final ShardDoc o2) {
//noinspection unchecked
return -fieldComparator.compareValues(sortVal(o1), sortVal(o2));
}
};
}
示例8: comparatorFieldComparator
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
Comparator<ShardDoc> comparatorFieldComparator(SortField sortField) {
final FieldComparator fieldComparator;
try {
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));
}
};
}
示例9: newComparator
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) {
assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldName());
final double dMissingValue = (Double) missingObject(missingValue, reversed);
// NOTE: it's important to pass null as a missing value in the constructor so that
// the comparator doesn't check docsWithField since we replace missing values in select()
return new FieldComparator.DoubleComparator(numHits, null, null) {
@Override
protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
final SortedNumericDoubleValues values = getValues(context);
final NumericDoubleValues selectedValues;
if (nested == null) {
selectedValues = sortMode.select(values, dMissingValue);
} else {
final BitSet rootDocs = nested.rootDocs(context);
final DocIdSetIterator innerDocs = nested.innerDocs(context);
selectedValues = sortMode.select(values, dMissingValue, rootDocs, innerDocs, context.reader().maxDoc());
}
return selectedValues.getRawDoubleValues();
}
@Override
public void setScorer(Scorer scorer) {
DoubleValuesComparatorSource.this.setScorer(scorer);
}
};
}
示例10: createCurrentUserFirstComparator
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
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());
}
};
}
示例11: newComparator
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldNames().indexName());
final double dMissingValue = (Double) missingObject(missingValue, reversed);
// NOTE: it's important to pass null as a missing value in the constructor so that
// the comparator doesn't check docsWithField since we replace missing values in select()
return new FieldComparator.DoubleComparator(numHits, null, null) {
@Override
protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
final SortedNumericDoubleValues values = getValues(context);
final NumericDoubleValues selectedValues;
if (nested == null) {
selectedValues = sortMode.select(values, dMissingValue);
} else {
final BitSet rootDocs = nested.rootDocs(context);
final DocIdSetIterator innerDocs = nested.innerDocs(context);
selectedValues = sortMode.select(values, dMissingValue, rootDocs, innerDocs, context.reader().maxDoc());
}
return selectedValues.getRawDoubleValues();
}
@Override
public void setScorer(Scorer scorer) {
DoubleValuesComparatorSource.this.setScorer(scorer);
}
};
}
示例12: sortField
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
/**
* 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));
}
};
}
});
}
示例13: setSortFieldRandom
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
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();
}
}
));
}
示例14: setScorer
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
@Override
public void setScorer(Scorer scorer) throws IOException {
this.scorer = scorer;
for (GroupHead groupHead : groups.values()) {
for (FieldComparator<?> comparator : groupHead.comparators) {
comparator.setScorer(scorer);
}
}
}
示例15: GroupHead
import org.apache.lucene.search.FieldComparator; //导入依赖的package包/类
@SuppressWarnings({"unchecked","rawtypes"})
private GroupHead(MutableValue groupValue, Sort sort, int doc) throws IOException {
super(groupValue, doc + readerContext.docBase);
final SortField[] sortFields = sort.getSort();
comparators = new FieldComparator[sortFields.length];
for (int i = 0; i < sortFields.length; i++) {
comparators[i] = sortFields[i].getComparator(1, i).setNextReader(readerContext);
comparators[i].setScorer(scorer);
comparators[i].copy(0, doc);
comparators[i].setBottom(0);
}
}