Skip to content

Commit

Permalink
Ensure empty completion entries are never indexed
Browse files Browse the repository at this point in the history
closes #10987
  • Loading branch information
areek committed May 14, 2015
1 parent df59288 commit af6b69e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Expand Up @@ -369,6 +369,9 @@ public Mapper parse(ParseContext context) throws IOException {
payload = payload == null ? EMPTY : payload;
if (surfaceForm == null) { // no surface form use the input
for (String input : inputs) {
if (input.length() == 0) {
continue;
}
BytesRef suggestPayload = analyzingSuggestLookupProvider.buildPayload(new BytesRef(
input), weight, payload);
context.doc().add(getCompletionField(ctx, input, suggestPayload));
Expand All @@ -377,6 +380,9 @@ public Mapper parse(ParseContext context) throws IOException {
BytesRef suggestPayload = analyzingSuggestLookupProvider.buildPayload(new BytesRef(
surfaceForm), weight, payload);
for (String input : inputs) {
if (input.length() == 0) {
continue;
}
context.doc().add(getCompletionField(ctx, input, suggestPayload));
}
}
Expand Down
Expand Up @@ -435,6 +435,34 @@ public void testSimpleField() throws Exception {

}

@Test // see issue #10987
public void testEmptySuggestion() throws Exception {
String mapping = jsonBuilder()
.startObject()
.startObject(TYPE)
.startObject("properties")
.startObject(FIELD)
.field("type", "completion")
.startObject("context")
.startObject("type_context")
.field("path", "_type")
.field("type", "category")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
.string();

assertAcked(client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, mapping).get());
ensureGreen();

client().prepareIndex(INDEX, TYPE, "1").setSource(FIELD, "")
.setRefresh(true).get();

}

@Test
public void testMultiValueField() throws Exception {
assertAcked(prepareCreate(INDEX).addMapping(TYPE, createMapping(TYPE, ContextBuilder.reference("st", "category"))));
Expand Down

0 comments on commit af6b69e

Please sign in to comment.