我希望我的Lucene查询包含类似于:
companyNam:梅赛德斯卡车
它将在companyName字段中与字符串"mercedes trucks"完全匹配.
companyName是一个未加密的字段,但任何带空格的东西都会返回null结果.
new TermQuery(new Term("companyName", "mercedes trucks"));
如果涉及空间,则总是得到0结果.否则我的程序运行正常.
也许替换:
mercedes trucks
同
mercedes?trucks
适合我.
像这样使用PhraseQuery:
//create the query objects BooleanQuery query = new BooleanQuery(); PhraseQuery q2 = new PhraseQuery(); //grab the search terms from the query string string[] str = Sitecore.Context.Request.QueryString[BRAND_TERM].Split(' '); //build the query foreach(string word in str) { //brand is the field I'm searching in q2.Add(new Term("brand", word.ToLower())); } //finally, add it to the BooleanQuery object query.Add(q2, BooleanClause.Occur.MUST); //Don't forget to run the query Hits hits = searcher.Search(query);
希望这可以帮助!