完成功能: keyword=='led' and (categoryid1 = "200010414596" orcategoryid2 = "200010414596" or categoryid3 = "200010414596" )
问题补充:
我现在是这样做的,有错,不知怎么改:
if (!string.IsNullOrEmpty(keyword))
{
//lucene 特殊字符
keyword = Regex.Replace(keyword, replacePattern, new MatchEvaluator(ReplaceSpecial));
if (!Regex.IsMatch(keyword, pattern))
{
BooleanQuery.SetMaxClauseCount(10000); //默认为1024;
keyword = keyword + "*";
}
QueryParser parserkeyword = new QueryParser("KeywordIndex", new StandardAnalyzer());
Query querykeyword = parserkeyword.Parse(keyword);
booleanQuery.Add(querykeyword, BooleanClause.Occur.MUST);
}
if (!string.IsNullOrEmpty(electroniccategoryid))
{
//根据关键字构造一个数组
String[] key = new String[] { electroniccategoryid };
//同时声明一个与之对应的字段数组
String[] fields = { "CategoryID1", "CategoryID2", "CategoryID3", "CategoryID4", "CategoryID5" };
//声明BooleanClause.Occur[]数组,它表示多个条件之间的关系
Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net.Analysis.Analyzer();
BooleanClause.Occur[] flags = new BooleanClause.Occur[] { BooleanClause.Occur.SHOULD };
//用MultiFieldQueryParser得到query对象
Query queryCategoryID = MultiFieldQueryParser.Parse(key, fields,null);
booleanQuery.Add(queryCategoryID, BooleanClause.Occur.MUST);
}