Search in sources :

Example 1 with FieldAndFieldType

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);
}
Also used : FakeFieldType(org.elasticsearch.index.mapper.MockFieldMapper.FakeFieldType) Query(org.apache.lucene.search.Query) BlendedTermQuery(org.apache.lucene.queries.BlendedTermQuery) MultiPhrasePrefixQuery(org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) DisjunctionMaxQuery(org.apache.lucene.search.DisjunctionMaxQuery) TermQuery(org.apache.lucene.search.TermQuery) SynonymQuery(org.apache.lucene.search.SynonymQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) QueryBuilders.multiMatchQuery(org.elasticsearch.index.query.QueryBuilders.multiMatchQuery) FieldAndFieldType(org.elasticsearch.index.search.MultiMatchQuery.FieldAndFieldType) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) Term(org.apache.lucene.index.Term) BytesRef(org.apache.lucene.util.BytesRef)

Example 2 with FieldAndFieldType

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);
}
Also used : Query(org.apache.lucene.search.Query) BlendedTermQuery(org.apache.lucene.queries.BlendedTermQuery) MultiPhrasePrefixQuery(org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) DisjunctionMaxQuery(org.apache.lucene.search.DisjunctionMaxQuery) TermQuery(org.apache.lucene.search.TermQuery) SynonymQuery(org.apache.lucene.search.SynonymQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) QueryBuilders.multiMatchQuery(org.elasticsearch.index.query.QueryBuilders.multiMatchQuery) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) Term(org.apache.lucene.index.Term) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) BoostQuery(org.apache.lucene.search.BoostQuery) FakeFieldType(org.elasticsearch.index.mapper.MockFieldMapper.FakeFieldType) FieldAndFieldType(org.elasticsearch.index.search.MultiMatchQuery.FieldAndFieldType) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) BytesRef(org.apache.lucene.util.BytesRef)

Example 3 with FieldAndFieldType

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);
}
Also used : FakeFieldType(org.elasticsearch.index.mapper.MockFieldMapper.FakeFieldType) Query(org.apache.lucene.search.Query) BlendedTermQuery(org.apache.lucene.queries.BlendedTermQuery) MultiPhrasePrefixQuery(org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) DisjunctionMaxQuery(org.apache.lucene.search.DisjunctionMaxQuery) TermQuery(org.apache.lucene.search.TermQuery) SynonymQuery(org.apache.lucene.search.SynonymQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) QueryBuilders.multiMatchQuery(org.elasticsearch.index.query.QueryBuilders.multiMatchQuery) FieldAndFieldType(org.elasticsearch.index.search.MultiMatchQuery.FieldAndFieldType) Term(org.apache.lucene.index.Term) BytesRef(org.apache.lucene.util.BytesRef)

Example 4 with FieldAndFieldType

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);
}
Also used : FakeFieldType(org.elasticsearch.index.mapper.MockFieldMapper.FakeFieldType) Query(org.apache.lucene.search.Query) BlendedTermQuery(org.apache.lucene.queries.BlendedTermQuery) MultiPhrasePrefixQuery(org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) DisjunctionMaxQuery(org.apache.lucene.search.DisjunctionMaxQuery) TermQuery(org.apache.lucene.search.TermQuery) SynonymQuery(org.apache.lucene.search.SynonymQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) QueryBuilders.multiMatchQuery(org.elasticsearch.index.query.QueryBuilders.multiMatchQuery) FieldAndFieldType(org.elasticsearch.index.search.MultiMatchQuery.FieldAndFieldType) Term(org.apache.lucene.index.Term) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

Term (org.apache.lucene.index.Term)4 BlendedTermQuery (org.apache.lucene.queries.BlendedTermQuery)4 BooleanQuery (org.apache.lucene.search.BooleanQuery)4 BoostQuery (org.apache.lucene.search.BoostQuery)4 DisjunctionMaxQuery (org.apache.lucene.search.DisjunctionMaxQuery)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)4 Query (org.apache.lucene.search.Query)4 SynonymQuery (org.apache.lucene.search.SynonymQuery)4 TermQuery (org.apache.lucene.search.TermQuery)4 BytesRef (org.apache.lucene.util.BytesRef)4 MultiPhrasePrefixQuery (org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery)4 FakeFieldType (org.elasticsearch.index.mapper.MockFieldMapper.FakeFieldType)4 QueryBuilders.multiMatchQuery (org.elasticsearch.index.query.QueryBuilders.multiMatchQuery)4 FieldAndFieldType (org.elasticsearch.index.search.MultiMatchQuery.FieldAndFieldType)4 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)2 MultiMatchQueryBuilder (org.elasticsearch.index.query.MultiMatchQueryBuilder)1