0
我不知道這是爲什麼不拉回文件:使用GetFieldQuery的Lucene查詢無法取回結果?
要添加的文件:
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.emailaddr ess:dan *)+ project.id:123456}
如果我刪除了parser.GetFieldQuery它效果很好。當我物理地查看索引文件時,會出現一個帶有project.id的條目和一個以「dan」開頭的條目。
我應該做一些其他的事情來面向project.id搜索嗎?