adapt to upstream lucene changes
This commit is contained in:
parent
e522458735
commit
79c58a122e
|
@ -82,14 +82,6 @@ public class SpanContainingQueryBuilder extends AbstractQueryBuilder<SpanContain
|
||||||
return new SpanContainingQuery((SpanQuery) innerBig, (SpanQuery) innerLittle);
|
return new SpanContainingQuery((SpanQuery) innerBig, (SpanQuery) innerLittle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setFinalBoost(Query query) {
|
|
||||||
if (boost != AbstractQueryBuilder.DEFAULT_BOOST) {
|
|
||||||
//preserve potential inner boost coming from lucene (default is big.boost)
|
|
||||||
query.setBoost(boost);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryValidationException validate() {
|
public QueryValidationException validate() {
|
||||||
QueryValidationException validationException = null;
|
QueryValidationException validationException = null;
|
||||||
|
|
|
@ -87,14 +87,6 @@ public class SpanWithinQueryBuilder extends AbstractQueryBuilder<SpanWithinQuery
|
||||||
return new SpanWithinQuery((SpanQuery) innerBig, (SpanQuery) innerLittle);
|
return new SpanWithinQuery((SpanQuery) innerBig, (SpanQuery) innerLittle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setFinalBoost(Query query) {
|
|
||||||
if (boost != AbstractQueryBuilder.DEFAULT_BOOST) {
|
|
||||||
//preserve potential inner boost coming from lucene (default is little.boost)
|
|
||||||
query.setBoost(boost);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryValidationException validate() {
|
public QueryValidationException validate() {
|
||||||
QueryValidationException validationException = null;
|
QueryValidationException validationException = null;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.search.*;
|
import org.apache.lucene.search.*;
|
||||||
import org.apache.lucene.util.automaton.TooComplexToDeterminizeException;
|
import org.apache.lucene.util.automaton.TooComplexToDeterminizeException;
|
||||||
import org.elasticsearch.common.lucene.all.AllTermQuery;
|
import org.elasticsearch.common.lucene.all.AllTermQuery;
|
||||||
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -189,24 +190,34 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
||||||
QueryShardContext shardContext = createShardContext();
|
QueryShardContext shardContext = createShardContext();
|
||||||
QueryStringQueryBuilder queryStringQuery = queryStringQuery(STRING_FIELD_NAME + ":boosted^2");
|
QueryStringQueryBuilder queryStringQuery = queryStringQuery(STRING_FIELD_NAME + ":boosted^2");
|
||||||
Query query = queryStringQuery.toQuery(shardContext);
|
Query query = queryStringQuery.toQuery(shardContext);
|
||||||
assertThat(query, instanceOf(TermQuery.class));
|
assertThat(query, instanceOf(BoostQuery.class));
|
||||||
assertThat(((TermQuery) query).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "boosted")));
|
BoostQuery boostQuery = (BoostQuery) query;
|
||||||
assertThat(query.getBoost(), equalTo(2.0f));
|
assertThat(boostQuery.getBoost(), Matchers.equalTo(2.0f));
|
||||||
|
assertThat(boostQuery.getQuery(), instanceOf(TermQuery.class));
|
||||||
|
assertThat(((TermQuery) boostQuery.getQuery()).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "boosted")));
|
||||||
queryStringQuery.boost(2.0f);
|
queryStringQuery.boost(2.0f);
|
||||||
query = queryStringQuery.toQuery(shardContext);
|
query = queryStringQuery.toQuery(shardContext);
|
||||||
assertThat(query.getBoost(), equalTo(4.0f));
|
assertThat(query, instanceOf(BoostQuery.class));
|
||||||
|
assertThat(((BoostQuery) query).getBoost(), Matchers.equalTo(4.0f));
|
||||||
|
|
||||||
queryStringQuery = queryStringQuery("((" + STRING_FIELD_NAME + ":boosted^2) AND (" + STRING_FIELD_NAME + ":foo^1.5))^3");
|
queryStringQuery = queryStringQuery("((" + STRING_FIELD_NAME + ":boosted^2) AND (" + STRING_FIELD_NAME + ":foo^1.5))^3");
|
||||||
query = queryStringQuery.toQuery(shardContext);
|
query = queryStringQuery.toQuery(shardContext);
|
||||||
assertThat(query, instanceOf(BooleanQuery.class));
|
assertThat(query, instanceOf(BoostQuery.class));
|
||||||
assertThat(assertBooleanSubQuery(query, TermQuery.class, 0).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "boosted")));
|
boostQuery = (BoostQuery) query;
|
||||||
assertThat(assertBooleanSubQuery(query, TermQuery.class, 0).getBoost(), equalTo(2.0f));
|
assertThat(boostQuery.getBoost(), equalTo(3.0f));
|
||||||
assertThat(assertBooleanSubQuery(query, TermQuery.class, 1).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "foo")));
|
BoostQuery boostQuery1 = assertBooleanSubQuery(boostQuery.getQuery(), BoostQuery.class, 0);
|
||||||
assertThat(assertBooleanSubQuery(query, TermQuery.class, 1).getBoost(), equalTo(1.5f));
|
assertThat(boostQuery1.getBoost(), equalTo(2.0f));
|
||||||
assertThat(query.getBoost(), equalTo(3.0f));
|
assertThat(boostQuery1.getQuery(), instanceOf(TermQuery.class));
|
||||||
|
assertThat(((TermQuery)boostQuery1.getQuery()).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "boosted")));
|
||||||
|
BoostQuery boostQuery2 = assertBooleanSubQuery(boostQuery.getQuery(), BoostQuery.class, 1);
|
||||||
|
assertThat(boostQuery2.getBoost(), equalTo(1.5f));
|
||||||
|
assertThat(boostQuery2.getQuery(), instanceOf(TermQuery.class));
|
||||||
|
assertThat(((TermQuery)boostQuery2.getQuery()).getTerm(), equalTo(new Term(STRING_FIELD_NAME, "foo")));
|
||||||
queryStringQuery.boost(2.0f);
|
queryStringQuery.boost(2.0f);
|
||||||
query = queryStringQuery.toQuery(shardContext);
|
query = queryStringQuery.toQuery(shardContext);
|
||||||
assertThat(query.getBoost(), equalTo(6.0f));
|
assertThat(query, instanceOf(BoostQuery.class));
|
||||||
|
boostQuery = (BoostQuery) query;
|
||||||
|
assertThat(boostQuery.getBoost(), equalTo(6.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
|
|
||||||
public class SpanContainingQueryBuilderTests extends AbstractQueryTestCase<SpanContainingQueryBuilder> {
|
public class SpanContainingQueryBuilderTests extends AbstractQueryTestCase<SpanContainingQueryBuilder> {
|
||||||
|
@ -41,16 +40,6 @@ public class SpanContainingQueryBuilderTests extends AbstractQueryTestCase<SpanC
|
||||||
assertThat(query, instanceOf(SpanContainingQuery.class));
|
assertThat(query, instanceOf(SpanContainingQuery.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void assertBoost(SpanContainingQueryBuilder queryBuilder, Query query) throws IOException {
|
|
||||||
if (queryBuilder.boost() == AbstractQueryBuilder.DEFAULT_BOOST) {
|
|
||||||
//lucene default behaviour
|
|
||||||
assertThat(query.getBoost(), equalTo(queryBuilder.bigQuery().boost()));
|
|
||||||
} else {
|
|
||||||
assertThat(query.getBoost(), equalTo(queryBuilder.boost()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidate() {
|
public void testValidate() {
|
||||||
int totalExpectedErrors = 0;
|
int totalExpectedErrors = 0;
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
|
|
||||||
public class SpanWithinQueryBuilderTests extends AbstractQueryTestCase<SpanWithinQueryBuilder> {
|
public class SpanWithinQueryBuilderTests extends AbstractQueryTestCase<SpanWithinQueryBuilder> {
|
||||||
|
@ -41,16 +40,6 @@ public class SpanWithinQueryBuilderTests extends AbstractQueryTestCase<SpanWithi
|
||||||
assertThat(query, instanceOf(SpanWithinQuery.class));
|
assertThat(query, instanceOf(SpanWithinQuery.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void assertBoost(SpanWithinQueryBuilder queryBuilder, Query query) throws IOException {
|
|
||||||
if (queryBuilder.boost() == AbstractQueryBuilder.DEFAULT_BOOST) {
|
|
||||||
//lucene default behaviour
|
|
||||||
assertThat(query.getBoost(), equalTo(queryBuilder.littleQuery().boost()));
|
|
||||||
} else {
|
|
||||||
assertThat(query.getBoost(), equalTo(queryBuilder.boost()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidate() {
|
public void testValidate() {
|
||||||
int totalExpectedErrors = 0;
|
int totalExpectedErrors = 0;
|
||||||
|
|
Loading…
Reference in New Issue