MatchData constructor

MatchData([
  1. String? term,
  2. String? field,
  3. Metadata? metadata
])

term - The term this match data is associated with field - The field in which the term was found metadata - The metadata recorded about this term in this field

Implementation

MatchData([String? term, String? field, Metadata? metadata]) {
  if (term == null || field == null) {
    return;
  }
  Metadata clonedMetadata = {};
  Iterable<String> metadataKeys = metadata?.keys ?? [];

  // Cloning the metadata to prevent the original
  // being mutated during match data combination.
  // Metadata is kept in an array within the inverted
  // index so cloning the data can be done with
  // List#sublist
  for (String key in metadataKeys) {
    clonedMetadata[key] = metadata![key]!.sublist(0);
  }

  this.metadata[term] = {};
  this.metadata[term]![field] = clonedMetadata;
}