Ejemplo n.º 1
0
        /// <summary>
        /// Applies the grouping.
        /// </summary>
        /// <param name="internalItem">The internal item.</param>
        internal void ApplyGroupBy(InternalItem internalItem)
        {
            ResultItem resultItem = new ResultItem(InDeserializationContext.IndexId,
                                                   internalItem.ItemId,
                                                   null,
                                                   InternalItemAdapter.ConvertToTagDictionary(internalItem.TagList, InDeserializationContext));

            byte[] compositeKey;
            //Check if GroupBy needs to be applied
            if (String.IsNullOrEmpty(InDeserializationContext.GroupBy.FieldName))
            {
                compositeKey = GetCompositeKey(internalItem,
                                               InDeserializationContext.GroupBy.GroupByFieldNameList);
            }
            else
            {
                byte[] fieldValue;
                if (String.Compare(InDeserializationContext.GroupBy.FieldName, "ItemId", true) == 0)
                {
                    fieldValue = internalItem.ItemId;
                }
                else
                {
                    internalItem.TryGetTagValue(InDeserializationContext.GroupBy.FieldName, out fieldValue);
                }

                compositeKey = fieldValue != null &&
                               InDeserializationContext.GroupBy.FieldValueSet.Contains(fieldValue)
                                          ? GetCompositeKey(internalItem,
                                                            InDeserializationContext.GroupBy.GroupByFieldNameList)
                                          : GetCompositeKey(internalItem,
                                                            InDeserializationContext.GroupBy.NonGroupByFieldNameList);
            }
            GroupByResult.Add(compositeKey, resultItem);
        }
 /// <summary>
 /// Searches the specified search item.
 /// </summary>
 /// <param name="searchItem">The search item.</param>
 /// <returns></returns>
 internal int Search(IndexItem searchItem)
 {
     return(InDeserializationContext.PrimarySortInfo.IsTag ?
            InternalItemList.LinearSearch(InternalItemAdapter.ConvertToInternalItem(searchItem), InDeserializationContext.LocalIdentityTagNames) :
            InternalItemList.BinarySearchItem(InternalItemAdapter.ConvertToInternalItem(searchItem),
                                              InDeserializationContext.PrimarySortInfo.IsTag,
                                              InDeserializationContext.PrimarySortInfo.FieldName,
                                              InDeserializationContext.PrimarySortInfo.SortOrderList, InDeserializationContext.LocalIdentityTagNames));
 }
        /// <summary>
        /// Gets the result item list.
        /// </summary>
        /// <param name="cacheIndexInternal">The cache index internal.</param>
        /// <param name="itemPositionList">The item position list.</param>
        /// <returns>List of ResultItems</returns>
        internal static List <ResultItem> GetResultItemList(CacheIndexInternal cacheIndexInternal, IEnumerable <int> itemPositionList)
        {
            List <ResultItem> resultItemList = new List <ResultItem>();

            foreach (int itemPosition in itemPositionList)
            {
                resultItemList.Add(new ResultItem(cacheIndexInternal.InDeserializationContext.IndexId,
                                                  cacheIndexInternal.GetItem(itemPosition).ItemId,
                                                  null,
                                                  InternalItemAdapter.ConvertToTagDictionary(cacheIndexInternal.GetItem(itemPosition).TagList, cacheIndexInternal.InDeserializationContext)));
            }

            return(resultItemList);
        }
        /// <summary>
        /// Gets the index data item list.
        /// </summary>
        /// <param name="cacheIndexInternal">The cache index internal.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="itemNum">If 0 gets all items.</param>
        /// <returns>List of IndexDataItems</returns>
        internal static List <IndexDataItem> GetIndexDataItemList(CacheIndexInternal cacheIndexInternal, int offset, int itemNum)
        {
            if (itemNum == Int32.MaxValue)
            {
                itemNum = cacheIndexInternal.Count;
            }

            List <IndexDataItem> resultItemList = new List <IndexDataItem>(itemNum);

            if (cacheIndexInternal.Count >= offset)
            {
                for (int i = offset - 1; i < cacheIndexInternal.Count && resultItemList.Count < itemNum; i++)
                {
                    resultItemList.Add(new IndexDataItem(cacheIndexInternal.GetItem(i).ItemId,
                                                         InternalItemAdapter.ConvertToTagDictionary(cacheIndexInternal.GetItem(i).TagList, cacheIndexInternal.InDeserializationContext)));
                }
            }
            return(resultItemList);
        }
 /// <summary>
 /// Gets the insert position.
 /// </summary>
 /// <param name="searchItem">The search item.</param>
 /// <param name="sortBy">The sort by.</param>
 /// <param name="comparer">The comparer.</param>
 /// <returns>InsertPosition</returns>
 internal int GetInsertPosition(IndexItem searchItem, SortBy sortBy, InternalItemComparer comparer)
 {
     return(InternalItemList.GetInsertPosition(InternalItemAdapter.ConvertToInternalItem(searchItem), comparer, sortBy));
 }