代码之家  ›  专栏  ›  技术社区  ›  mathieu

(N) 休眠。搜索:在一个字段中索引不同的属性

  •  3
  • mathieu  · 技术社区  · 16 年前

    当我使用Lucene对我的实体进行索引时,我习惯于将所有索引属性放在一个名为“all”的字段中,以对我的“所有”实体类型进行搜索。

    [Indexed(Index = "MyIndex")]
    public class Post
    {
        [DocumentId]
        public virtual int Id { get; set; }
        [IndexedEmbedded]
        public virtual Author Author { get; set; }
        [IndexedEmbedded]
        public virtual IEnumerable<Category> Categories { get; set; }
        [Field(Index.Tokenized, Store = Store.Yes)]
        [Field(Name = "All", Index = Index.Tokenized, Store = Store.Yes)]
        public virtual string Name { get; set; }
        [Field(Name = "All", Index = Index.Tokenized, Store = Store.Yes)]
        [Field(Index.Tokenized, Store = Store.Yes)]
        public virtual string Body { get; set; }
    }
    

    但我在ScopedAnalyzer.cs第26行抛出了一个异常:“key已经存在于字典中”:

    scopedAnalyzers.Add(scope, analyzer);
    

    其中“scope”是索引字段的名称(此处为“All”)。如果我开一张支票,比如

    if( !scopedAnalyzers.ContainsKey( scope ) )
    

    然而,我并不容易修改NHibernate。搜索源代码。

    有人对如何在一个字段中索引不同的属性有什么建议吗?

    1 回复  |  直到 12 年前
        1
  •  2
  •   Andrew Smith    16 年前

    如果您在使用Field属性指定所需内容时遇到问题,可以创建一个类桥,允许您创建自己的文档。

    http://docs.jboss.org/hibernate/stable/search/reference/en/html/search-mapping-bridge.html 见4.2.2.3。ClassBridge路段

    推荐文章