Query DSL: Span Term Query wrongly parses when boost is provided, causing using it in span or to fail, closes #1032.

This commit is contained in:
kimchy 2011-06-15 13:11:22 +03:00
parent 551b98f2f8
commit 11f19ff6da
3 changed files with 43 additions and 0 deletions

View File

@ -74,6 +74,7 @@ public class SpanTermQueryParser implements QueryParser {
}
}
}
parser.nextToken();
} else {
value = parser.text();
// move to the next token

View File

@ -1223,6 +1223,18 @@ public class SimpleIndexQueryParserTests {
assertThat(((SpanTermQuery) spanOrQuery.getClauses()[2]).getTerm(), equalTo(new Term("age", NumericUtils.longToPrefixCoded(36))));
}
@Test public void testSpanOrQuery2() throws IOException {
IndexQueryParserService queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/spanOr2.json");
Query parsedQuery = queryParser.parse(query).query();
assertThat(parsedQuery, instanceOf(SpanOrQuery.class));
SpanOrQuery spanOrQuery = (SpanOrQuery) parsedQuery;
assertThat(spanOrQuery.getClauses().length, equalTo(3));
assertThat(((SpanTermQuery) spanOrQuery.getClauses()[0]).getTerm(), equalTo(new Term("age", NumericUtils.longToPrefixCoded(34))));
assertThat(((SpanTermQuery) spanOrQuery.getClauses()[1]).getTerm(), equalTo(new Term("age", NumericUtils.longToPrefixCoded(35))));
assertThat(((SpanTermQuery) spanOrQuery.getClauses()[2]).getTerm(), equalTo(new Term("age", NumericUtils.longToPrefixCoded(36))));
}
@Test public void testQueryFilterBuilder() throws Exception {
IndexQueryParserService queryParser = queryParser();
Query parsedQuery = queryParser.parse(filteredQuery(termQuery("name.first", "shay"), queryFilter(termQuery("name.last", "banon")))).query();

View File

@ -0,0 +1,30 @@
{
"span_or" : {
"clauses" : [
{
"span_term" : {
"age" : {
"value" : 34,
"boost" : 1.0
}
}
},
{
"span_term" : {
"age" : {
"value" : 35,
"boost" : 1.0
}
}
},
{
"span_term" : {
"age" : {
"value" : 36,
"boost" : 1.0
}
}
}
]
}
}