carlos palma
carlos palma

Reputation: 834

Hippo CMS search within linked beans

I have a hippo bean that contains a list of hippobeans as linkedBeans.

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

Now I want to create a query to retrieve the comments like this:

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

The idea is to retrieve all the articles such that the comments associated to them contain the string "good job". So far this query does not return anything. Is it possible to look inside the array of HippoBeans associated as LinkedBeans to another HippoBean? And if so how can this be accomplished? I have seen examples that allow searching for text in a single property, like this:

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

in this case the query returns only those documents such that their title contains the string "Hello World"

Upvotes: 0

Views: 191

Answers (2)

carlos palma
carlos palma

Reputation: 834

This will return all the comment documents that contain a link to the article document:

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

The first argument is the specific instance of the article class that has been linked by several comment documents.

For a more detailed explanation see: https://www.onehippo.org/library/concepts/search/search-all-hippodocument-beans-that-have-a-link-to-a-hippodocument-you-have.html

Upvotes: 1

Jasper Floor
Jasper Floor

Reputation: 553

The example:comment isn't the comment, it's a reference to the comment. So this query is looking for the string "good job" in a uuid. You unfortunately cannot create this query the way you want. You will need a second query, per article, to find this information. Or query all the comments for "good job" and retrieve the articles associated with them. Either way it will be expensive.

Upvotes: 1

Related Questions