addZonePostings method
Adds a postings for the docId
to PostingsMap entry for the term
.
Returns true if posting positions for the docId
did not previously
exist in the PostingsMap.
Looks up an existing entry for term
and inserts/overwrites an entry
for docId
if it exists.
If no entry for term
exists in the PostingsMap, creates a new entry
and adds positions
for docId
to the new entry.
Implementation
bool addZonePostings(String term, String docId, ZonePostingsMap positions) {
//
// get the entry for the term or initialize a new one if it does not exist
final DocPostingsMap entry = this[term] ?? {};
// get the existing positions list for [docId] if it exists
final existingEntry = entry[docId];
// overwrite the positions for docId
entry[docId] = positions;
// set the entry for term with the new positions for docId
this[term] = entry;
// return true if a positions list for [docId] did not existed
return existingEntry == null;
}