Search returns no result but XPath returns result!

107 views
Skip to first unread message

Eric Nguyen personal

unread,
May 19, 2015, 5:15:48 AM5/19/15
to hippo-c...@googlegroups.com
I'm implementing search for images and assets.

I've printed out the JCR query as follows:

//*[(@hippo:paths='e6187783-5298-4b2f-95b7-7524f3bd1ce7' or @hippo:paths='c52841d4-b73c-4edb-9bcd-4d7a5d635a2d') and (@hippo:availability='live') and not(@jcr:primaryType='nt:frozenNode') and (jcr:contains(., 'tania') or (jcr:contains(., 'tania.jpg')) or (jcr:contains(., 'tania.jpeg')) or (jcr:contains(., 'tania.png')) or (jcr:contains(., 'tania.gif')))] order by @jcr:lastModified ascending

I've tested it at http://localhost:8080/cms/repository and it returns 1 result:

Query executed
//*[(@hippo:paths='e6187783-5298-4b2f-95b7-7524f3bd1ce7' or @hippo:paths='c52841d4-b73c-4edb-9bcd-4d7a5d635a2d') and (@hippo:availability='live') and not(@jcr:primaryType='nt:frozenNode') and (jcr:contains(., 'tania') or (jcr:contains(., 'tania.jpg')) or (jcr:contains(., 'tania.jpeg')) or (jcr:contains(., 'tania.png')) or (jcr:contains(., 'tania.gif')))] order by @jcr:lastModified ascending

Number of results found: 1
/content/gallery/scc/news--events/social/2015/tania.jpg/tania.jpg
#jcr:primaryTypejcr:pathjcr:score
1 scc:scc /content/gallery/scc/news--events/social/2015/tania.jpg/tania.jpg 6708

However, on my site, it returns pageable.total 0!

What's happening?

Eric Nguyen personal

unread,
May 19, 2015, 5:20:07 AM5/19/15
to hippo-c...@googlegroups.com
Strange enough, search for "tania.jpg" on my site returns the 1 correct result!

Jeroen Reijn

unread,
May 19, 2015, 7:47:50 AM5/19/15
to hippo-c...@googlegroups.com
What was the term used for searching when you got 0 results?

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Visit this group at http://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.



--
Jeroen Reijn
Hippo

Amsterdam office - Oosteinde 11, 1017 WT Amsterdam
Boston office - 745 Atlantic Ave, Eight Floor, Boston MA 02111, United states of America.

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

http://blog.jeroenreijn.com | @jreijn | http://about.me/jeroenreijn

Ard Schrijvers

unread,
May 20, 2015, 4:40:35 AM5/20/15
to hippo-c...@googlegroups.com
On Tue, May 19, 2015 at 11:20 AM, Eric Nguyen personal
<ericng...@gmail.com> wrote:
> Strange enough, search for "tania.jpg" on my site returns the 1 correct
> result!

Site and cms both implement a slightly different query so a difference
can be correct (for example cms postfixes search strings with a '*'
and the site doesn't)

Regards Ard
> --
> Hippo Community Group: The place for all discussions and announcements about
> Hippo CMS (and HST, repository etc. etc.)
>
> To post to this group, send email to hippo-c...@googlegroups.com
> RSS:
> https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
> ---
> You received this message because you are subscribed to the Google Groups
> "Hippo Community" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to hippo-communi...@googlegroups.com.
> Visit this group at http://groups.google.com/group/hippo-community.
> For more options, visit https://groups.google.com/d/optout.



--
Hippo Netherlands, Oosteinde 11, 1017 WT Amsterdam, Netherlands
Hippo USA, Inc.- 745 Atlantic Ave, Eight Floor, Boston MA 02111,

Eric Nguyen personal

unread,
May 20, 2015, 9:10:57 PM5/20/15
to hippo-c...@googlegroups.com
The search term that gives 0 result is "tania"
(the expected result is 1 image with file name "Tania.jpg")

Eric Nguyen personal

unread,
May 20, 2015, 9:12:44 PM5/20/15
to hippo-c...@googlegroups.com
So what am I supposed to do Ard?

From the experiment at http://localhost:8080/cms/repository, my query is already correct, isn't it?

Ard Schrijvers

unread,
May 21, 2015, 4:32:09 AM5/21/15
to hippo-c...@googlegroups.com
Hey Eric,

On Thu, May 21, 2015 at 3:12 AM, Eric Nguyen personal
<ericng...@gmail.com> wrote:
> So what am I supposed to do Ard?

I am sorry, I think I was put on the wrong foot by your second mail. I
have now closely looked at your first mail, because the problem you
seem to have is that the repository does return a hit, but the site
doesn't. Right? The query you test in the repository is the one that
is executed in the site, so, you'd expect the same number of results,
right?

Now, I am not sure if you are using some standard search component,
but in your first mail you write:

pageable.total 0

Typically, this is correct as long as there are no more hits then
pageSize. I think paging totals will only be larger than 0 if paging
should be shown, but when the number of hits is smaller than the page
size, obviously you don't need to show pages. In other words, did you
look at the correct number/result?

If this is not the problem, the only other possibility is that the
site does the query with the 'liveuser' and in the repository you did
the query most likely with admin. You then have to test the query in
the repository servlet while logging in with the liveuser

HTH,

Regards Ard

Eric Nguyen personal

unread,
May 21, 2015, 10:43:13 PM5/21/15
to hippo-c...@googlegroups.com
Hi Ard,

No worries, I found and resolved the problem :)

Everything is right update to the HstQueryResult.

However, something is wrong with the default conversion from HstQueryResult => the Pageable object for displaying the results!
I've tried the following and there was 0 items in the Pageable object!
Overrode buildQuery() method
Overrode beforeRender() method and used: 
Pageable<HippoBean> result = this.executeQuery(request, paramInfo, hstQuery);


Then I built the Pageable myself from the HstQueryResult and it works :D:
hstQuery.setLimit(pageSize);
hstQuery.setOffset(pageSize * (crPage - 1));

if (query != null && !"".equals(query)) {
Filter f = hstQuery.createFilter();
f.addContains(".", query + "*");

hstQuery.setFilter(f);
}
hstQuery.addOrderByDescending("jcr:lastModified");

HstQueryResult result = hstQuery.execute();
log.info("hst query "+hstQuery.toString());

log.info("current page is " + crPage);
HippoBeanIterator it = result.getHippoBeans();
// it.skip(pageSize * (crPage - 1));

Pageable<HippoBean> pageable = new IterablePagination<>(it,
result.getTotalSize(), pageSize, crPage);
log.info("pageable size " + pageable.getTotal());


log.info("size is " + result.getSize() + " - " + result.getTotalSize());

request.setAttribute("pageable", pageable);

Ard Schrijvers

unread,
May 22, 2015, 4:01:30 AM5/22/15
to hippo-c...@googlegroups.com
Hey Eric, thx for your feedback

Regards Ard

On Fri, May 22, 2015 at 4:43 AM, Eric Nguyen personal
Reply all
Reply to author
Forward
0 new messages