/// <inheritdoc /> public int Add(T item, DocumentStatistics documentStatistics) { if (this.ItemLookup.ContainsKey(item)) { throw new LiftiException(ExceptionMessages.ItemAlreadyIndexed); } var id = this.reusableIds.Count == 0 ? this.nextId++ : this.reusableIds.Dequeue(); this.Add(id, item, new ItemMetadata <T>(id, item, documentStatistics)); return(id); }
/// <inheritdoc /> public void Add(int id, T item, DocumentStatistics documentStatistics) { if (this.ItemLookup.ContainsKey(item)) { throw new LiftiException(ExceptionMessages.ItemAlreadyIndexed); } if (this.ItemIdLookup.ContainsKey(id)) { throw new LiftiException(ExceptionMessages.IdAlreadyUsed, id); } this.Add(id, item, new ItemMetadata <T>(id, item, documentStatistics)); this.nextId = Math.Max(this.nextId, id + 1); }
private IndexStatistics Adjust(DocumentStatistics documentStatistics, int direction) { if (documentStatistics is null) { throw new ArgumentNullException(nameof(documentStatistics)); } var updatedFieldTokenCount = this.TokenCountByField; foreach (var fieldTokenCount in documentStatistics.TokenCountByField) { updatedFieldTokenCount.TryGetValue(fieldTokenCount.Key, out var previousCount); updatedFieldTokenCount = updatedFieldTokenCount.SetItem(fieldTokenCount.Key, previousCount + (fieldTokenCount.Value * direction)); } return(new IndexStatistics( updatedFieldTokenCount, this.TotalTokenCount + (documentStatistics.TotalTokenCount * direction))); }
internal IndexStatistics Add(DocumentStatistics documentStatistics) { return(Adjust(documentStatistics, 1)); }
internal IndexStatistics Remove(DocumentStatistics documentStatistics) { return(Adjust(documentStatistics, -1)); }