in aios/storage/indexlib/index/inverted_index/config/InvertedIndexConfigSerializer.cpp [50:182]
void InvertedIndexConfigSerializer::Serialize(const indexlibv2::config::InvertedIndexConfig& indexConfig,
autil::legacy::Jsonizable::JsonWrapper* json)
{
if (indexConfig.IsVirtual()) {
return;
}
assert(json->GetMode() == autil::legacy::Jsonizable::TO_JSON);
std::map<std::string, autil::legacy::Any> jsonMap = json->GetMap();
json->Jsonize(indexlibv2::config::InvertedIndexConfig::INDEX_NAME, indexConfig.GetIndexName());
json->Jsonize(indexlibv2::config::InvertedIndexConfig::INDEX_FORMAT_VERSIONID,
indexConfig.GetIndexFormatVersionId());
if (indexConfig.IsIndexUpdatable()) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::INDEX_UPDATABLE, indexConfig.IsIndexUpdatable());
if (indexConfig.IsPatchCompressed()) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::PATCH_COMPRESSED, indexConfig.IsPatchCompressed());
}
}
if (!indexConfig.GetAnalyzer().empty()) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::INDEX_ANALYZER, indexConfig.GetAnalyzer());
}
std::string typeStr =
indexlibv2::config::InvertedIndexConfig::InvertedIndexTypeToStr(indexConfig.GetInvertedIndexType());
json->Jsonize(indexlibv2::config::InvertedIndexConfig::INDEX_TYPE, typeStr);
int enableValue = 1;
int disableValue = 0;
if (indexConfig.GetDictConfig().get()) {
std::string dictName = indexConfig.GetDictConfig()->GetDictName();
json->Jsonize(indexlibv2::config::InvertedIndexConfig::HIGH_FEQUENCY_DICTIONARY, dictName);
}
if (indexConfig.GetAdaptiveDictionaryConfig().get()) {
std::string ruleName = indexConfig.GetAdaptiveDictionaryConfig()->GetRuleName();
json->Jsonize(indexlibv2::config::InvertedIndexConfig::HIGH_FEQUENCY_ADAPTIVE_DICTIONARY, ruleName);
}
if (indexConfig.GetFileCompressConfigV2().get()) {
std::string fileCompress = indexConfig.GetFileCompressConfigV2()->GetCompressName();
json->Jsonize(FILE_COMPRESSOR, fileCompress);
}
if (indexConfig.GetDictConfig() || indexConfig.GetAdaptiveDictionaryConfig()) {
std::string postingType;
if (indexConfig.GetHighFrequencyTermPostingType() == indexlib::index::hp_bitmap) {
postingType = indexlibv2::config::InvertedIndexConfig::HIGH_FREQ_TERM_BITMAP_POSTING;
} else {
assert(indexConfig.GetHighFrequencyTermPostingType() == indexlib::index::hp_both);
postingType = indexlibv2::config::InvertedIndexConfig::HIGH_FREQ_TERM_BOTH_POSTING;
}
json->Jsonize(indexlibv2::config::InvertedIndexConfig::HIGH_FEQUENCY_TERM_POSTING_TYPE, postingType);
}
if (indexConfig.GetShardingType() == indexlibv2::config::InvertedIndexConfig::IST_NEED_SHARDING) {
int32_t shardingCount = (int32_t)indexConfig.GetShardingIndexConfigs().size();
json->Jsonize(indexlibv2::config::InvertedIndexConfig::SHARDING_COUNT, shardingCount);
}
auto invertedIndexType = indexConfig.GetInvertedIndexType();
auto optionFlag = indexConfig.GetOptionFlag();
if (invertedIndexType == it_pack || invertedIndexType == it_expack || invertedIndexType == it_text) {
if (optionFlag & of_term_payload) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::TERM_PAYLOAD_FLAG, enableValue);
} else {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::TERM_PAYLOAD_FLAG, disableValue);
}
if (optionFlag & of_doc_payload) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::DOC_PAYLOAD_FLAG, enableValue);
} else {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::DOC_PAYLOAD_FLAG, disableValue);
}
if (optionFlag & of_position_payload) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::POSITION_PAYLOAD_FLAG, enableValue);
} else {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::POSITION_PAYLOAD_FLAG, disableValue);
}
if (optionFlag & of_position_list) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::POSITION_LIST_FLAG, enableValue);
} else {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::POSITION_LIST_FLAG, disableValue);
}
if (optionFlag & of_tf_bitmap) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::TERM_FREQUENCY_BITMAP, enableValue);
} else {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::TERM_FREQUENCY_BITMAP, disableValue);
}
} else if (invertedIndexType == it_string || invertedIndexType == it_number ||
invertedIndexType == it_number_int8 || invertedIndexType == it_number_uint8 ||
invertedIndexType == it_number_int16 || invertedIndexType == it_number_uint16 ||
invertedIndexType == it_number_int32 || invertedIndexType == it_number_uint32 ||
invertedIndexType == it_number_int64 || invertedIndexType == it_number_uint64) {
if (optionFlag & of_term_payload) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::TERM_PAYLOAD_FLAG, enableValue);
} else {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::TERM_PAYLOAD_FLAG, disableValue);
}
if (optionFlag & of_doc_payload) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::DOC_PAYLOAD_FLAG, enableValue);
} else {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::DOC_PAYLOAD_FLAG, disableValue);
}
}
if ((invertedIndexType != it_primarykey64) && (invertedIndexType != it_primarykey128) &&
(invertedIndexType != it_kv) && (invertedIndexType != it_kkv) && (invertedIndexType != it_trie) &&
(invertedIndexType != it_spatial) && (invertedIndexType != it_datetime) && (invertedIndexType != it_range) &&
!(optionFlag & of_term_frequency)) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::TERM_FREQUENCY_FLAG, disableValue);
}
if (indexConfig.IsReferenceCompress()) {
std::string indexCompressMode = indexlibv2::config::InvertedIndexConfig::INDEX_COMPRESS_MODE_REFERENCE;
json->Jsonize(indexlibv2::config::InvertedIndexConfig::INDEX_COMPRESS_MODE, indexCompressMode);
}
if (indexConfig.IsHashTypedDictionary()) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::USE_HASH_DICTIONARY,
indexConfig.IsHashTypedDictionary());
}
// truncate
if (indexConfig.HasTruncate()) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::HAS_TRUNCATE, indexConfig.HasTruncate());
auto truncateProfilesStr = indexConfig.GetUseTruncateProfilesStr();
if (!truncateProfilesStr.empty()) {
json->Jsonize(indexlibv2::config::InvertedIndexConfig::USE_TRUNCATE_PROFILES, truncateProfilesStr);
}
}
JsonizeShortListVbyteCompress(indexConfig, json);
}