@Override public Query rewrite(IndexReader reader) throws IOException { final SpanQuery rewritten = (SpanQuery) query.rewrite(reader); if (getBoost() == 1f) { return rewritten; } if (rewritten.getClass() == SpanBoostQuery.class) { SpanBoostQuery in = (SpanBoostQuery) rewritten; return new SpanBoostQuery(in.query, getBoost() * in.getBoost()); } if (query != rewritten) { return new SpanBoostQuery(rewritten, getBoost()); } return this; }
@Override public void normalize(float norm, float boost) { weight.normalize(norm, SpanBoostQuery.this.getBoost() * boost); }
@Override public Query rewrite(IndexReader reader) throws IOException { final SpanQuery rewritten = (SpanQuery) query.rewrite(reader); if (getBoost() == 1f) { return rewritten; } if (rewritten.getClass() == SpanBoostQuery.class) { SpanBoostQuery in = (SpanBoostQuery) rewritten; return new SpanBoostQuery(in.query, getBoost() * in.getBoost()); } if (query != rewritten) { return new SpanBoostQuery(rewritten, getBoost()); } return this; }
@Override public void normalize(float norm, float boost) { weight.normalize(norm, SpanBoostQuery.this.getBoost() * boost); }
@Override public String toString(String field) { boolean needsParens = NO_PARENS_REQUIRED_QUERIES.contains(query.getClass()) == false; StringBuilder builder = new StringBuilder(); if (needsParens) { builder.append("("); } builder.append(query.toString(field)); if (needsParens) { builder.append(")"); } builder.append("^"); builder.append(getBoost()); return builder.toString(); }
@Override public String toString(String field) { boolean needsParens = NO_PARENS_REQUIRED_QUERIES.contains(query.getClass()) == false; StringBuilder builder = new StringBuilder(); if (needsParens) { builder.append("("); } builder.append(query.toString(field)); if (needsParens) { builder.append(")"); } builder.append("^"); builder.append(getBoost()); return builder.toString(); }
public void addSpanQuery(Query q) { if (q.getClass() == MatchNoDocsQuery.class) return; if (! (q instanceof SpanQuery)) throw new AssertionError("Expected SpanQuery: " + q.toString(getFieldName())); float boost = 1f; if (q instanceof SpanBoostQuery) { SpanBoostQuery bq = (SpanBoostQuery) q; boost = bq.getBoost(); q = bq.getQuery(); } addSpanQueryWeighted((SpanQuery)q, boost); }
public void addSpanQuery(Query q) { if (q.getClass() == MatchNoDocsQuery.class) return; if (! (q instanceof SpanQuery)) throw new AssertionError("Expected SpanQuery: " + q.toString(getFieldName())); float boost = 1f; if (q instanceof SpanBoostQuery) { SpanBoostQuery bq = (SpanBoostQuery) q; boost = bq.getBoost(); q = bq.getQuery(); } addSpanQueryWeighted((SpanQuery)q, boost); }
weight.normalize(1f, getBoost()); return new SpanWeight(this, searcher, terms) {
weight.normalize(1f, getBoost()); return new SpanWeight(this, searcher, terms) {
/** * 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); }