lucene 4: fix boost mapping tests

This commit is contained in:
Shay Banon 2012-11-05 11:37:58 +01:00
parent ffd262e96f
commit 5c45aad260
1 changed files with 6 additions and 15 deletions

View File

@ -46,12 +46,10 @@ public class BoostMappingTests {
.field("field", "b") .field("field", "b")
.endObject().bytes()); .endObject().bytes());
assertThat(doc.rootDoc().getFields().size(), equalTo(2)); // one fo the same named field will have the proper boost, the others will have 1
float sum = 0.0f; IndexableField[] fields = doc.rootDoc().getFields("field");
for (IndexableField field : doc.rootDoc().getFields()) { assertThat(fields[0].boost(), equalTo(2.0f));
sum += field.boost(); assertThat(fields[1].boost(), equalTo(1.0f));
}
assertThat(3.0f, equalTo(sum)); // 2.0 (for first field) + 1.0 (for second field)
} }
@Test @Test
@ -65,20 +63,13 @@ public class BoostMappingTests {
ParsedDocument doc = mapper.parse("type", "1", XContentFactory.jsonBuilder().startObject() ParsedDocument doc = mapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field", "a") .field("field", "a")
.field("_boost", 2.0f) .field("_boost", 2.0f)
.endObject().bytes()); .endObject().bytes());
assertThat(doc.rootDoc().getFields().size(), equalTo(1)); assertThat(doc.rootDoc().getField("field").boost(), equalTo(1.0f));
for (IndexableField field : doc.rootDoc().getFields()) {
assertThat(field.boost(), equalTo(1.0f));
}
doc = mapper.parse("type", "1", XContentFactory.jsonBuilder().startObject() doc = mapper.parse("type", "1", XContentFactory.jsonBuilder().startObject()
.field("field", "a") .field("field", "a")
.field("custom_boost", 2.0f) .field("custom_boost", 2.0f)
.endObject().bytes()); .endObject().bytes());
assertThat(doc.rootDoc().getFields().size(), equalTo(1)); assertThat(doc.rootDoc().getField("field").boost(), equalTo(2.0f));
for (IndexableField field : doc.rootDoc().getFields()) {
assertThat(field.boost(), equalTo(2.0f));
}
} }
} }