/** * Checks the result of {@link QueryBuilder#toQuery(QueryShardContext)} given the original {@link QueryBuilder} * and {@link QueryShardContext}. Verifies that named queries and boost are properly handled and delegates to * {@link #doAssertLuceneQuery(AbstractQueryBuilder, Query, SearchContext)} for query specific checks. */ private void assertLuceneQuery(QB queryBuilder, Query query, SearchContext context) throws IOException { if (queryBuilder.queryName() != null) { Query namedQuery = context.getQueryShardContext().copyNamedQueries().get(queryBuilder.queryName()); assertThat(namedQuery, equalTo(query)); } if (query != null) { if (queryBuilder.boost() != AbstractQueryBuilder.DEFAULT_BOOST) { assertThat(query, either(instanceOf(BoostQuery.class)).or(instanceOf(SpanBoostQuery.class))); if (query instanceof SpanBoostQuery) { SpanBoostQuery spanBoostQuery = (SpanBoostQuery) query; assertThat(spanBoostQuery.getBoost(), equalTo(queryBuilder.boost())); query = spanBoostQuery.getQuery(); } else { BoostQuery boostQuery = (BoostQuery) query; assertThat(boostQuery.getBoost(), equalTo(queryBuilder.boost())); query = boostQuery.getQuery(); } } } doAssertLuceneQuery(queryBuilder, query, context); }
float getBoost(Query q) { if (q instanceof BoostQuery) { return ((BoostQuery)q).getBoost(); } else if (q instanceof SpanBoostQuery) { return ((SpanBoostQuery)q).getBoost(); } return 1.0f; }
private Float getBoost(Query q) { if (q instanceof BoostQuery) { return ((BoostQuery)q).getBoost(); } else if (q instanceof SpanBoostQuery) { return ((SpanBoostQuery)q).getBoost(); } return 1.0f; }