Пример #1
0
        /// <summary>
        /// Searches the index.
        /// </summary>
        /// <param name="queryText"></param>
        /// <param name="keywordFilter">A Hashtable where the key is the fieldname of the keyword and 
        /// the value the keyword itself.</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public SearchResultCollection Find(string queryText, Hashtable keywordFilter, int pageIndex, int pageSize)
        {
            long startTicks = DateTime.Now.Ticks;

            Hits hits;
            try
            {
                Query query = MultiFieldQueryParser.Parse(queryText, new string[] {"title", "contents"}, new StandardAnalyzer());
                IndexSearcher searcher = new IndexSearcher(this._indexDirectory);

                if (keywordFilter != null && keywordFilter.Count > 0)
                {
                    QueryFilter qf = BuildQueryFilterFromKeywordFilter(keywordFilter);
                    hits = searcher.Search(query, qf);
                }
                else
                {
                    hits = searcher.Search(query);
                }
                int start = pageIndex*pageSize;
                int end = (pageIndex + 1)*pageSize;
                if (hits.Length() <= end)
                {
                    end = hits.Length();
                }
                SearchResultCollection results = new SearchResultCollection();
                results.TotalCount = hits.Length();
                results.PageIndex = pageIndex;

                for (int i = start; i < end; i++)
                {
                    SearchResult result = new SearchResult();
                    result.Title = hits.Doc(i).Get("title");
                    result.Summary = hits.Doc(i).Get("summary");
                    result.Author = hits.Doc(i).Get("author");
                    result.ModuleType = hits.Doc(i).Get("moduletype");
                    result.Path = hits.Doc(i).Get("path");
                    result.Category = hits.Doc(i).Get("category");
                    result.DateCreated = DateTime.Parse((hits.Doc(i).Get("datecreated")));
                    result.Score = hits.Score(i);
                    result.Boost = hits.Doc(i).GetBoost();
                    result.SectionId = Int32.Parse(hits.Doc(i).Get("sectionid"));
                    results.Add(result);
                }
                searcher.Close();
                results.ExecutionTime = DateTime.Now.Ticks - startTicks;

                return results;
            }
            catch (Exception ex)
            {
                throw new SearchException("Error while performing full-text search.", ex);
            }
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="searchResult"></param>
 public void Remove(SearchResult searchResult)
 {
     this.List.Remove(searchResult);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="searchResult"></param>
 public void Add(SearchResult searchResult)
 {
     this.List.Add(searchResult);
 }