开发者

Lucene query using GetFieldQuery not getting back results?

开发者 https://www.devze.com 2023-04-07 12:05 出处:网络
I am not sure why this is not pulling back documents: The documents being added: docu开发者_如何学Cment.Add(new Field(\"project.id\", projectId.ToString(), Field.Store.YES, Field.Index.NO));

I am not sure why this is not pulling back documents:

The documents being added:

docu开发者_如何学Cment.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));

The Query in 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);

                   }
               }

The query being passed to Lucene: query.Query = {+(contact.emailaddress:dan* ) +project.id:123456}

if I remove the parser.GetFieldQuery it works great. When I physically look into the index file there is an entry with the project.id and an entry that starts with "dan".

Should I be doing something else to facet the search by project.id?


I ended up changing the way Lucene was storing the project.id:

document.Add(new Field("project.id", projectId.ToString(), Field.Store.NO, Field.Index.ANALYZED));
0

精彩评论

暂无评论...
验证码 换一张
取 消