Skip to content

Commit

Permalink
Fix spotless + precommit failure
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
  • Loading branch information
harshavamsi committed Jan 24, 2024
1 parent c4da6ed commit 802c462
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,20 @@ public Query termQuery(Object value, @Nullable QueryShardContext context) {
}
if (isSearchable() && hasDocValues()) {
String term = value.toString();
if (value instanceof String)
value = new BytesRef(((String) value).getBytes());
if (value instanceof String) value = new BytesRef(((String) value));
if (term.contains("/")) {
final Tuple<InetAddress, Integer> cidr = InetAddresses.parseCidr(term);
return InetAddressPoint.newPrefixQuery(name(), cidr.v1(), cidr.v2());
}
return new IndexOrDocValuesQuery(query, SortedSetDocValuesField.newSlowExactQuery(name(), (BytesRef)(value)));
return new IndexOrDocValuesQuery(query, SortedSetDocValuesField.newSlowExactQuery(name(), (BytesRef) (value)));
}
if (hasDocValues()) {
String term = value.toString();
if (value instanceof String) value = new BytesRef(((String) value));
if (term.contains("/")) {
final Tuple<InetAddress, Integer> cidr = InetAddresses.parseCidr(term);
return InetAddressPoint.newPrefixQuery(name(), cidr.v1(), cidr.v2());
}
return SortedSetDocValuesField.newSlowExactQuery(name(), ((BytesRef) value));
}
return query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,27 @@ public void testTermQuery() {
Query query = InetAddressPoint.newExactQuery("field", InetAddresses.forString(ip));

assertEquals(
new IndexOrDocValuesQuery(
query,
SortedSetDocValuesField.newSlowExactQuery("field", new BytesRef(ip))
),
new IndexOrDocValuesQuery(query, SortedSetDocValuesField.newSlowExactQuery("field", new BytesRef(ip))),
ft.termQuery(ip, null)
);

ip = "192.168.1.7";
query = InetAddressPoint.newExactQuery("field", InetAddresses.forString(ip));
assertEquals(
new IndexOrDocValuesQuery(
query,
SortedSetDocValuesField.newSlowExactQuery("field", new BytesRef(ip))
),
new IndexOrDocValuesQuery(query, SortedSetDocValuesField.newSlowExactQuery("field", new BytesRef(ip))),
ft.termQuery(ip, null)
);

ip = "2001:db8::2:1";
String prefix = ip + "/64";

query = InetAddressPoint.newPrefixQuery("field", InetAddresses.forString(ip), 64);
assertEquals(
query,
ft.termQuery(prefix, null)
);
assertEquals(query, ft.termQuery(prefix, null));

ip = "192.168.1.7";
prefix = ip + "/16";
query = InetAddressPoint.newPrefixQuery("field", InetAddresses.forString(ip), 16);
assertEquals(
query,
ft.termQuery(prefix, null)
);
assertEquals(query, ft.termQuery(prefix, null));

MappedFieldType unsearchable = new IpFieldMapper.IpFieldType("field", false, false, false, null, Collections.emptyMap());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> unsearchable.termQuery("::1", null));
Expand Down

0 comments on commit 802c462

Please sign in to comment.