예제 #1
0
        public override int BinarySearchItem(
            IndexDataItem searchItem,
            bool isTagPrimarySort,
            string sortFieldName,
            List <SortOrder> sortOrderList,
            List <string> localIdentityTagNames)
        {
            try
            {
                int searchIndex = -1;
                if (ResultItemList != null && ResultItemList.Count > 0)
                {
                    IndexDataItemComparer comparer = new IndexDataItemComparer(isTagPrimarySort, sortFieldName, sortOrderList);
                    searchIndex = ResultItemList.BinarySearch(searchItem, comparer);

                    //Look for localIdentity at searchIndex
                    if (searchIndex > -1 && localIdentityTagNames.Count > 0)
                    {
                        if (EqualsLocalId(ResultItemList[searchIndex], searchItem, localIdentityTagNames))
                        {
                            return(searchIndex);
                        }

                        //Search to left of the searchIndex
                        int newIndex = searchIndex - 1;
                        while (newIndex > -1 && comparer.Compare(ResultItemList[newIndex], searchItem) == 0)
                        {
                            if (EqualsLocalId(ResultItemList[newIndex], searchItem, localIdentityTagNames))
                            {
                                return(newIndex);
                            }
                            newIndex--;
                        }

                        //Search to right of index
                        newIndex = searchIndex + 1;
                        while (newIndex < Count && comparer.Compare(ResultItemList[newIndex], searchItem) == 0)
                        {
                            if (EqualsLocalId(ResultItemList[newIndex], searchItem, localIdentityTagNames))
                            {
                                return(newIndex);
                            }
                            newIndex++;
                        }
                        return(-1);
                    }
                }
                return(searchIndex);
            }
            catch (Exception ex)
            {
                throw new Exception("Error in Binary Search", ex);
            }
        }
예제 #2
0
 public override int BinarySearchItem(
     IndexDataItem searchItem,
     bool isTagPrimarySort,
     string sortFieldName,
     List <SortOrder> sortOrderList,
     List <string> localIdentityTagNames)
 {
     if (ResultItemList != null)
     {
         IndexDataItemComparer comparer = new IndexDataItemComparer(isTagPrimarySort, sortFieldName, sortOrderList);
         return(ResultItemList.BinarySearch(searchItem, comparer));
     }
     return(-1);
 }