add tests for boosted wildcard and prefix queries

This commit is contained in:
kimchy 2011-03-02 00:26:49 +02:00
parent 9560451896
commit ce862da8f4
3 changed files with 37 additions and 0 deletions

View File

@ -408,6 +408,17 @@ public class SimpleIndexQueryParserTests {
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 {
IndexQueryParser queryParser = queryParser();
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*")));
}
@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 {
IndexQueryParser queryParser = queryParser();
Query parsedQuery = queryParser.parse(rangeQuery("age").from(23).to(54).includeLower(true).includeUpper(false)).query();

View File

@ -0,0 +1,8 @@
{
"prefix" : {
"name.first" : {
"value" : "sh",
"boost" : 1.2
}
}
}

View File

@ -0,0 +1,8 @@
{
"wildcard" : {
"name.first" : {
"value" : "sh*",
"boost" : 1.2
}
}
}