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);