use of org.elasticsearch.index.search.MultiMatchQuery.FieldAndFieldType in project elasticsearch by elastic.
the class MultiMatchQueryTests method testBlendTermsUnsupportedValue.
public void testBlendTermsUnsupportedValue() {
FakeFieldType ft1 = new FakeFieldType();
ft1.setName("foo");
FakeFieldType ft2 = new FakeFieldType() {
@Override
public Query termQuery(Object value, QueryShardContext context) {
throw new IllegalArgumentException();
}
};
ft2.setName("bar");
Term[] terms = new Term[] { new Term("foo", "baz") };
float[] boosts = new float[] { 2 };
Query expected = BlendedTermQuery.booleanBlendedQuery(terms, boosts, false);
Query actual = MultiMatchQuery.blendTerm(indexService.newQueryShardContext(randomInt(20), null, () -> {
throw new UnsupportedOperationException();
}), new BytesRef("baz"), null, 1f, new FieldAndFieldType(ft1, 2), new FieldAndFieldType(ft2, 3));
assertEquals(expected, actual);
}
use of org.elasticsearch.index.search.MultiMatchQuery.FieldAndFieldType in project elasticsearch by elastic.
the class MultiMatchQueryTests method testBlendNoTermQuery.
public void testBlendNoTermQuery() {
FakeFieldType ft1 = new FakeFieldType();
ft1.setName("foo");
FakeFieldType ft2 = new FakeFieldType() {
@Override
public Query termQuery(Object value, QueryShardContext context) {
return new MatchAllDocsQuery();
}
};
ft2.setName("bar");
Term[] terms = new Term[] { new Term("foo", "baz") };
float[] boosts = new float[] { 2 };
Query expectedClause1 = BlendedTermQuery.booleanBlendedQuery(terms, boosts, false);
Query expectedClause2 = new BoostQuery(new MatchAllDocsQuery(), 3);
Query expected = new BooleanQuery.Builder().setDisableCoord(true).add(expectedClause1, Occur.SHOULD).add(expectedClause2, Occur.SHOULD).build();
Query actual = MultiMatchQuery.blendTerm(indexService.newQueryShardContext(randomInt(20), null, () -> {
throw new UnsupportedOperationException();
}), new BytesRef("baz"), null, 1f, new FieldAndFieldType(ft1, 2), new FieldAndFieldType(ft2, 3));
assertEquals(expected, actual);
}
use of org.elasticsearch.index.search.MultiMatchQuery.FieldAndFieldType in project elasticsearch by elastic.
the class MultiMatchQueryTests method testBlendTermsWithFieldBoosts.
public void testBlendTermsWithFieldBoosts() {
FakeFieldType ft1 = new FakeFieldType();
ft1.setName("foo");
ft1.setBoost(100);
FakeFieldType ft2 = new FakeFieldType();
ft2.setName("bar");
ft2.setBoost(10);
Term[] terms = new Term[] { new Term("foo", "baz"), new Term("bar", "baz") };
float[] boosts = new float[] { 200, 30 };
Query expected = BlendedTermQuery.booleanBlendedQuery(terms, boosts, false);
Query actual = MultiMatchQuery.blendTerm(indexService.newQueryShardContext(randomInt(20), null, () -> {
throw new UnsupportedOperationException();
}), new BytesRef("baz"), null, 1f, new FieldAndFieldType(ft1, 2), new FieldAndFieldType(ft2, 3));
assertEquals(expected, actual);
}
use of org.elasticsearch.index.search.MultiMatchQuery.FieldAndFieldType in project elasticsearch by elastic.
the class MultiMatchQueryTests method testBlendTerms.
public void testBlendTerms() {
FakeFieldType ft1 = new FakeFieldType();
ft1.setName("foo");
FakeFieldType ft2 = new FakeFieldType();
ft2.setName("bar");
Term[] terms = new Term[] { new Term("foo", "baz"), new Term("bar", "baz") };
float[] boosts = new float[] { 2, 3 };
Query expected = BlendedTermQuery.booleanBlendedQuery(terms, boosts, false);
Query actual = MultiMatchQuery.blendTerm(indexService.newQueryShardContext(randomInt(20), null, () -> {
throw new UnsupportedOperationException();
}), new BytesRef("baz"), null, 1f, new FieldAndFieldType(ft1, 2), new FieldAndFieldType(ft2, 3));
assertEquals(expected, actual);
}
Aggregations