Example #1
0
            /// <summary>
            /// 获取搜索数据标识集合(任意匹配分词,根据权重排序)
            /// </summary>
            /// <param name="text">搜索关键字</param>
            /// <param name="maxSize">关键字最大字符长度</param>
            /// <param name="skipCount">跳过记录数据</param>
            /// <param name="getCount">获取记录数据</param>
            /// <param name="count">匹配数据总数</param>
            /// <param name="isKey">数据标识过滤</param>
            /// <param name="getWeight">权重计算</param>
            /// <returns>数据标识集合</returns>
            public keyType[] SearchAny(string text, int maxSize, int skipCount, int getCount, out int count, Func <keyType, bool> isKey = null, IWeight getWeight = null)
            {
                Simplified.Set(text, maxSize, true);
                if (Simplified.Size == 0)
                {
                    count = 0;
                    return(EmptyArray <keyType> .Array);
                }

                queryResult.Length = 0;
                wordQuery.Get(ref Simplified, MatchType.None, ref queryResult, ref lessWords);
                switch (queryResult.Count)
                {
                case 0: count = 0; break;

                case 1:
                    resultIndexArray.Length = 0;
                    foreach (KeyValuePair <keyType, ResultIndexArray> result in queryResult[0].Value.Dictionary)
                    {
                        if (isKey(result.Key))
                        {
                            resultIndexArray.Add(result);
                        }
                    }
                    count = resultIndexArray.Length;
                    if (count > skipCount)
                    {
                        return(resultIndexArray.GetRangeSortDesc(result => result.Value.Indexs.Length, skipCount, Math.Min(getCount, count - skipCount), result => result.Key));
                    }
                    break;

                default:
                    GetWeights(isKey, getWeight);
                    count = weights.Count;
                    if (count > skipCount)
                    {
                        weightArray.Length = 0;
                        weights.CopyTo(ref weightArray);
                        return(weightArray.GetRangeSortDesc(weight => weight.Value, skipCount, Math.Min(getCount, count - skipCount), result => result.Key));
                    }
                    break;
                }
                return(EmptyArray <keyType> .Array);
            }
Example #2
0
            /// <summary>
            /// 获取搜索数据标识集合(任意匹配分词,根据权重排序)
            /// </summary>
            /// <param name="text">搜索关键字</param>
            /// <param name="maxSize">关键字最大字符长度</param>
            /// <param name="skipCount">跳过记录数据</param>
            /// <param name="getCount">获取记录数据</param>
            /// <param name="count">匹配数据总数</param>
            /// <param name="isKey">数据标识过滤</param>
            /// <param name="getWeight">权重计算</param>
            /// <returns>数据标识集合</returns>
            public keyType[] SearchAny(string text, int maxSize, int skipCount, int getCount, out int count, Func <keyType, bool> isKey = null, IWeight getWeight = null)
            {
                Simplified.Set(text, maxSize);
                Search(false);
                switch (queryResult.Count)
                {
                case 0: count = 0; break;

                case 1:
                    resultIndexArray.Length = 0;
                    foreach (KeyValuePair <keyType, ResultIndexArray> result in queryResult[0].Value.Dictionary)
                    {
                        if (isKey(result.Key))
                        {
                            resultIndexArray.Add(result);
                        }
                    }
                    count = resultIndexArray.Length;
                    if (count > skipCount)
                    {
                        return(resultIndexArray.GetRangeSortDesc(result => result.Value.Indexs.Length, skipCount, Math.Min(getCount, count - skipCount), result => result.Key));
                    }
                    break;

                default:
                    GetWeights(isKey, getWeight);
                    count = weights.Count;
                    if (count > skipCount)
                    {
                        weightArray.Length = 0;
                        weights.CopyTo(ref weightArray);
                        //weightArray.PrepLength(count);
                        //foreach (KeyValuePair<keyType, int> weight in weights) weightArray.UnsafeAdd(weight);
                        return(weightArray.GetRangeSortDesc(weight => weight.Value, skipCount, Math.Min(getCount, count - skipCount), result => result.Key));
                    }
                    break;
                }
                return(NullValue <keyType> .Array);
            }