@@ -181,8 +181,19 @@ private static MappedFieldType unsearchable() {
181
181
public void testTermQuery () {
182
182
MappedFieldType ft = new NumberFieldMapper .NumberFieldType ("field" , NumberFieldMapper .NumberType .LONG );
183
183
Query dvQuery = SortedNumericDocValuesField .newSlowExactQuery ("field" , 42 );
184
- Query query = new IndexOrDocValuesQuery (LongPoint .newExactQuery ("field" , 42 ), dvQuery );
185
- assertEquals (query , ft .termQuery ("42" , null ));
184
+ Query pointQuery = LongPoint .newExactQuery ("field" , 42 );
185
+ Query indexOrDocValuesQuery = new IndexOrDocValuesQuery (pointQuery , dvQuery );
186
+ Query approximateQuery = new ApproximateScoreQuery (
187
+ indexOrDocValuesQuery ,
188
+ new ApproximatePointRangeQuery (
189
+ "field" ,
190
+ LongPoint .pack (new long [] { 42 }).bytes ,
191
+ LongPoint .pack (new long [] { 42 }).bytes ,
192
+ 1 ,
193
+ ApproximatePointRangeQuery .LONG_FORMAT
194
+ )
195
+ );
196
+ assertEquals (approximateQuery , ft .termQuery ("42" , null ));
186
197
187
198
MappedFieldType unsearchable = unsearchable ();
188
199
IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () -> unsearchable .termQuery ("42" , null ));
@@ -621,10 +632,26 @@ public void testNegativeZero() {
621
632
NumberType .HALF_FLOAT .rangeQuery ("field" , null , +0f , true , false , false , true , MOCK_QSC )
622
633
);
623
634
624
- assertFalse (NumberType .DOUBLE .termQuery ("field" , -0d , true , true ).equals (NumberType .DOUBLE .termQuery ("field" , +0d , true , true )));
625
- assertFalse (NumberType .FLOAT .termQuery ("field" , -0f , true , true ).equals (NumberType .FLOAT .termQuery ("field" , +0f , true , true )));
635
+ // For term queries, we need to extract the original query from the ApproximateScoreQuery
636
+ Query negativeZeroDouble = NumberType .DOUBLE .termQuery ("field" , -0d , true , true );
637
+ Query positiveZeroDouble = NumberType .DOUBLE .termQuery ("field" , +0d , true , true );
638
+ assertFalse (
639
+ ((ApproximateScoreQuery ) negativeZeroDouble ).getOriginalQuery ()
640
+ .equals (((ApproximateScoreQuery ) positiveZeroDouble ).getOriginalQuery ())
641
+ );
642
+
643
+ Query negativeZeroFloat = NumberType .FLOAT .termQuery ("field" , -0f , true , true );
644
+ Query positiveZeroFloat = NumberType .FLOAT .termQuery ("field" , +0f , true , true );
645
+ assertFalse (
646
+ ((ApproximateScoreQuery ) negativeZeroFloat ).getOriginalQuery ()
647
+ .equals (((ApproximateScoreQuery ) positiveZeroFloat ).getOriginalQuery ())
648
+ );
649
+
650
+ Query negativeZeroHalfFloat = NumberType .HALF_FLOAT .termQuery ("field" , -0f , true , true );
651
+ Query positiveZeroHalfFloat = NumberType .HALF_FLOAT .termQuery ("field" , +0f , true , true );
626
652
assertFalse (
627
- NumberType .HALF_FLOAT .termQuery ("field" , -0f , true , true ).equals (NumberType .HALF_FLOAT .termQuery ("field" , +0f , true , true ))
653
+ ((ApproximateScoreQuery ) negativeZeroHalfFloat ).getOriginalQuery ()
654
+ .equals (((ApproximateScoreQuery ) positiveZeroHalfFloat ).getOriginalQuery ())
628
655
);
629
656
}
630
657
0 commit comments