In function 'add', each time append a posting. In function 'Add', for each changed term, sort the postings according to their DID to maintain sorted.
In 'add' function, instead of append the new posting at the end, if use binary search to find the loc to insert, we maintain the sorted order by nature. Then we don't need the work in 'Add' function. It will become more efficient.
something like this around https://github.com/topicai/weakand/blob/develop/index.go#L75:
for term, tf := range d.Terms {
insertPos = sort.Search(len(idx.Ivt[term]), func(i int) bool {return idx.Ivt[term][i].DocId >= did})
idx.Ivt[term] = append(idx.Ivt[:insertPos], append(Posting{DocId: did, TF: tf}, idx.Ivt[insertPos:]...)...)
// changed[term]++
}
In function 'add', each time append a posting. In function 'Add', for each changed term, sort the postings according to their DID to maintain sorted.
In 'add' function, instead of append the new posting at the end, if use binary search to find the loc to insert, we maintain the sorted order by nature. Then we don't need the work in 'Add' function. It will become more efficient.
something like this around https://github.com/topicai/weakand/blob/develop/index.go#L75: