/// <summary> /// Repositions the index item. /// </summary> /// <param name="cacheIndexInternal">The cache index internal.</param> /// <param name="indexInfo">The index info.</param> /// <param name="addItem">The add item.</param> /// <param name="searchIndex">Index of the search.</param> /// <param name="internalItem">The internal item.</param> /// <param name="comparer">The comparer.</param> private static void RepositionIndexItem(CacheIndexInternal cacheIndexInternal, Index indexInfo, IndexDataItem addItem, int searchIndex, InternalItem internalItem, InternalItemComparer comparer) { // Remove the Item from current position cacheIndexInternal.DeleteItem(searchIndex, false); // Determine where to insert the Item int newSearchIndex = cacheIndexInternal.GetInsertPosition(addItem, indexInfo.PrimarySortInfo.SortOrderList[0].SortBy, comparer); // insert the item at new position cacheIndexInternal.InsertItem(internalItem, newSearchIndex, false); }
/// <summary> /// Adds the new item. /// </summary> /// <param name="clientIndex">Index from the client.</param> /// <param name="cacheIndexInternal">The cache index internal.</param> /// <param name="indexInfo">The index info.</param> /// <param name="addItem">The add item.</param> /// <param name="storeContext">The store context.</param> /// <param name="comparer">The comparer.</param> private static void AddNewItem(CacheIndex clientIndex, CacheIndexInternal cacheIndexInternal, Index indexInfo, IndexDataItem addItem, IndexStoreContext storeContext, InternalItemComparer comparer) { int searchIndex; List<KeyValuePair<int, byte[]>> kvpList; searchIndex = cacheIndexInternal.GetInsertPosition(addItem, indexInfo.PrimarySortInfo.SortOrderList[0].SortBy, comparer); //Add item to CacheIndexInternal kvpList = null; if (addItem.Tags != null && addItem.Tags.Count > 0) { kvpList = new List<KeyValuePair<int, byte[]>>(); if (clientIndex.TargetIndexName != null) //Save to single index { foreach (KeyValuePair<string, byte[]> kvp in addItem.Tags) { //Add to tagHashCollection storeContext.TagHashCollection.AddTag(cacheIndexInternal.InDeserializationContext.TypeId, kvp.Key); kvpList.Add(new KeyValuePair<int, byte[]>(TagHashCollection.GetTagHashCode(kvp.Key), kvp.Value)); } } else //Save to multiple indexes { List<string> tagNameList; clientIndex.IndexTagMapping.TryGetValue(cacheIndexInternal.InDeserializationContext.IndexName, out tagNameList); foreach (string tagName in tagNameList) { //Add to tagHashCollection storeContext.TagHashCollection.AddTag(cacheIndexInternal.InDeserializationContext.TypeId, tagName); kvpList.Add(new KeyValuePair<int, byte[]>(TagHashCollection.GetTagHashCode(tagName), addItem.Tags[tagName])); } } } cacheIndexInternal.InsertItem(new InternalItem { ItemId = addItem.ItemId, TagList = kvpList }, searchIndex, true); }