Ejemplo n.º 1
0
        /// <summary>
        /// 按关键词搜索学校
        /// </summary>
        /// <param name="keywords"></param>
        /// <param name="pagerInfo"></param>
        /// <returns></returns>
        public List <SchoolSample> SearchSchoolList(string keywords, PagerInfo pagerInfo)
        {
            List <SchoolSample> list = new List <SchoolSample>();

            try
            {
                BooleanQuery query = new BooleanQuery();
                if (!string.IsNullOrEmpty(keywords))
                {
                    string[] keywordsParts = StringHelper.Split <string>(keywords, StringSplitOptions.RemoveEmptyEntries, " ", ",");

                    foreach (string keywordsPart in keywordsParts)
                    {
                        string lowerCaseKeywordsPart = keywordsPart.ToLower();

                        BooleanQuery groupQuery = new BooleanQuery();
                        groupQuery.Add(new WildcardQuery(new Term("Name", "*" + keywordsPart + "*")), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
                        groupQuery.Add(new WildcardQuery(new Term("CnName", "*" + keywordsPart + "*")), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
                        groupQuery.Add(new WildcardQuery(new Term("Pinyin", "*" + keywordsPart + "*")), Lucene.Net.Search.BooleanClause.Occur.SHOULD);

                        groupQuery.Add(new WildcardQuery(new Term("LC_Name", "*" + lowerCaseKeywordsPart + "*")), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
                        groupQuery.Add(new WildcardQuery(new Term("LC_CnName", "*" + lowerCaseKeywordsPart + "*")), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
                        groupQuery.Add(new WildcardQuery(new Term("LC_Pinyin", "*" + lowerCaseKeywordsPart + "*")), Lucene.Net.Search.BooleanClause.Occur.SHOULD);

                        query.Add(groupQuery, BooleanClause.Occur.MUST);
                    }

                    Sort sort = null;

                    LuceneManager.SearchLuceneData(LuceneTextIndexType.AllSchool, query, sort, pagerInfo, delegate(Document doc)
                    {
                        SchoolSample school = new SchoolSample(doc);

                        list.Add(school);
                    });
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex);
                pagerInfo.RecordCount = 0;
            }

            return(list);
        }
Ejemplo n.º 2
0
        public List <SchoolSample> SearchList(string keywords, PagerInfo pagerInfo)
        {
            List <SchoolSample> list = new List <SchoolSample>();

            try
            {
                BooleanQuery query = new BooleanQuery();
                if (!string.IsNullOrEmpty(keywords))
                {
                    string[] keywordsParts = keywords.Split(' ', ',');

                    foreach (string keywordsPart in keywordsParts)
                    {
                        string lowerCaseKeywordsPart = keywordsPart.ToLower();

                        BooleanQuery groupQuery = new BooleanQuery();

                        groupQuery.Add(new WildcardQuery(new Term("CnName", "*" + lowerCaseKeywordsPart + "*")), BooleanClause.Occur.SHOULD);
                        groupQuery.Add(new WildcardQuery(new Term("Pinyin", "*" + lowerCaseKeywordsPart + "*")), BooleanClause.Occur.SHOULD);

                        query.Add(groupQuery, BooleanClause.Occur.MUST);
                    }
                }



                Sort   sort         = null;
                string textIndexDir = LuceneManager.GetLuceneTextIndexDirectoryPath(LuceneTextIndexType.ChinaUniversity, null);

                LuceneManager.SearchLuceneData(textIndexDir, query, sort, pagerInfo, delegate(Document doc)
                {
                    SchoolSample school = new SchoolSample(doc);

                    list.Add(school);
                });
            }
            catch (Exception ex)
            {
                pagerInfo.RecordCount = 0;
            }

            return(list);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 按关键词搜索文章
        /// </summary>
        /// <param name="keywords"></param>
        /// <param name="pagerInfo"></param>
        /// <returns></returns>
        public List <LuceneArticle> SearchArticleList(string keywords, PagerInfo pagerInfo)
        {
            List <LuceneArticle> list  = new List <LuceneArticle>();
            BooleanQuery         query = new BooleanQuery();

            if (!string.IsNullOrEmpty(keywords))
            {
                string[] keywordsParts = keywords.Split(',');//逗号分隔

                foreach (string keywordsPart in keywordsParts)
                {
                    string lowerCaseKeywordsPart = keywordsPart.ToLower();

                    BooleanQuery groupQuery = new BooleanQuery();
                    groupQuery.Add(new WildcardQuery(new Term("Id", "*" + keywordsPart + "*")), BooleanClause.Occur.SHOULD);
                    groupQuery.Add(new WildcardQuery(new Term("Title", "*" + keywordsPart + "*")), BooleanClause.Occur.SHOULD);
                    groupQuery.Add(new WildcardQuery(new Term("Content", "*" + keywordsPart + "*")), BooleanClause.Occur.SHOULD);
                    query.Add(groupQuery, BooleanClause.Occur.MUST);
                }
                Sort sort = null;
                try
                {
                    List <Document> documentList = LuceneManager.SearchLuceneData(directoryPath, query, sort, pagerInfo, null);
                    if (documentList != null && documentList.Count > 0)
                    {
                        documentList.ForEach(item => { list.Add(new LuceneArticle(item)); });
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Info(this, ex.ToString());

                    pagerInfo.RecordCount = 0;
                }
            }


            return(list);
        }