【问题标题】:Hippo CMS search within linked beansHippo CMS 在链接的 bean 中搜索
【发布时间】:2018-09-07 17:24:18
【问题描述】:

我有一个河马豆,其中包含一系列河马作为linkedBeans。

  @HippoEssentialsGenerated(internalName = "example:comment")
public List<HippoBean> getComment() {
    return getLinkedBeans("comment", HippoBean.class);
}

现在我想创建一个查询来检索这样的 cmets:

hstQuery = HstQueryBuilder.create(scope)
            .ofTypes(Article.class)
            .where(constraint("example:comment").contains("good job"))
            .build();

这个想法是检索所有文章,使得与它们关联的 cmets 包含字符串“good job”。到目前为止,这个查询没有返回任何东西。是否可以查看作为 LinkedBeans 关联到另一个 HippoBean 的 HippoBeans 数组内部?如果是这样,如何做到这一点?我见过允许在单个属性中搜索文本的示例,如下所示:

 HstQuery hstQuery = HstQueryBuilder.create(scope)
            .ofTypes(BaseDocument.class)
            .where(constraint("title").contains("Hello World"))
            .limit(pageSize)
            .offset(pageSize * (pageNum - 1))
            .orderByDescending("mynamespace:date")
            .build();

在这种情况下,查询只返回那些标题包含字符串“Hello World”的文档

【问题讨论】:

    标签: repository contains hippocms


    【解决方案1】:

    example:comment 不是评论,它是对评论的引用。所以这个查询在 uuid 中寻找字符串“good job”。不幸的是,您无法按照您想要的方式创建此查询。对于每篇文章,您需要进行第二次查询才能找到此信息。或者查询所有 cmets 的“good job”并检索与它们关联的文章。无论哪种方式都会很昂贵。

    【讨论】:

      【解决方案2】:

      这将返回所有包含文章文档链接的评论文档:

      ContentBeanUtils.createIncomingBeansQuery(article,scope,"example:comment/@hippo:docbase,Comment.class,false)
      

      第一个参数是被多个评论文档链接的文章类的具体实例。

      更详细的解释见: https://www.onehippo.org/library/concepts/search/search-all-hippodocument-beans-that-have-a-link-to-a-hippodocument-you-have.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-09-09
        • 1970-01-01
        • 1970-01-01
        • 2015-05-04
        • 2015-04-08
        • 2023-03-20
        • 2015-04-05
        相关资源
        最近更新 更多