use of org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude in project elasticsearch by elastic.
the class IncludeExcludeTests method testExactExcludeValuesEquals.
public void testExactExcludeValuesEquals() throws IOException {
String[] excValues = { "a", "b" };
String[] differentExcValues = { "a", "c" };
IncludeExclude serialized = serialize(new IncludeExclude(null, excValues), IncludeExclude.EXCLUDE_FIELD);
assertFalse(serialized.isPartitionBased());
assertFalse(serialized.isRegexBased());
IncludeExclude same = new IncludeExclude(null, excValues);
assertEquals(serialized, same);
assertEquals(serialized.hashCode(), same.hashCode());
IncludeExclude different = new IncludeExclude(null, differentExcValues);
assertFalse(serialized.equals(different));
assertTrue(serialized.hashCode() != different.hashCode());
}
use of org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude in project elasticsearch by elastic.
the class IncludeExcludeTests method serializeMixedRegex.
// Serializes/deserializes the IncludeExclude statement with include AND
// exclude clauses
private IncludeExclude serializeMixedRegex(IncludeExclude incExc) throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
if (randomBoolean()) {
builder.prettyPrint();
}
builder.startObject();
incExc.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
XContentParser parser = createParser(builder);
QueryParseContext parseContext = new QueryParseContext(parser);
XContentParser.Token token = parser.nextToken();
assertEquals(token, XContentParser.Token.START_OBJECT);
IncludeExclude inc = null;
IncludeExclude exc = null;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
assertEquals(XContentParser.Token.FIELD_NAME, token);
if (IncludeExclude.INCLUDE_FIELD.match(parser.currentName())) {
token = parser.nextToken();
inc = IncludeExclude.parseInclude(parser, parseContext);
} else if (IncludeExclude.EXCLUDE_FIELD.match(parser.currentName())) {
token = parser.nextToken();
exc = IncludeExclude.parseExclude(parser, parseContext);
} else {
throw new IllegalArgumentException("Unexpected field name serialized in test: " + parser.currentName());
}
}
assertNotNull(inc);
assertNotNull(exc);
// Include and Exclude clauses are parsed independently and then merged
return IncludeExclude.merge(inc, exc);
}
use of org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude in project elasticsearch by elastic.
the class IncludeExcludeTests method testSingleTermWithOrds.
public void testSingleTermWithOrds() throws IOException {
RandomAccessOrds ords = new RandomAccessOrds() {
boolean consumed = true;
@Override
public void setDocument(int docID) {
consumed = false;
}
@Override
public long nextOrd() {
if (consumed) {
return SortedSetDocValues.NO_MORE_ORDS;
} else {
consumed = true;
return 0;
}
}
@Override
public BytesRef lookupOrd(long ord) {
assertEquals(0, ord);
return new BytesRef("foo");
}
@Override
public long getValueCount() {
return 1;
}
@Override
public long ordAt(int index) {
return 0;
}
@Override
public int cardinality() {
return 1;
}
};
IncludeExclude inexcl = new IncludeExclude(new TreeSet<>(Collections.singleton(new BytesRef("foo"))), null);
OrdinalsFilter filter = inexcl.convertToOrdinalsFilter(DocValueFormat.RAW);
LongBitSet acceptedOrds = filter.acceptedGlobalOrdinals(ords);
assertEquals(1, acceptedOrds.length());
assertTrue(acceptedOrds.get(0));
inexcl = new IncludeExclude(new TreeSet<>(Collections.singleton(new BytesRef("bar"))), null);
filter = inexcl.convertToOrdinalsFilter(DocValueFormat.RAW);
acceptedOrds = filter.acceptedGlobalOrdinals(ords);
assertEquals(1, acceptedOrds.length());
assertFalse(acceptedOrds.get(0));
inexcl = new IncludeExclude(new TreeSet<>(Collections.singleton(new BytesRef("foo"))), new TreeSet<>(Collections.singleton(new BytesRef("foo"))));
filter = inexcl.convertToOrdinalsFilter(DocValueFormat.RAW);
acceptedOrds = filter.acceptedGlobalOrdinals(ords);
assertEquals(1, acceptedOrds.length());
assertFalse(acceptedOrds.get(0));
inexcl = new IncludeExclude(// means everything included
null, new TreeSet<>(Collections.singleton(new BytesRef("foo"))));
filter = inexcl.convertToOrdinalsFilter(DocValueFormat.RAW);
acceptedOrds = filter.acceptedGlobalOrdinals(ords);
assertEquals(1, acceptedOrds.length());
assertFalse(acceptedOrds.get(0));
}
use of org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude in project elasticsearch by elastic.
the class IncludeExcludeTests method testRegexIncludeAndExclude.
public void testRegexIncludeAndExclude() throws IOException {
String incRegex = "foo.*";
String excRegex = "football";
String differentExcRegex = "foosball";
IncludeExclude serialized = serializeMixedRegex(new IncludeExclude(incRegex, excRegex));
assertFalse(serialized.isPartitionBased());
assertTrue(serialized.isRegexBased());
IncludeExclude same = new IncludeExclude(incRegex, excRegex);
assertEquals(serialized, same);
assertEquals(serialized.hashCode(), same.hashCode());
IncludeExclude different = new IncludeExclude(incRegex, differentExcRegex);
assertFalse(serialized.equals(different));
assertTrue(serialized.hashCode() != different.hashCode());
}
use of org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude in project elasticsearch by elastic.
the class IncludeExcludeTests method testExactIncludeValuesEquals.
public void testExactIncludeValuesEquals() throws IOException {
String[] incValues = { "a", "b" };
String[] differentIncValues = { "a", "c" };
IncludeExclude serialized = serialize(new IncludeExclude(incValues, null), IncludeExclude.INCLUDE_FIELD);
assertFalse(serialized.isPartitionBased());
assertFalse(serialized.isRegexBased());
IncludeExclude same = new IncludeExclude(incValues, null);
assertEquals(serialized, same);
assertEquals(serialized.hashCode(), same.hashCode());
IncludeExclude different = new IncludeExclude(differentIncValues, null);
assertFalse(serialized.equals(different));
assertTrue(serialized.hashCode() != different.hashCode());
}
Aggregations