如何删除Lunece.net DeleteDocuments?

时间:2014-11-06 14:08:45

标签: lucene.net

这是我的T-SQL查询:

DELETE FROM Table 
WHERE Id = 10000 AND Locale = N'en-US'

如何将此T-SQL查询转换为Lucene.net DeleteDocuments

此Lucene.net声明不起作用。

Document document = CreateLocationDocument(region);
Lucene.Net.Search.BooleanQuery query = new Lucene.Net.Search.BooleanQuery();

var queryParser1 = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "Id", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30));
var queryParser2 = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "Locale", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30));

query.Add(queryParser1.Parse(region1.id.ToString()), Lucene.Net.Search.Occur.SHOULD);
query.Add(queryParser2.Parse(region1.languageCode), Lucene.Net.Search.Occur.SHOULD);

indexWriter.DeleteDocuments(query);

这句话是OR查询。

我需要和查询。

1 个答案:

答案 0 :(得分:0)

我可以使用MultiFieldQueryParser MultiFiendQueryParser有2个选项 AND_OPERATOR和OR_OPERATOR。

我可以将MultiFieldQueryParser与AND_OPERATOR一起使用 你可以看到这个陈述

Lucene.Net.QueryParsers.MultiFieldQueryParser queryParser = new Lucene.Net.QueryParsers.MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, new[] { "language_code", "keyword" }, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30));
queryParser.DefaultOperator = MultiFieldQueryParser.AND_OPERATOR;
queryParser.AllowLeadingWildcard = true;
Lucene.Net.Search.Query query = queryParser.Parse(String.Format(@"(language_code:{0} keyword:{1}*)", locationRQ.Language, locationRQ.Query));