我不确定为什么这不会撤回文件:
正在添加的文件:
document.Add(new Field("project.id", projectId.ToString(), Field.Store.YES, Field.Index.NO));
document.Add(new Field("contact.id", entity.Id.ToString(), Field.Store.YES, Field.Index.NO));
document.Add(new Field("contact.businesspartnerid", entity.BusinessPartnerId.ToString(), Field.Store.YES, Field.Index.NO));
document.Add(new Field("contact.businesspartner.name", entity.BusinessPartner.Name, Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("contact.emailaddress", entity.EmailAddress, Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("contact.firstname", entity.FirstName, Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("contact.lastname", entity.LastName, Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("contact.fullname", entity.FirstName + " " + entity.LastName, Field.Store.YES, Field.Index.ANALYZED));
Lucene.Net中的查询:
var prefix = "dan";
var fields = new {"contact.emailaddress"};
var filterFields = new Dictionary<string,string>();
filterFields.add("project.id","123456");
var parser = new MultiFieldQueryParser(Version.LUCENE_29, fields, new KeywordAnalyzer());
var query = new BooleanQuery();
query.Add(parser.Parse(prefix + "*"), BooleanClause.Occur.MUST);
if (filterFields != null)
{
foreach (var field in filterFields)
{
query.Add(parser.GetFieldQuery(field.Key, field.Value), BooleanClause.Occur.MUST);
}
}
传递给Lucene的查询: query.Query = {+(contact.emailaddress:dan *)+ project.id:123456}
如果我删除了解析器.GetFieldQuery它工作得很好。当我实际查看索引文件时,有一个带有project.id的条目和一个以“dan”开头的条目。
我是否应该通过project.id做其他事情来面对搜索?
答案 0 :(得分:0)
我最终改变了Lucene存储项目的方式.id:
document.Add(new Field("project.id", projectId.ToString(), Field.Store.NO, Field.Index.ANALYZED));