@indexedEmbedded的includePaths属性在放置嵌套实例字段时不创建索引

时间:2014-06-28 12:25:17

标签: java lucene hibernate-search

使用以下版本进行休眠搜索:

  • 冬眠核-4.2.0.Final.jar
  • 冬眠-搜索引擎-4.4.2.Final.jar
  • 冬眠-搜索分析仪-3.3.0.Final.jar
  • 冬眠-搜索ORM-4.4.2.Final.jar
  • lucene的核 - 3.6.2.jar

在放置实例的实例时,我遇到了includePaths注释@indexedEmbedded属性的问题。例如:(假设所有字段都有适当的getter / setter)

根类:

@Indexed
public class RootClass {

@IndexedEmbedded
private Set<Instance> setOfInstances;

}

实例类:

public class Instance {

@Field(index = Index.YES, analyze = Analyze.YES, norms = Norms.NO, store = Store.NO)
private String name;

@Field(index = Index.YES, analyze = Analyze.YES, norms = Norms.NO, store = Store.NO)
private String vesion;

@IndexedEmbedded(includePaths={"type", "location", "users.name", "users.country"})
private InstanceDetail deltail;
}

InstanceDetail类:

public class InstanceDetail{

@Field(index = Index.YES, analyze = Analyze.YES, norms = Norms.NO, store = Store.NO)
private int type;

@Field(index = Index.YES, analyze = Analyze.YES, norms = Norms.NO, store = Store.NO)
private String location;

@IndexedEmbedded
private Set<User> users;

@Field(index = Index.YES, analyze = Analyze.YES, norms = Norms.NO, store = Store.NO)
private String ref1;

@Field(index = Index.YES, analyze = Analyze.YES, norms = Norms.NO, store = Store.NO)
private String ref2

@IndexedEmbedded
private Set<Area> usersArea;
}

用户类:

public class User{
    @Field(index = Index.YES, analyze = Analyze.YES, norms = Norms.NO, store = Store.NO)
    private String name;

    @Field(index = Index.YES, analyze = Analyze.YES, norms = Norms.NO, store = Store.NO)
    private String address;

    @Field(index = Index.YES, analyze = Analyze.YES, norms = Norms.NO, store = Store.NO)
    private String mobile;

    @Field(index = Index.YES, analyze = Analyze.YES, norms = Norms.NO, store = Store.NO)
    private String country;
}

因此,当我在includePaths的{​​{1}}上定义 IndexedEmbedded 注释的 InstanceDetail 属性时, > 字段 Instance (其他人来得像名字/ vesion)正在为RootClass对象编制索引。 (按日志确认)。没有任何例外。

所以这是根据HibernateSearch的设计或者与我的实现有关的东西。

2 个答案:

答案 0 :(得分:0)

它应该有效,但您可能遇到与https://hibernate.atlassian.net/browse/HSEARCH-1112

相关的错误

答案 1 :(得分:0)

您必须在depth上的@IndexedEmedded注释中指定Instance.deltail才能获得InstanceDetail的属性。根据Javadocs:

  

当深度达到深度= 1表示停止索引嵌入元素   关联元素是索引的,但不是其嵌入元素。

     

默认值取决于includePaths属性的值:   如果没有定义路径,则默认为Integer.MAX_VALUE;如果有的话   定义了includePaths,如果没有,则默认深度被解释为0   指定为与其默认值不同的值。

depth设置为1会嵌入InstanceDetail的属性,而将其设置为2则会嵌入InstanceDetail及其关联的属性User秒。