Metadata Examples
If you want to process both standardized and non-standardized metadata elements, you can loop through Metadata without checking is_standard() or standard_key() – both standardized and non-standardized metadata can be handled in the same way.
However, standardization allows you to handle particular metadata fields differently. Below is an illustrative example of how you might use standardized fields to act on documents.
// Search for documents created by a certain company
// Check for the Company standardized field
try
{
auto company = document.metadata().at(MetadataKey::Company);
if (company.convert_to_string() == "OpenText")
{
// Found matching standardized field
return pathToInputFile;
}
}
catch (const std::out_of_range&)
{
// No Company standardized field in the metadata, continue
}
// Check the unstandardized fields, in case the document included the
// company name using a non-standard key
for (auto [key, field] : document.metadata())
{
// Ignore standardized fields
if (field.is_standard())
continue;
// Custom visitor derived from MetadataVisitorBase<bool> whose visit
// functions all return false, except visit_target_encoding_string
// which returns true if the string matches "OpenText"
static CompanyIsOpenTextVisitor companyIsOpenText;
if (field.apply_visitor(companyIsOpenText))
{
// Found matching non-standardized field
return pathToInputFile;
}
}