Skip to content

Commit

Permalink
Fixing more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
  • Loading branch information
harshavamsi committed Nov 15, 2023
1 parent 443e205 commit 36708f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import org.apache.lucene.document.Document;
import org.apache.lucene.document.DoublePoint;
import org.apache.lucene.document.LongField;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.index.DirectoryReader;
Expand Down Expand Up @@ -78,7 +79,8 @@ public void testTermsQuery() {
long scaledValue1 = Math.round(value1 * ft.getScalingFactor());
double value2 = (randomDouble() * 2 - 1) * 10000;
long scaledValue2 = Math.round(value2 * ft.getScalingFactor());
assertEquals(LongPoint.newSetQuery("scaled_float", scaledValue1, scaledValue2), ft.termsQuery(Arrays.asList(value1, value2), null));
assertEquals(LongField.newSetQuery("scaled_float", scaledValue1, scaledValue2), ft.termsQuery(Arrays.asList(value1,
value2), null));
}

public void testRangeQuery() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.DoublePoint;
import org.apache.lucene.document.FloatPoint;
import org.apache.lucene.document.IntField;
import org.apache.lucene.document.IntPoint;
import org.apache.lucene.document.LongField;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.index.DirectoryReader;
Expand Down Expand Up @@ -118,15 +120,15 @@ public void testIsFieldWithinQuery() throws IOException {

public void testIntegerTermsQueryWithDecimalPart() {
MappedFieldType ft = new NumberFieldMapper.NumberFieldType("field", NumberType.INTEGER);
assertEquals(IntPoint.newSetQuery("field", 1), ft.termsQuery(Arrays.asList(1, 2.1), null));
assertEquals(IntPoint.newSetQuery("field", 1), ft.termsQuery(Arrays.asList(1.0, 2.1), null));
assertEquals(IntField.newSetQuery("field", 1), ft.termsQuery(Arrays.asList(1, 2.1), null));
assertEquals(IntField.newSetQuery("field", 1), ft.termsQuery(Arrays.asList(1.0, 2.1), null));
assertTrue(ft.termsQuery(Arrays.asList(1.1, 2.1), null) instanceof MatchNoDocsQuery);
}

public void testLongTermsQueryWithDecimalPart() {
MappedFieldType ft = new NumberFieldMapper.NumberFieldType("field", NumberType.LONG);
assertEquals(LongPoint.newSetQuery("field", 1), ft.termsQuery(Arrays.asList(1, 2.1), null));
assertEquals(LongPoint.newSetQuery("field", 1), ft.termsQuery(Arrays.asList(1.0, 2.1), null));
assertEquals(LongField.newSetQuery("field", 1), ft.termsQuery(Arrays.asList(1, 2.1), null));
assertEquals(LongField.newSetQuery("field", 1), ft.termsQuery(Arrays.asList(1.0, 2.1), null));
assertTrue(ft.termsQuery(Arrays.asList(1.1, 2.1), null) instanceof MatchNoDocsQuery);
}

Expand All @@ -151,16 +153,18 @@ public void testLongTermQueryWithDecimalPart() {
}

private static MappedFieldType unsearchable() {
return new NumberFieldType("field", NumberType.LONG, false, false, true, true, null, Collections.emptyMap());
return new NumberFieldType("field", NumberType.LONG, false, false, false, true, null, Collections.emptyMap());
}

public void testTermQuery() {
MappedFieldType ft = new NumberFieldMapper.NumberFieldType("field", NumberFieldMapper.NumberType.LONG);
assertEquals(LongPoint.newExactQuery("field", 42), ft.termQuery("42", null));
Query dvQuery = SortedNumericDocValuesField.newSlowExactQuery("field", 42);
Query query = new IndexOrDocValuesQuery(LongPoint.newExactQuery("field", 42), dvQuery);
assertEquals(query, ft.termQuery("42", null));

MappedFieldType unsearchable = unsearchable();
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> unsearchable.termQuery("42", null));
assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
assertEquals("Cannot search on field [field] since it is both not indexed, and does not have doc_values enabled.", e.getMessage());
}

public void testRangeQueryWithNegativeBounds() {
Expand Down Expand Up @@ -380,7 +384,7 @@ public void testLongRangeQuery() {
IllegalArgumentException.class,
() -> unsearchable.rangeQuery("1", "3", true, true, null, null, null, MOCK_QSC)
);
assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
assertEquals("Cannot search on field [field] since it is both not indexed, and does not have doc_values enabled.", e.getMessage());
}

public void testUnsignedLongRangeQuery() {
Expand All @@ -396,7 +400,7 @@ public void testUnsignedLongRangeQuery() {
IllegalArgumentException.class,
() -> unsearchable.rangeQuery("1", "3", true, true, null, null, null, MOCK_QSC)
);
assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
assertEquals("Cannot search on field [field] since it is both not indexed, and does not have doc_values enabled.", e.getMessage());
}

public void testDoubleRangeQuery() {
Expand All @@ -416,7 +420,7 @@ public void testDoubleRangeQuery() {
IllegalArgumentException.class,
() -> unsearchable.rangeQuery("1", "3", true, true, null, null, null, MOCK_QSC)
);
assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
assertEquals("Cannot search on field [field] since it is both not indexed, and does not have doc_values enabled.", e.getMessage());
}

public void testConversions() {
Expand Down

0 comments on commit 36708f8

Please sign in to comment.