0

如何查询添加为 IndexEmbedded 的数据?
我有一个实体类

  [Indexed]
  public class Something
  {
    [Field(Index.Tokenized, Store = Store.Yes)]
    public virtual string Description { get; set; }

    [IndexedEmbedded]
    public virtual Category Category { get; set; }
    [IndexedEmbedded]
    public virtual Location Location { get; set; }
  }

位置为

[Indexed]
  public class Location 
  {
    /// </summary>            
    [Field(Index.Tokenized, Store = Store.Yes)]
    public virtual string Address
    {
  }

数据被添加到索引中(包括普通属性和 IndexEmbedded),我可以使用 Luke 看到它们。
但是,当我使用全文查询时,我只得到正常属性的有效结果,而不是IndexedEmbedded
例如 “样本描述” => 1 个结果,“帕洛阿尔托” => 0 个结果(它们都在索引中) 这是我的查询

using (IFullTextSession s = Search.CreateFullTextSession(NHibernateSession.GetSession())) {
        MultiFieldQuerParser qp = new MultiFieldQueryParser(new[] {
                                                                     “Description”,“Title”,”Name”
                                                                   }, new StandardAnalyzer());
        IQuery NHQuery = s.CreateFullTextQuery(qp.Parse(query), typeof(Something));
        result = NHQuery.List();

我做错了什么或遗漏了什么吗?

4

1 回答 1

2

据我所知,您没有引用 IndexedEmbedded 集合的字段。您应该在 MultiFieldQueryParser 中添加以下字段

new MultiFieldQueryParser(new[] {"Description", "Title", "Name", "Location.Address"})

字段的正确名称应该在 Luke 中可见,并以您应用IndexedEmbedded属性的属性名称为前缀。


编辑:如果默认前缀不符合您的喜好,您可以使用IndexedEmbedded属性的前缀参数更改它

于 2009-07-29T10:22:14.607 回答