Exemplo n.º 1
0
        /// <summary>
        /// 开始索引
        /// </summary>
        /// <param name="name"></param>
        public virtual void Begin(string name)
        {
            if (!StoreIndexs.ContainsKey(name))
            {
                return;
            }
            var storeIndex = StoreIndexs[name];

            if (storeIndex == null)
            {
                return;
            }
            Worder.Load(storeIndex);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 删除索引
        /// </summary>
        /// <param name="name"></param>
        public virtual void Delete(string name)
        {
            if (!StoreIndexs.ContainsKey(name))
            {
                return;
            }
            var storeIndex = StoreIndexs[name];

            if (storeIndex == null)
            {
                return;
            }
            Worder.Clear(storeIndex);
            Documentor.Clear(storeIndex);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 得到结果
        /// </summary>
        /// <param name="searchQuery"></param>
        /// <returns></returns>
        protected virtual SearchResultInfo GetSearchResultByFind(SearchQueryInfo searchQuery)
        {
            var result = new SearchResultInfo {
                Terms = Analyzer.Resolve(searchQuery.Key)
            };

            if (result.Terms == null)
            {
                return(result);
            }
            if (!StoreIndexs.ContainsKey(searchQuery.Name))
            {
                return(result);
            }
            var storeIndex = StoreIndexs[searchQuery.Name];

            if (storeIndex == null)
            {
                return(result);
            }
            result.Feilds = storeIndex.StoreFields.Select(it => it.Name).ToList();
            result.Words  = new List <WordInfo>();
            foreach (var term in result.Terms)
            {
                if (result.Words.Count(it => it.Name == term.Name) > 0)
                {
                    continue;
                }
                var word = Worder.GetInfo(storeIndex, term.Name);
                if (word != null)
                {
                    result.Words.Add(word);
                }
            }
            var documentIds = GetSearchDocumentIds(storeIndex, result, searchQuery);

            if (documentIds != null)
            {
                result.DocumentCount = documentIds.Count;
                AddSearchDocuments(storeIndex, searchQuery, result, documentIds);
            }
            if (result.Words.Count > 0)
            {
                result.DataCount = result.Words.Sum(it => it.DocumentCount) / result.Words.Count;
            }
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 删除词典
        /// </summary>
        /// <param name="name"></param>
        /// <param name="terms"></param>
        public virtual bool DeleteWords(string name, IList <TermInfo> terms)
        {
            if (!StoreIndexs.ContainsKey(name))
            {
                return(false);
            }
            var storeIndex = StoreIndexs[name];

            if (storeIndex == null)
            {
                return(false);
            }
            foreach (var term in terms)
            {
                Worder.Remove(storeIndex, term.Name);
            }
            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 创建索引
        /// </summary>
        /// <param name="name"></param>
        /// <param name="documents"></param>
        public virtual void AddDocuments(string name, IList <DocumentInfo> documents)
        {
            if (!StoreIndexs.ContainsKey(name))
            {
                return;
            }
            var storeIndex = StoreIndexs[name];

            if (storeIndex == null)
            {
                return;
            }
            foreach (var document in documents)
            {
                var feildTerms = SaveDocument(storeIndex, document);
                CreateWords(storeIndex, document, feildTerms);
            }
        }