【问题标题】:Hibernate lucene search collections and enumsHibernate lucene 搜索集合和枚举
【发布时间】:2014-07-24 21:46:29
【问题描述】:

我正在尝试使用休眠搜索(lucene)在我的应用程序中实现搜索功能。对字符串字段的简单搜索工作完美,但现在事情变得更加复杂...... 我希望你能给我一些提示或样本。

我有以下实体...

@Entity
@Indexed
public class ChildClass {

    @Enumerated
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    private EnumType enumType;
    ....

    //getter setter

}

=========================================

@Entity
@Indexed
public class ParentClass {

@IndexEmbeded
List<ChildClass> childs;

   //getter setter...

}

=========================================

public enum EnumType {
  a,b,c
}

========================================

现在我尝试搜索并找到例如:

"查找具有 child.enumtype = a 的子类的 ParentClasses 列表"

我可以使用 hql 或本机 sql 查询来做到这一点。但是如何使用 hibernate lucene 查询来做到这一点。

提前致谢

【问题讨论】:

  • 只是为了澄清地图例如 @Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO) @IndexedEmbedded(depth = 1) private Map cmets ;我可以使用如下查询: luceneQuery = queryBuilder.keyword().wildcard().onField("cmets").matching(searchString).createQuery(); booleanJunction.should(luceneQuery);此查询按预期返回结果。我对上述用例有疑问

标签: hibernate collections enums lucene hibernate-search


【解决方案1】:

您对@IndexedEmbedded 的使用不适用于这种情况-在我看来,您的子类是一个实体,就像在子实体中一样,它们引用了它们的父类,因此父类对其具有双向映射孩子们。

here 所述(Address 是用例示例)

确保 Place Lucene 文档在地址时更新 更改,则需要在双向的另一侧进行标记 与@ContainedIn 的关系。

@ContainedIn 仅对指向实体的关联有用 与嵌入(收集)对象相反。

也许您可以尝试在您的child 列表中添加@ContainedIn 注释。

总结:

  • 您可以使用从ChildParent 的@IndexedEmbedded(在父属性上)
  • 您可以使用@ContainedIn 从ParentCollection&lt;Child&gt;(双向)

【讨论】:

  • 感谢您的回复,到目前为止我了解,但是对于上面的 szenario,luceneQurery 应该如何,如您所见,我已经尝试过@IndexEmbedded
猜你喜欢
  • 2015-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多