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

21 lines
648 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;
2022-05-10 00:31:16 +02:00
import it.cavallium.dbengine.utils.LFSR;
2020-12-07 22:15:18 +01:00
public class RandomFieldComparatorSource extends FieldComparatorSource {
private final LFSR rand;
public RandomFieldComparatorSource() {
this.rand = LFSR.random(24, ThreadLocalRandom.current().nextInt(1 << 24));
}
@Override
2022-04-30 21:56:42 +02:00
public FieldComparator<?> newComparator(String fieldName, int numHits, boolean enableSkipping, boolean reversed) {
2020-12-07 22:15:18 +01:00
return new RandomFieldComparator(rand.iterator(), numHits);
}
}