I recently updated Lucene.net from nuget and DeleteDocuments stopped working. The following code is similar to what I am doing ... This is copied from "orchard cms". I noticed similar questions, but the solutions are not relevant to my case. Does anyone face the same problem?
public void Delete(string indexName, IEnumerable<int> documentIds) {
documentIds = documentIds.ToArray();
if (!documentIds.Any()) {
return;
}
using(var writer = new IndexWriter(indexName, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), false, IndexWriter.MaxFieldLength.UNLIMITED)) {
var query = new BooleanQuery();
try {
foreach (var id in documentIds) {
query.Add(new BooleanClause(new TermQuery(new Term("id", id.ToString(CultureInfo.InvariantCulture))), Occur.SHOULD));
}
writer.DeleteDocuments(query);
}
catch (Exception ex) {
Logger.Error(ex, "An unexpected error occured while removing the documents [{0}] from the index [{1}].", String.Join(", ", documentIds), indexName);
}
}
}
source
share