Пример #1
0
        /// <summary>
        /// 根据网站ID和关键字查询结果
        /// </summary>
        /// <param name="wenSiteIds"></param>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public static IQueryable <ContentEntity> SearchByShortNameIq(string wenSiteShortName, string keyword)
        {
            IQueryable <ContentEntity> mdoels = null;

            if (!string.IsNullOrEmpty(wenSiteShortName))
            {
                LUCENCEINDEXPATH = string.Format(LUCENCEINDEXPATH, wenSiteShortName);
                INDEX_DIR        = new DirectoryInfo(LUCENCEINDEXPATH);
                BooleanQuery bQuery = new BooleanQuery();

                using (IndexSearcher searcher = new IndexSearcher(FSDirectory.Open(INDEX_DIR), true))
                {
                    QueryParser parseFullName = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "FullName", analyzer);
                    Query       query         = parseFullName.Parse(keyword);
                    bQuery.Add(query, Occur.SHOULD);

                    QueryParser parseAuthor = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "Author", analyzer);
                    Query       queryAuthor = parseAuthor.Parse(keyword);
                    bQuery.Add(queryAuthor, Occur.SHOULD);

                    QueryParser parseContent = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "Content", analyzer);
                    Query       queryContent = parseContent.Parse(keyword);
                    bQuery.Add(queryContent, Occur.SHOULD);

                    TopDocs       tds = searcher.Search(bQuery, Int32.MaxValue);
                    List <string> ids = new List <string>();
                    foreach (ScoreDoc sd in tds.ScoreDocs)
                    {
                        Document doc = searcher.Doc(sd.Doc);
                        ids.Add(doc.Get("Id"));
                    }
                    if (ids != null && ids.Count > 0)
                    {
                        ContentApp contentApp = new ContentApp();
                        mdoels = contentApp.GetListsIq(m => ids.Contains(m.Id) && m.DeleteMark != true && m.EnabledMark == true);
                    }
                    searcher.Dispose();
                }
            }
            return(mdoels);
        }