CavalliumDBEngine/src/main/java/it/cavallium/dbengine/lucene/RandomFieldComparatorSource.java

21 lines
637 B
Java
Raw Normal View History

2021-01-30 22:14:48 +01:00
package it.cavallium.dbengine.lucene;
2020-12-07 22:15:18 +01:00
import java.util.concurrent.ThreadLocalRandom;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.FieldComparatorSource;
import org.warp.commonutils.random.LFSR;
public class RandomFieldComparatorSource extends FieldComparatorSource {
private final LFSR rand;
public RandomFieldComparatorSource() {
this.rand = LFSR.random(24, ThreadLocalRandom.current().nextInt(1 << 24));
}
@Override
2021-02-03 14:37:02 +01:00
public FieldComparator<?> newComparator(String fieldName, int numHits, int sortPos, boolean reversed) {
2020-12-07 22:15:18 +01:00
return new RandomFieldComparator(rand.iterator(), numHits);
}
}