Lucene.Net进行多字段搜索

Lucene.Net进行多字段搜索

Lucene.Net进行多字段搜索的关键代码:
             Lucene.Net.Search.IndexSearcher iSearcher
            = new Lucene.Net.Search.IndexSearcher(path);

            //多字段进行搜索
            string[] fields = { "Title", "KeyWords", "Content" };
            Lucene.Net.QueryParsers.QueryParser qp
                = new Lucene.Net.QueryParsers.MultiFieldQueryParser(fields, new Lucene.Net.Analysis.Standard.StandardAnalyzer());
            qp.SetDefaultOperator(Lucene.Net.QueryParsers.QueryParser.OR_OPERATOR);

            //进行多条件检索
            Lucene.Net.Search.BooleanQuery booleanQuery = new Lucene.Net.Search.BooleanQuery();
            Lucene.Net.Search.Query tempQuery = qp.Parse(key);
            booleanQuery.Add(tempQuery, Lucene.Net.Search.BooleanClause.Occur.MUST);
            Lucene.Net.Search.Hits hits = iSearcher.Search(booleanQuery);
posted @ 2009-10-08 19:25  searchDM  阅读(467)  评论(0编辑  收藏  举报