add tests for boosted wildcard and prefix queries
This commit is contained in:
parent
9560451896
commit
ce862da8f4
|
@ -408,6 +408,17 @@ public class SimpleIndexQueryParserTests {
|
||||||
assertThat(prefixQuery.getPrefix(), equalTo(new Term("name.first", "sh")));
|
assertThat(prefixQuery.getPrefix(), equalTo(new Term("name.first", "sh")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test public void testPrefixBoostQuery() throws IOException {
|
||||||
|
IndexQueryParser queryParser = queryParser();
|
||||||
|
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/prefix-boost.json");
|
||||||
|
Query parsedQuery = queryParser.parse(query).query();
|
||||||
|
assertThat(parsedQuery, instanceOf(PrefixQuery.class));
|
||||||
|
PrefixQuery prefixQuery = (PrefixQuery) parsedQuery;
|
||||||
|
// since age is automatically registered in data, we encode it as numeric
|
||||||
|
assertThat(prefixQuery.getPrefix(), equalTo(new Term("name.first", "sh")));
|
||||||
|
assertThat((double) prefixQuery.getBoost(), closeTo(1.2, 0.00001));
|
||||||
|
}
|
||||||
|
|
||||||
@Test public void testPrefixFilteredQueryBuilder() throws IOException {
|
@Test public void testPrefixFilteredQueryBuilder() throws IOException {
|
||||||
IndexQueryParser queryParser = queryParser();
|
IndexQueryParser queryParser = queryParser();
|
||||||
Query parsedQuery = queryParser.parse(filteredQuery(termQuery("name.first", "shay"), prefixFilter("name.first", "sh"))).query();
|
Query parsedQuery = queryParser.parse(filteredQuery(termQuery("name.first", "shay"), prefixFilter("name.first", "sh"))).query();
|
||||||
|
@ -474,6 +485,16 @@ public class SimpleIndexQueryParserTests {
|
||||||
assertThat(wildcardQuery.getTerm(), equalTo(new Term("name.first", "sh*")));
|
assertThat(wildcardQuery.getTerm(), equalTo(new Term("name.first", "sh*")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test public void testWildcardBoostQuery() throws IOException {
|
||||||
|
IndexQueryParser queryParser = queryParser();
|
||||||
|
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/wildcard-boost.json");
|
||||||
|
Query parsedQuery = queryParser.parse(query).query();
|
||||||
|
assertThat(parsedQuery, instanceOf(WildcardQuery.class));
|
||||||
|
WildcardQuery wildcardQuery = (WildcardQuery) parsedQuery;
|
||||||
|
assertThat(wildcardQuery.getTerm(), equalTo(new Term("name.first", "sh*")));
|
||||||
|
assertThat((double) wildcardQuery.getBoost(), closeTo(1.2, 0.00001));
|
||||||
|
}
|
||||||
|
|
||||||
@Test public void testRangeQueryBuilder() throws IOException {
|
@Test public void testRangeQueryBuilder() throws IOException {
|
||||||
IndexQueryParser queryParser = queryParser();
|
IndexQueryParser queryParser = queryParser();
|
||||||
Query parsedQuery = queryParser.parse(rangeQuery("age").from(23).to(54).includeLower(true).includeUpper(false)).query();
|
Query parsedQuery = queryParser.parse(rangeQuery("age").from(23).to(54).includeLower(true).includeUpper(false)).query();
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"prefix" : {
|
||||||
|
"name.first" : {
|
||||||
|
"value" : "sh",
|
||||||
|
"boost" : 1.2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"wildcard" : {
|
||||||
|
"name.first" : {
|
||||||
|
"value" : "sh*",
|
||||||
|
"boost" : 1.2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue