Пример #1
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || GetType() != o.GetType())
            {
                return(false);
            }

            SearchGroup <TGroupValue> that = (SearchGroup <TGroupValue>)o;

            if (GroupValue == null)
            {
                if (that.GroupValue != null)
                {
                    return(false);
                }
            }
            else if (!GroupValue.Equals(that.GroupValue))
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
            public virtual ICollection <SearchGroup <T> > Merge(IList <IEnumerable <ISearchGroup <T> > > shards, int offset, int topN)
            {
                int maxQueueSize = offset + topN;

                //System.out.println("merge");
                // Init queue:
                for (int shardIDX = 0; shardIDX < shards.Count; shardIDX++)
                {
                    IEnumerable <ISearchGroup <T> > shard = shards[shardIDX];
                    if (shard.Any())
                    {
                        //System.out.println("  insert shard=" + shardIDX);
                        UpdateNextGroup(maxQueueSize, new ShardIter <T>(shard, shardIDX));
                    }
                }

                // Pull merged topN groups:
                List <SearchGroup <T> > newTopGroups = new List <SearchGroup <T> >();

                int count = 0;

                while (queue.Count != 0)
                {
                    MergedGroup <T> group = queue.First();
                    queue.Remove(group);
                    group.IsProcessed = true;
                    //System.out.println("  pop: shards=" + group.shards + " group=" + (group.groupValue == null ? "null" : (((BytesRef) group.groupValue).utf8ToString())) + " sortValues=" + Arrays.toString(group.topValues));
                    if (count++ >= offset)
                    {
                        SearchGroup <T> newGroup = new SearchGroup <T>();
                        newGroup.GroupValue = group.GroupValue;
                        newGroup.SortValues = group.TopValues;
                        newTopGroups.Add(newGroup);
                        if (newTopGroups.Count == topN)
                        {
                            break;
                        }
                        //} else {
                        // System.out.println("    skip < offset");
                    }

                    // Advance all iters in this group:
                    foreach (ShardIter <T> shardIter in group.Shards)
                    {
                        UpdateNextGroup(maxQueueSize, shardIter);
                    }
                }

                if (newTopGroups.Count == 0)
                {
                    return(null);
                }
                else
                {
                    return(newTopGroups);
                }
            }
        /// <summary>
        /// Returns top groups, starting from offset.  This may
        /// return null, if no groups were collected, or if the
        /// number of unique groups collected is &lt;= offset.
        /// </summary>
        /// <param name="groupOffset">The offset in the collected groups</param>
        /// <param name="fillFields">Whether to fill to <see cref="SearchGroup.sortValues"/></param>
        /// <returns>top groups, starting from offset</returns>
        public virtual IEnumerable <ISearchGroup <TGroupValue> > GetTopGroups(int groupOffset, bool fillFields)
        {
            //System.out.println("FP.getTopGroups groupOffset=" + groupOffset + " fillFields=" + fillFields + " groupMap.size()=" + groupMap.size());

            if (groupOffset < 0)
            {
                throw new ArgumentException("groupOffset must be >= 0 (got " + groupOffset + ")");
            }

            if (groupMap.Count <= groupOffset)
            {
                return(null);
            }

            if (orderedGroups == null)
            {
                BuildSortedSet();
            }

            ICollection <ISearchGroup <TGroupValue> > result = new List <ISearchGroup <TGroupValue> >();
            int upto           = 0;
            int sortFieldCount = groupSort.GetSort().Length;

            foreach (CollectedSearchGroup <TGroupValue> group in orderedGroups)
            {
                if (upto++ < groupOffset)
                {
                    continue;
                }
                //System.out.println("  group=" + (group.groupValue == null ? "null" : group.groupValue.utf8ToString()));
                SearchGroup <TGroupValue> searchGroup = new SearchGroup <TGroupValue>();
                searchGroup.GroupValue = group.GroupValue;
                if (fillFields)
                {
                    searchGroup.SortValues = new object[sortFieldCount];
                    for (int sortFieldIDX = 0; sortFieldIDX < sortFieldCount; sortFieldIDX++)
                    {
                        searchGroup.SortValues[sortFieldIDX] = comparators[sortFieldIDX].Value(group.ComparatorSlot);
                    }
                }
                result.Add(searchGroup);
            }
            //System.out.println("  return " + result.size() + " groups");
            return(result);
        }