addDocKeywordScore method

bool addDocKeywordScore(
  1. String keyword,
  2. String docId,
  3. double score
)

Adds a keword score for the docId to KeywordPostingsMap entry for the keyword.

Returns true if a keyword score for the docId did not previously exist in the KeywordPostingsMap.

Looks up an existing entry for keyword and inserts/overwrites an entry for docId if it exists.

If no entry for keyword exists in the KeywordPostingsMap, creates a new entry and adds score for docId to the new entry.

Implementation

bool addDocKeywordScore(String keyword, String docId, double score) {
  //
  // get the entry for the keyword or initialize a new one if it does not exist
  final Map<String, double> entry = this[keyword] ?? {};
  // get the existing positions list for [docId] if it exists
  final existingEntry = entry[docId];
  // overwrite the positions for docId
  entry[docId] = score;
  // set the entry for keyword with the new positions for docId
  this[keyword] = entry;
  // return true if a positions list for [docId] did not existed
  return existingEntry == null;
}