fix the type of the mapping

This commit is contained in:
Shay Banon 2013-06-11 14:49:07 +02:00
parent 3a0f9c6ea3
commit 78fb12bcaa

View File

@ -19,13 +19,6 @@
package org.elasticsearch.test.integration.search.rescore; package org.elasticsearch.test.integration.search.rescore;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
import org.apache.lucene.util.English; import org.apache.lucene.util.English;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType; import org.elasticsearch.action.search.SearchType;
@ -41,6 +34,12 @@ import org.elasticsearch.search.rescore.RescoreBuilder;
import org.elasticsearch.test.integration.AbstractSharedClusterTest; import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
/** /**
* *
*/ */
@ -94,7 +93,7 @@ public class QueryRescorerTests extends AbstractSharedClusterTest {
assertSecondHit(searchResponse, hasId("2")); assertSecondHit(searchResponse, hasId("2"));
assertThirdHit(searchResponse, hasId("3")); assertThirdHit(searchResponse, hasId("3"));
} }
@Test @Test
public void testMoreDocs() throws Exception { public void testMoreDocs() throws Exception {
Builder builder = ImmutableSettings.builder(); Builder builder = ImmutableSettings.builder();
@ -103,7 +102,7 @@ public class QueryRescorerTests extends AbstractSharedClusterTest {
builder.put("index.analysis.filter.synonym.type", "synonym"); builder.put("index.analysis.filter.synonym.type", "synonym");
builder.putArray("index.analysis.filter.synonym.synonyms", "ave => ave, avenue", "street => str, street"); builder.putArray("index.analysis.filter.synonym.synonyms", "ave => ave, avenue", "street => str, street");
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type2").startObject("properties") XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("field1").field("type", "string").field("index_analyzer", "whitespace").field("search_analyzer", "synonym") .startObject("field1").field("type", "string").field("index_analyzer", "whitespace").field("search_analyzer", "synonym")
.endObject().endObject().endObject().endObject(); .endObject().endObject().endObject().endObject();
@ -140,16 +139,16 @@ public class QueryRescorerTests extends AbstractSharedClusterTest {
assertFirstHit(searchResponse, hasId("2")); assertFirstHit(searchResponse, hasId("2"));
assertSecondHit(searchResponse, hasId("6")); assertSecondHit(searchResponse, hasId("6"));
assertThirdHit(searchResponse, hasId("3")); assertThirdHit(searchResponse, hasId("3"));
searchResponse = client() searchResponse = client()
.prepareSearch() .prepareSearch()
.setQuery(QueryBuilders.matchQuery("field1", "lexington avenue massachusetts").operator(MatchQueryBuilder.Operator.OR)) .setQuery(QueryBuilders.matchQuery("field1", "lexington avenue massachusetts").operator(MatchQueryBuilder.Operator.OR))
.setFrom(0) .setFrom(0)
.setSize(5) .setSize(5)
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setRescorer( .setRescorer(
RescoreBuilder.queryRescorer(QueryBuilders.matchPhraseQuery("field1", "lexington avenue massachusetts").slop(3)) RescoreBuilder.queryRescorer(QueryBuilders.matchPhraseQuery("field1", "lexington avenue massachusetts").slop(3))
.setQueryWeight(0.6f).setRescoreQueryWeight(2.0f)).setRescoreWindow(20).execute().actionGet(); .setQueryWeight(0.6f).setRescoreQueryWeight(2.0f)).setRescoreWindow(20).execute().actionGet();
assertThat(searchResponse.getHits().hits().length, equalTo(5)); assertThat(searchResponse.getHits().hits().length, equalTo(5));
assertHitCount(searchResponse, 9); assertHitCount(searchResponse, 9);
@ -165,10 +164,10 @@ public class QueryRescorerTests extends AbstractSharedClusterTest {
assertThat(leftHits.getHits().length, equalTo(rightHits.getHits().length)); assertThat(leftHits.getHits().length, equalTo(rightHits.getHits().length));
SearchHit[] hits = leftHits.getHits(); SearchHit[] hits = leftHits.getHits();
for (int i = 0; i < hits.length; i++) { for (int i = 0; i < hits.length; i++) {
assertThat(hits[i].getId(), equalTo(rightHits.getHits()[i].getId())); assertThat(hits[i].getId(), equalTo(rightHits.getHits()[i].getId()));
} }
} }
private static final void assertEquivalentOrSubstringMatch(String query, SearchResponse plain, SearchResponse rescored) { private static final void assertEquivalentOrSubstringMatch(String query, SearchResponse plain, SearchResponse rescored) {
SearchHits leftHits = plain.getHits(); SearchHits leftHits = plain.getHits();
SearchHits rightHits = rescored.getHits(); SearchHits rightHits = rescored.getHits();
@ -200,7 +199,7 @@ public class QueryRescorerTests extends AbstractSharedClusterTest {
for (int i = 0; i < numDocs; i++) { for (int i = 0; i < numDocs; i++) {
client().prepareIndex("test", "type1", String.valueOf(i)).setSource("field1", English.intToEnglish(i)).execute().actionGet(); client().prepareIndex("test", "type1", String.valueOf(i)).setSource("field1", English.intToEnglish(i)).execute().actionGet();
} }
flush(); flush();
optimize(); // make sure we don't have a background merge running optimize(); // make sure we don't have a background merge running
refresh(); refresh();
@ -220,44 +219,44 @@ public class QueryRescorerTests extends AbstractSharedClusterTest {
.constantScoreQuery(QueryBuilders.matchPhraseQuery("field1", intToEnglish).slop(3))) .constantScoreQuery(QueryBuilders.matchPhraseQuery("field1", intToEnglish).slop(3)))
.setQueryWeight(1.0f) .setQueryWeight(1.0f)
.setRescoreQueryWeight(0.0f)) // no weigth - so we basically use the same score as the actual query .setRescoreQueryWeight(0.0f)) // no weigth - so we basically use the same score as the actual query
.setRescoreWindow(50).execute().actionGet(); .setRescoreWindow(50).execute().actionGet();
SearchResponse plain = client().prepareSearch() SearchResponse plain = client().prepareSearch()
.setPreference("test") // ensure we hit the same shards for tie-breaking .setPreference("test") // ensure we hit the same shards for tie-breaking
.setQuery(QueryBuilders.matchQuery("field1", query).operator(MatchQueryBuilder.Operator.OR)).setFrom(0).setSize(10) .setQuery(QueryBuilders.matchQuery("field1", query).operator(MatchQueryBuilder.Operator.OR)).setFrom(0).setSize(10)
.execute().actionGet(); .execute().actionGet();
// check equivalence // check equivalence
assertEquivalent(plain, rescored); assertEquivalent(plain, rescored);
rescored = client() rescored = client()
.prepareSearch() .prepareSearch()
.setPreference("test") // ensure we hit the same shards for tie-breaking .setPreference("test") // ensure we hit the same shards for tie-breaking
.setQuery(QueryBuilders.matchQuery("field1", query).operator(MatchQueryBuilder.Operator.OR)) .setQuery(QueryBuilders.matchQuery("field1", query).operator(MatchQueryBuilder.Operator.OR))
.setFrom(0) .setFrom(0)
.setSize(10) .setSize(10)
.setRescorer( .setRescorer(
RescoreBuilder RescoreBuilder
.queryRescorer( .queryRescorer(
QueryBuilders QueryBuilders
.constantScoreQuery(QueryBuilders.matchPhraseQuery("field1", "not in the index").slop(3))) .constantScoreQuery(QueryBuilders.matchPhraseQuery("field1", "not in the index").slop(3)))
.setQueryWeight(1.0f) .setQueryWeight(1.0f)
.setRescoreQueryWeight(1.0f)) .setRescoreQueryWeight(1.0f))
.setRescoreWindow(50).execute().actionGet(); .setRescoreWindow(50).execute().actionGet();
// check equivalence // check equivalence
assertEquivalent(plain, rescored); assertEquivalent(plain, rescored);
rescored = client() rescored = client()
.prepareSearch() .prepareSearch()
.setPreference("test") // ensure we hit the same shards for tie-breaking .setPreference("test") // ensure we hit the same shards for tie-breaking
.setQuery(QueryBuilders.matchQuery("field1", query).operator(MatchQueryBuilder.Operator.OR)) .setQuery(QueryBuilders.matchQuery("field1", query).operator(MatchQueryBuilder.Operator.OR))
.setFrom(0) .setFrom(0)
.setSize(10) .setSize(10)
.setRescorer( .setRescorer(
RescoreBuilder RescoreBuilder
.queryRescorer( .queryRescorer(
QueryBuilders.matchPhraseQuery("field1", intToEnglish).slop(0)) QueryBuilders.matchPhraseQuery("field1", intToEnglish).slop(0))
.setQueryWeight(1.0f).setRescoreQueryWeight(1.0f)).setRescoreWindow(100).execute().actionGet(); .setQueryWeight(1.0f).setRescoreQueryWeight(1.0f)).setRescoreWindow(100).execute().actionGet();
// check equivalence or if the first match differs we check if the phrase is a substring of the top doc // check equivalence or if the first match differs we check if the phrase is a substring of the top doc
assertEquivalentOrSubstringMatch(intToEnglish, plain, rescored); assertEquivalentOrSubstringMatch(intToEnglish, plain, rescored);
} }
@ -265,7 +264,7 @@ public class QueryRescorerTests extends AbstractSharedClusterTest {
@Test @Test
public void testExplain() throws Exception { public void testExplain() throws Exception {
prepareCreate("test") prepareCreate("test")
.addMapping( .addMapping(
"type1", "type1",
jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1") jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1")