|
42 | 42 | import org.apache.lucene.document.LongPoint;
|
43 | 43 | import org.apache.lucene.document.SortedNumericDocValuesField;
|
44 | 44 | import org.apache.lucene.document.StoredField;
|
| 45 | +import org.apache.lucene.index.LeafReaderContext; |
45 | 46 | import org.apache.lucene.sandbox.document.BigIntegerPoint;
|
46 | 47 | import org.apache.lucene.sandbox.document.HalfFloatPoint;
|
47 | 48 | import org.apache.lucene.search.BoostQuery;
|
| 49 | +import org.apache.lucene.search.ConstantScoreWeight; |
48 | 50 | import org.apache.lucene.search.IndexOrDocValuesQuery;
|
49 | 51 | import org.apache.lucene.search.IndexSearcher;
|
50 | 52 | import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery;
|
51 | 53 | import org.apache.lucene.search.MatchNoDocsQuery;
|
52 | 54 | import org.apache.lucene.search.PointInSetQuery;
|
53 | 55 | import org.apache.lucene.search.Query;
|
| 56 | +import org.apache.lucene.search.QueryVisitor; |
| 57 | +import org.apache.lucene.search.ScoreMode; |
| 58 | +import org.apache.lucene.search.Scorer; |
| 59 | +import org.apache.lucene.search.ScorerSupplier; |
| 60 | +import org.apache.lucene.search.Weight; |
54 | 61 | import org.apache.lucene.util.BytesRef;
|
55 | 62 | import org.apache.lucene.util.NumericUtils;
|
56 | 63 | import org.opensearch.common.Explicit;
|
@@ -1508,36 +1515,89 @@ public static Query unsignedLongRangeQuery(
|
1508 | 1515 | return builder.apply(l, u);
|
1509 | 1516 | }
|
1510 | 1517 |
|
1511 |
| - static PointInSetQuery bitmapIndexQuery(String field, RoaringBitmap bitmap) { |
1512 |
| - final BytesRef encoded = new BytesRef(new byte[Integer.BYTES]); |
1513 |
| - return new PointInSetQuery(field, 1, Integer.BYTES, new PointInSetQuery.Stream() { |
| 1518 | + static Query bitmapIndexQuery(String field, RoaringBitmap bitmap) { |
| 1519 | + return new Query() { |
1514 | 1520 |
|
1515 |
| - final Iterator<Integer> iterator = bitmap.iterator(); |
| 1521 | + @Override |
| 1522 | + public String toString(String field) { |
| 1523 | + return ""; |
| 1524 | + } |
1516 | 1525 |
|
1517 | 1526 | @Override
|
1518 |
| - public BytesRef next() { |
1519 |
| - int value; |
1520 |
| - if (iterator.hasNext()) { |
1521 |
| - value = iterator.next(); |
1522 |
| - } else { |
1523 |
| - return null; |
1524 |
| - } |
1525 |
| - IntPoint.encodeDimension(value, encoded.bytes, 0); |
1526 |
| - return encoded; |
| 1527 | + public void visit(QueryVisitor visitor) { |
| 1528 | + |
1527 | 1529 | }
|
1528 |
| - }) { |
| 1530 | + |
1529 | 1531 | @Override
|
1530 |
| - public Query rewrite(IndexSearcher indexSearcher) throws IOException { |
1531 |
| - if (bitmap.isEmpty()) { |
1532 |
| - return new MatchNoDocsQuery(); |
1533 |
| - } |
1534 |
| - return super.rewrite(indexSearcher); |
| 1532 | + public boolean equals(Object obj) { |
| 1533 | + return false; |
1535 | 1534 | }
|
1536 | 1535 |
|
1537 | 1536 | @Override
|
1538 |
| - protected String toString(byte[] value) { |
1539 |
| - assert value.length == Integer.BYTES; |
1540 |
| - return Integer.toString(IntPoint.decodeDimension(value, 0)); |
| 1537 | + public int hashCode() { |
| 1538 | + return 0; |
| 1539 | + } |
| 1540 | + |
| 1541 | + @Override |
| 1542 | + public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) { |
| 1543 | + return new ConstantScoreWeight(this, boost) { |
| 1544 | + @Override |
| 1545 | + public Scorer scorer(LeafReaderContext context) throws IOException { |
| 1546 | + return scorerSupplier(context).get(Long.MAX_VALUE); |
| 1547 | + } |
| 1548 | + |
| 1549 | + @Override |
| 1550 | + public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { |
| 1551 | + return new ScorerSupplier() { |
| 1552 | + @Override |
| 1553 | + public Scorer get(long leadCost) throws IOException { |
| 1554 | + |
| 1555 | + final BytesRef encoded = new BytesRef(new byte[Integer.BYTES]); |
| 1556 | + Query query = new PointInSetQuery(field, 1, Integer.BYTES, new PointInSetQuery.Stream() { |
| 1557 | + |
| 1558 | + final Iterator<Integer> iterator = bitmap.iterator(); |
| 1559 | + |
| 1560 | + @Override |
| 1561 | + public BytesRef next() { |
| 1562 | + int value; |
| 1563 | + if (iterator.hasNext()) { |
| 1564 | + value = iterator.next(); |
| 1565 | + } else { |
| 1566 | + return null; |
| 1567 | + } |
| 1568 | + IntPoint.encodeDimension(value, encoded.bytes, 0); |
| 1569 | + return encoded; |
| 1570 | + } |
| 1571 | + }) { |
| 1572 | + @Override |
| 1573 | + public Query rewrite(IndexSearcher indexSearcher) throws IOException { |
| 1574 | + if (bitmap.isEmpty()) { |
| 1575 | + return new MatchNoDocsQuery(); |
| 1576 | + } |
| 1577 | + return super.rewrite(indexSearcher); |
| 1578 | + } |
| 1579 | + |
| 1580 | + @Override |
| 1581 | + protected String toString(byte[] value) { |
| 1582 | + assert value.length == Integer.BYTES; |
| 1583 | + return Integer.toString(IntPoint.decodeDimension(value, 0)); |
| 1584 | + } |
| 1585 | + }; |
| 1586 | + return query.createWeight(searcher, scoreMode, boost).scorer(context); |
| 1587 | + } |
| 1588 | + |
| 1589 | + @Override |
| 1590 | + public long cost() { |
| 1591 | + return bitmap.getLongCardinality(); |
| 1592 | + } |
| 1593 | + }; |
| 1594 | + } |
| 1595 | + |
| 1596 | + @Override |
| 1597 | + public boolean isCacheable(LeafReaderContext ctx) { |
| 1598 | + return false; |
| 1599 | + } |
| 1600 | + }; |
1541 | 1601 | }
|
1542 | 1602 | };
|
1543 | 1603 | }
|
|
0 commit comments