Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search_as_you_type field with term_vector #66432

Merged
merged 2 commits into from
Dec 16, 2020
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 @@ -166,8 +166,8 @@ public SearchAsYouTypeFieldMapper build(ContentPath contentPath) {
indexAnalyzers.put(ft.name(), indexAnalyzer);

// set up the prefix field
FieldType prefixft = new FieldType(fieldType);
prefixft.setStoreTermVectors(false);
FieldType prefixft = new FieldType();
prefixft.setIndexOptions(fieldType.indexOptions());
prefixft.setOmitNorms(true);
prefixft.setStored(false);
final String fullName = buildFullName(contentPath);
Expand All @@ -179,10 +179,8 @@ public SearchAsYouTypeFieldMapper build(ContentPath contentPath) {
SearchAsYouTypeAnalyzer.withShingle(searchAnalyzer.analyzer(), maxShingleSize.getValue()));
// don't wrap the root field's search quote analyzer as prefix field doesn't support phrase queries
TextSearchInfo prefixSearchInfo = new TextSearchInfo(prefixft, similarity.getValue(), prefixSearchWrapper, searchAnalyzer);
final PrefixFieldType prefixFieldType
= new PrefixFieldType(fullName, prefixSearchInfo, Defaults.MIN_GRAM, Defaults.MAX_GRAM);
final NamedAnalyzer prefixAnalyzer
= new NamedAnalyzer(indexAnalyzer.name(), AnalyzerScope.INDEX, prefixIndexWrapper);
final PrefixFieldType prefixFieldType = new PrefixFieldType(fullName, prefixSearchInfo, Defaults.MIN_GRAM, Defaults.MAX_GRAM);
final NamedAnalyzer prefixAnalyzer = new NamedAnalyzer(indexAnalyzer.name(), AnalyzerScope.INDEX, prefixIndexWrapper);
final PrefixFieldMapper prefixFieldMapper = new PrefixFieldMapper(prefixft, prefixFieldType);
indexAnalyzers.put(prefixFieldType.name(), prefixAnalyzer);

Expand All @@ -206,8 +204,7 @@ public SearchAsYouTypeFieldMapper build(ContentPath contentPath) {
final ShingleFieldType shingleFieldType = new ShingleFieldType(fieldName, shingleSize, textSearchInfo);
shingleFieldType.setPrefixFieldType(prefixFieldType);
shingleFieldTypes[i] = shingleFieldType;
NamedAnalyzer shingleAnalyzer
= new NamedAnalyzer(indexAnalyzer.name(), AnalyzerScope.INDEX, shingleIndexWrapper);
NamedAnalyzer shingleAnalyzer = new NamedAnalyzer(indexAnalyzer.name(), AnalyzerScope.INDEX, shingleIndexWrapper);
shingleFieldMappers[i] = new ShingleFieldMapper(shingleft, shingleFieldType);
indexAnalyzers.put(shingleFieldType.name(), shingleAnalyzer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,48 @@ public void testStoredOnly() throws IOException {
}

public void testTermVectors() throws IOException {
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "search_as_you_type").field("term_vector", "yes")));
ParsedDocument doc = mapper.parse(source(b -> b.field("field", "some text")));
for (String termVector : new String[] { "yes", "with_positions", "with_offsets", "with_positions_offsets",
"with_positions_payloads", "with_positions_offsets_payloads"}) {
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "search_as_you_type")
.field("term_vector", termVector)));
ParsedDocument doc = mapper.parse(source(b -> b.field("field", "some text")));

assertTrue(fieldType(doc, "field").storeTermVectors());
IndexableFieldType rootField = fieldType(doc, "field");
assertTrue(rootField.storeTermVectors());
if (termVector.contains("positions")) {
assertThat(rootField.storeTermVectorPositions(), equalTo(termVector.contains("positions")));
}
if (termVector.contains("offsets")) {
assertTrue(rootField.storeTermVectorOffsets());
assertThat(rootField.storeTermVectorOffsets(), equalTo(termVector.contains("offsets")));
}
if (termVector.contains("payloads")) {
assertTrue(rootField.storeTermVectorPayloads());
assertThat(rootField.storeTermVectorPayloads(), equalTo(termVector.contains("payloads")));
}

Stream.of(
fieldType(doc, "field._2gram"),
fieldType(doc, "field._3gram")
).forEach(ft -> assertTrue(ft.storeTermVectors()));
Stream.of(
fieldType(doc, "field._2gram"),
fieldType(doc, "field._3gram")
).forEach(ft -> {
assertTrue(ft.storeTermVectors());
if (termVector.contains("positions")) {
assertThat(ft.storeTermVectorPositions(), equalTo(termVector.contains("positions")));
}
if (termVector.contains("offsets")) {
assertThat(ft.storeTermVectorOffsets(), equalTo(termVector.contains("offsets")));
}
if (termVector.contains("payloads")) {
assertThat(ft.storeTermVectorPayloads(), equalTo(termVector.contains("payloads")));
}
});

PrefixFieldMapper prefixFieldMapper = getPrefixFieldMapper(mapper, "field._index_prefix");
assertFalse(prefixFieldMapper.fieldType.storeTermVectors());
PrefixFieldMapper prefixFieldMapper = getPrefixFieldMapper(mapper, "field._index_prefix");
assertFalse(prefixFieldMapper.fieldType.storeTermVectors());
assertFalse(prefixFieldMapper.fieldType.storeTermVectorOffsets());
assertFalse(prefixFieldMapper.fieldType.storeTermVectorPositions());
assertFalse(prefixFieldMapper.fieldType.storeTermVectorPayloads());
}
}

public void testNorms() throws IOException {
Expand Down