コード例 #1
0
ファイル: Search.cs プロジェクト: zhangb12465/AutoCSer
        /// <summary>
        /// 执行任务
        /// </summary>
        public override void RunTask()
        {
            SearchItem[] result = null;
            try
            {
                ThreadParameter threadParameter = Searcher.DefaultThreadParameter;
                SubString       simplifiedKey   = threadParameter.SetSimplified(key, maxTextSize);
                if (simplifiedKey.Count != 0)
                {
                    HashString cacheKey = simplifiedKey;
                    result = resultCache.Get(ref cacheKey, null);
                    if (result == null)
                    {
                        long wordCount = Searcher.Default.Results.WordCount;
                        LeftArray <KeyValue <HashString, AutoCSer.Search.StaticSearcher <DataKey> .QueryResult> > results = threadParameter.Search();
                        switch (results.Count)
                        {
                        case 0: result = NullValue <SearchItem> .Array; break;

                        case 1:
                            threadParameter.ResultIndexArray.Empty();
                            results[0].Value.CopyTo(ref threadParameter.ResultIndexArray);
                            result = threadParameter.ResultIndexArray.GetRangeSortDesc(value => getWeight(value.Key.Type, value.Value.Indexs.Length), 0, pageSize, value => new SearchItem(results[0].Key, value));
                            break;

                        default:
                            threadParameter.GetWeights();
                            result = threadParameter.GetWeightArray()
                                     .GetRangeSortDesc(weight => getWeight(weight.Key.Type, weight.Value), 0, pageSize, weight => new SearchItem(weight.Key));
                            break;
                        }
                        resultCache.Set(ref cacheKey, result);
                        if (resultCache.Count > maxResultCount)
                        {
                            resultCache.Pop();
                        }
                    }
                }
            }
            finally
            {
                onSearch.Callback(result ?? NullValue <SearchItem> .Array);
            }
        }