jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Klimetschek <aklim...@day.com>
Subject Re: Excerpts on search queries.
Date Fri, 27 Nov 2009 16:03:02 GMT
On Sat, Nov 28, 2009 at 00:00, Simon Gaeremynck <gaeremyncks@gmail.com> wrote:
> I am trying to do a basic search query on the entire repository that returns
> any node that has a  sling:resourceType property and that has a
> property/content that matches a search string.
> If there is a match I need to get all the properties of that node and an
> excerpt of the matched string.
> I have the following xpath query who returns the correct nodes:
> //*[@sling:resourceType and (jcr:contains(jcr:content,'*test*') or
> jcr:contains(.,'*test*'))]
> This query gives me the parent of the jcr:content node and all the
> properties on it, which is exactly what I want.
> Now, I thought I could get the excerpts out of the results by appending
> /rep:excerpt(.) like so:
> //*[@sling:resourceType and (jcr:contains(jcr:content,'*test*') or
> jcr:contains(.,'*test*'))]/rep:excerpt(.)
> But this doesn't give my a usable excerpt.

I guess the excerpt is only useful when done on the jcr:content node.
So I think this query should do the trick:

//*[@sling:resourceType and (jcr:contains(jcr:content,'test') or

and then you'd call the rep:excerpt() with the jcr:content as parameter:

Row row = ...
Value excerpt = row.getValue("rep:excerpt(jcr:content)");

In this case you could also switch between the excerpt from a
jcr:content subnode or the node itself, depending on what exists.

Note that I also changed "*test*" to "test" as that should give the
same results. jcr:contains does a full text search, not an exact
comparison, hence word stemming etc. all take place.

> Another problem I'm facing with excerpts is when I try to get an excerpt out
> of a property/jcr:content with no (or almost none) content around the
> highlighted word/phrase.
> It seems to fill up the space by taking other property values of the node.

You can have a custom excerpt provider:


Alexander Klimetschek

View raw message