Search in sources :

Example 11 with QueryShardContext

use of org.opensearch.index.query.QueryShardContext in project OpenSearch by opensearch-project.

the class HasChildQueryBuilderTests method testNonDefaultSimilarity.

public void testNonDefaultSimilarity() throws Exception {
    QueryShardContext shardContext = createShardContext();
    HasChildQueryBuilder hasChildQueryBuilder = hasChildQuery(CHILD_DOC, new TermQueryBuilder("custom_string", "value"), ScoreMode.None);
    HasChildQueryBuilder.LateParsingQuery query = (HasChildQueryBuilder.LateParsingQuery) hasChildQueryBuilder.toQuery(shardContext);
    Similarity expected = SimilarityService.BUILT_IN.get(similarity).apply(Settings.EMPTY, Version.CURRENT, null);
    assertThat(((PerFieldSimilarityWrapper) query.getSimilarity()).get("custom_string"), instanceOf(expected.getClass()));
}
Also used : Similarity(org.apache.lucene.search.similarities.Similarity) QueryShardContext(org.opensearch.index.query.QueryShardContext) TermQueryBuilder(org.opensearch.index.query.TermQueryBuilder)

Example 12 with QueryShardContext

use of org.opensearch.index.query.QueryShardContext in project OpenSearch by opensearch-project.

the class ParentIdQueryBuilderTests method testDisallowExpensiveQueries.

public void testDisallowExpensiveQueries() {
    QueryShardContext queryShardContext = mock(QueryShardContext.class);
    when(queryShardContext.allowExpensiveQueries()).thenReturn(false);
    ParentIdQueryBuilder queryBuilder = doCreateTestQueryBuilder();
    OpenSearchException e = expectThrows(OpenSearchException.class, () -> queryBuilder.toQuery(queryShardContext));
    assertEquals("[joining] queries cannot be executed when 'search.allow_expensive_queries' is set to false.", e.getMessage());
}
Also used : QueryShardContext(org.opensearch.index.query.QueryShardContext) OpenSearchException(org.opensearch.OpenSearchException)

Example 13 with QueryShardContext

use of org.opensearch.index.query.QueryShardContext in project OpenSearch by opensearch-project.

the class HasChildQueryBuilderTests method testDisallowExpensiveQueries.

public void testDisallowExpensiveQueries() {
    QueryShardContext queryShardContext = mock(QueryShardContext.class);
    when(queryShardContext.allowExpensiveQueries()).thenReturn(false);
    HasChildQueryBuilder queryBuilder = hasChildQuery(CHILD_DOC, new TermQueryBuilder("custom_string", "value"), ScoreMode.None);
    OpenSearchException e = expectThrows(OpenSearchException.class, () -> queryBuilder.toQuery(queryShardContext));
    assertEquals("[joining] queries cannot be executed when 'search.allow_expensive_queries' is set to false.", e.getMessage());
}
Also used : QueryShardContext(org.opensearch.index.query.QueryShardContext) OpenSearchException(org.opensearch.OpenSearchException) TermQueryBuilder(org.opensearch.index.query.TermQueryBuilder)

Example 14 with QueryShardContext

use of org.opensearch.index.query.QueryShardContext in project OpenSearch by opensearch-project.

the class HasParentQueryBuilderTests method testIgnoreUnmappedWithRewrite.

public void testIgnoreUnmappedWithRewrite() throws IOException {
    // WrapperQueryBuilder makes sure we always rewrite
    final HasParentQueryBuilder queryBuilder = new HasParentQueryBuilder("unmapped", new WrapperQueryBuilder(new MatchAllQueryBuilder().toString()), false);
    queryBuilder.ignoreUnmapped(true);
    QueryShardContext queryShardContext = createShardContext();
    Query query = queryBuilder.rewrite(queryShardContext).toQuery(queryShardContext);
    assertThat(query, notNullValue());
    assertThat(query, instanceOf(MatchNoDocsQuery.class));
}
Also used : Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) JoinQueryBuilders.hasParentQuery(org.opensearch.join.query.JoinQueryBuilders.hasParentQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) QueryShardContext(org.opensearch.index.query.QueryShardContext) WrapperQueryBuilder(org.opensearch.index.query.WrapperQueryBuilder) MatchAllQueryBuilder(org.opensearch.index.query.MatchAllQueryBuilder)

Example 15 with QueryShardContext

use of org.opensearch.index.query.QueryShardContext in project OpenSearch by opensearch-project.

the class HasParentQueryBuilderTests method testToQueryInnerQueryType.

public void testToQueryInnerQueryType() throws IOException {
    QueryShardContext shardContext = createShardContext();
    HasParentQueryBuilder hasParentQueryBuilder = new HasParentQueryBuilder(PARENT_DOC, new IdsQueryBuilder().addIds("id"), false);
    Query query = hasParentQueryBuilder.toQuery(shardContext);
    HasChildQueryBuilderTests.assertLateParsingQuery(query, PARENT_DOC, "id");
}
Also used : IdsQueryBuilder(org.opensearch.index.query.IdsQueryBuilder) Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) JoinQueryBuilders.hasParentQuery(org.opensearch.join.query.JoinQueryBuilders.hasParentQuery) QueryShardContext(org.opensearch.index.query.QueryShardContext)

Aggregations

QueryShardContext (org.opensearch.index.query.QueryShardContext)131 Query (org.apache.lucene.search.Query)46 QueryBuilder (org.opensearch.index.query.QueryBuilder)29 TermQuery (org.apache.lucene.search.TermQuery)27 IndexSettings (org.opensearch.index.IndexSettings)25 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)23 Settings (org.opensearch.common.settings.Settings)22 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)21 IndexService (org.opensearch.index.IndexService)20 Term (org.apache.lucene.index.Term)17 BooleanQuery (org.apache.lucene.search.BooleanQuery)17 Directory (org.apache.lucene.store.Directory)17 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)17 Engine (org.opensearch.index.engine.Engine)17 BytesRef (org.apache.lucene.util.BytesRef)16 MatchAllQueryBuilder (org.opensearch.index.query.MatchAllQueryBuilder)16 SortField (org.apache.lucene.search.SortField)15 IndexSearcher (org.apache.lucene.search.IndexSearcher)14 IndexReader (org.apache.lucene.index.IndexReader)13 Matchers.containsString (org.hamcrest.Matchers.containsString)13