Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        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)));
        }
Пример #4
0
 internal IndexStatistics Add(DocumentStatistics documentStatistics)
 {
     return(Adjust(documentStatistics, 1));
 }
Пример #5
0
 internal IndexStatistics Remove(DocumentStatistics documentStatistics)
 {
     return(Adjust(documentStatistics, -1));
 }