当我使用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。搜索源代码。
有人对如何在一个字段中索引不同的属性有什么建议吗?