Lucene'加入'怎么样?第二部分

时间:2010-02-22 15:05:49

标签: lucene.net nhibernate.search

第一部分here ......


要求:
在多个字段中搜索多个值 AND Where Bar.Id == argBar.Id

var parser = new MultiFieldQueryParser
  (new[] { "Name", "Title" }, new SimpleAnalyzer());

parser.???(string.Format("Bar.Id:{0}",argBar.Id)); // o_0

var query = Session.CreateFullTextQuery
   (parser.Parse(searchValue), new[] { typeof(Foo) });

Found this

Query searchQuery = MultiFieldQueryParser.Parse
  (term, new[] {"title", "description"},  
         new[] {BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD},  
         new StandardAnalyzer());

所以,理论上 - 我应该能够添加argBar.IdBooleanClause.Occur.Must,但Lucene.Net 2.4.0.2中没有这样的重载。

1 个答案:

答案 0 :(得分:0)

var bq = new BooleanQuery();
bq.Add(parser.Parse(searchValue), BooleanClause.Occur.SHOULD);
bq.Add(new TermQuery
  (new Term("Bar.Id", argBar.Id.ToString()), BooleanClause.Occur.Must);

var r = Session.CreateFullTextQuery(bq, new[] {typeof(Foo)});
//victory