|
33 | 33 | import org.apache.lucene.sandbox.facet.plain.histograms.HistogramCollectorManager;
|
34 | 34 | import org.apache.lucene.search.IndexSearcher;
|
35 | 35 | import org.apache.lucene.search.MatchAllDocsQuery;
|
| 36 | +import org.apache.lucene.search.PointRangeQuery; |
36 | 37 | import org.apache.lucene.store.Directory;
|
37 | 38 | import org.apache.lucene.store.MMapDirectory;
|
| 39 | +import org.apache.lucene.util.NumericUtils; |
38 | 40 | import org.openjdk.jmh.annotations.Benchmark;
|
39 | 41 | import org.openjdk.jmh.annotations.BenchmarkMode;
|
40 | 42 | import org.openjdk.jmh.annotations.Fork;
|
@@ -122,9 +124,33 @@ public static class BenchmarkParams {
|
122 | 124 | }
|
123 | 125 |
|
124 | 126 | @Benchmark
|
125 |
| - public void collectHistogram(BenchmarkParams params) throws IOException { |
| 127 | + public void matchAllQueryHistogram(BenchmarkParams params) throws IOException { |
126 | 128 | IndexSearcher searcher = new IndexSearcher(reader);
|
127 | 129 | searcher.search(
|
128 | 130 | new MatchAllDocsQuery(), new HistogramCollectorManager("f", params.bucketWidth, 10000));
|
129 | 131 | }
|
| 132 | + |
| 133 | + @Benchmark |
| 134 | + public void pointRangeQueryHistogram(BenchmarkParams params) throws IOException { |
| 135 | + IndexSearcher searcher = new IndexSearcher(reader); |
| 136 | + |
| 137 | + Random r = new Random(0); |
| 138 | + int lowerBound = r.nextInt(params.docCount / 4, 3 * params.docCount / 4); |
| 139 | + // Filter for about 1/10 of the available documents |
| 140 | + int upperBound = lowerBound + params.docCount / 10; |
| 141 | + byte[] lowerPoint = new byte[Long.BYTES]; |
| 142 | + byte[] upperPoint = new byte[Long.BYTES]; |
| 143 | + NumericUtils.longToSortableBytes(lowerBound, lowerPoint, 0); |
| 144 | + NumericUtils.longToSortableBytes(upperBound, upperPoint, 0); |
| 145 | + final PointRangeQuery prq = |
| 146 | + new PointRangeQuery("f", lowerPoint, upperPoint, 1) { |
| 147 | + @Override |
| 148 | + protected String toString(int dimension, byte[] value) { |
| 149 | + return Long.toString(NumericUtils.sortableBytesToLong(value, 0)); |
| 150 | + } |
| 151 | + }; |
| 152 | + |
| 153 | + // Don't need to increase the default bucket count |
| 154 | + searcher.search(prq, new HistogramCollectorManager("f", params.bucketWidth)); |
| 155 | + } |
130 | 156 | }
|
0 commit comments