Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ public SearchAsYouTypeFieldMapper build(Mapper.BuilderContext context) {
final NamedAnalyzer searchQuoteAnalyzer = fieldType().searchQuoteAnalyzer();

// set up the prefix field
final String prefixFieldName = name() + PREFIX_FIELD_SUFFIX;
final PrefixFieldType prefixFieldType = new PrefixFieldType(name(), prefixFieldName, Defaults.MIN_GRAM, Defaults.MAX_GRAM);
final String fullName = buildFullName(context);
final String prefixFieldName = fullName + PREFIX_FIELD_SUFFIX;
final PrefixFieldType prefixFieldType = new PrefixFieldType(fullName, prefixFieldName, Defaults.MIN_GRAM, Defaults.MAX_GRAM);
prefixFieldType.setIndexOptions(fieldType().indexOptions());
// wrap the root field's index analyzer with shingles and edge ngrams
final SearchAsYouTypeAnalyzer prefixIndexWrapper =
Expand All @@ -180,7 +181,7 @@ public SearchAsYouTypeFieldMapper build(Mapper.BuilderContext context) {
for (int i = 0; i < shingleFieldMappers.length; i++) {
final int shingleSize = i + 2;
final ShingleFieldType shingleFieldType = new ShingleFieldType(fieldType(), shingleSize);
shingleFieldType.setName(getShingleFieldName(name(), shingleSize));
shingleFieldType.setName(getShingleFieldName(buildFullName(context), shingleSize));
// wrap the root field's index, search, and search quote analyzers with shingles
final SearchAsYouTypeAnalyzer shingleIndexWrapper =
SearchAsYouTypeAnalyzer.withShingle(indexAnalyzer.analyzer(), shingleSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,60 @@ public void testSimpleMerge() throws IOException {
}
}

public void testMultiFields() throws IOException {
for (int shingleSize = 2; shingleSize < 4; shingleSize++) {
final XContentBuilder mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject("a_field")
.field("type", "text")
.startObject("fields")
.startObject("suggest")
.field("type", "search_as_you_type")
.field("max_shingle_size", shingleSize)
.endObject()
.endObject()
.endObject()
.endObject()
.endObject();

final String index = "foo_" + shingleSize;
final String path = "a_field.suggest";
List<String> fields = new ArrayList<>();
fields.add(path);
final MapperService mapperService =
createIndex(index, Settings.EMPTY, "_doc", mapping).mapperService();
FieldType fieldType = mapperService.fullName(path + "._index_prefix");
assertThat(fieldType, instanceOf(PrefixFieldType.class));
PrefixFieldType prefixFieldType = (PrefixFieldType) fieldType;
assertEquals(path, prefixFieldType.parentField);
for (int i = 2; i < shingleSize; i++) {
String name = path + "._" + i + "gram";
fields.add(name);
fieldType = mapperService.fullName(name);
assertThat(fieldType, instanceOf(ShingleFieldType.class));
ShingleFieldType ft = (ShingleFieldType) fieldType;
assertEquals(i, ft.shingleSize);
assertTrue(prefixFieldType == ft.prefixFieldType);
}

ParsedDocument doc = mapperService.documentMapper()
.parse(new SourceToParse("test", "_doc", "1",
BytesReference.bytes(
XContentFactory.jsonBuilder()
.startObject()
.field("a_field", "new york city")
.endObject()
), XContentType.JSON)
);
for (String field : fields) {
IndexableField[] indexFields = doc.rootDoc().getFields(field);
assertEquals(1, indexFields.length);
assertEquals("new york city", indexFields[0].stringValue());
}
}
}

public void testIndexOptions() throws IOException {
final String mapping = Strings.toString(XContentFactory.jsonBuilder()
.startObject()
Expand Down