Set term vector flags to false for ._index_prefix field (#1901). (#3119)

* Set term vector flags to false for ._index_prefix field (#1901).

Signed-off-by: Vesa Pehkonen <vesa.pehkonen@intel.com>

* Replaced the FieldType copy ctor with ctor for the prefix field and replaced
setting the field type parameters with setIndexOptions(). (#1901)

Signed-off-by: Vesa Pehkonen <vesa.pehkonen@intel.com>

* Added tests for term vectors. (#1901)

Signed-off-by: Vesa Pehkonen <vesa.pehkonen@intel.com>

* Fixed code formatting error.

Signed-off-by: Vesa Pehkonen <vesa.pehkonen@intel.com>

Co-authored-by: sdp <sdp@9049fa06826d.jf.intel.com>
This commit is contained in:
vpehkone 2022-05-26 08:05:52 -07:00 committed by GitHub
parent 1e6dd560df
commit e6475255de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 8 deletions

View File

@ -205,8 +205,8 @@ public class SearchAsYouTypeFieldMapper extends ParametrizedFieldMapper {
ft.setIndexAnalyzer(analyzers.getIndexAnalyzer());
// 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(context);

View File

@ -352,7 +352,18 @@ public class SearchAsYouTypeFieldMapperTests extends MapperTestCase {
}
public void testTermVectors() throws IOException {
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "search_as_you_type").field("term_vector", "yes")));
String[] termVectors = {
"yes",
"with_positions",
"with_offsets",
"with_positions_offsets",
"with_positions_payloads",
"with_positions_offsets_payloads" };
for (String termVector : termVectors) {
DocumentMapper mapper = createDocumentMapper(
fieldMapping(b -> b.field("type", "search_as_you_type").field("term_vector", termVector))
);
assertTrue(getRootFieldMapper(mapper, "field").fieldType().fieldType.storeTermVectors());
@ -361,6 +372,10 @@ public class SearchAsYouTypeFieldMapperTests extends MapperTestCase {
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 {