Excerpt/hit.getExcerpt() is giving {relevant_links} as value when using QueryBuilderAPI | Community
Skip to main content
kamalakannank62
Level 3
Apr 2, 2019 12:49 PM UTC
Solved

Excerpt/hit.getExcerpt() is giving {relevant_links} as value when using QueryBuilderAPI

I am Using Query builder API for fulltext search, When using hits.getExcerpt() i am getting value as {relevant_links} for few pages. But when checking the same under http://localhost:4502/libs/cq/search/content/querydebug.html  i was able to see proper excerpt for the pages. I have set setExcerpt to true while constructing the query before executing is there something am missing?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
chandu_t
chandu_tAccepted solution
Level 3
Apr 3, 2019 9:37 AM UTC

Strange issue, double check your content most likely some content issue.

12 replies

kamalakannank62
Level 3
Apr 3, 2019 9:41 AM UTC

yeah its an content issue, got it.

Thank you bsloki​ , chandu t​

Translate
chandu_t
chandu_tAccepted solution
Level 3
Apr 3, 2019 9:37 AM UTC

Strange issue, double check your content most likely some content issue.

Translate
kamalakannank62
Level 3
Apr 3, 2019 7:51 AM UTC

One more thing is that when a page is having a text="Shipping" and if my search term is "ship", I am getting "{relevant_link}" as excerpt but when I Search "Shipping" i am getting a proper excerpt , Is there a way to make the Query to search exact word?

Translate
kamalakannank62
Level 3
Apr 3, 2019 7:21 AM UTC

I am not supposed to share the content package.

Translate
kamalakannank62
Level 3
Apr 3, 2019 7:21 AM UTC

bsloki​ thank you for the inputs, will raise a Day care ticket.

Translate
Lokesh_Shivalingaiah
Level 10
Apr 3, 2019 6:50 AM UTC

Also, raise a daycare ticket if you will not be able to share the content package here..

Translate
Lokesh_Shivalingaiah
Level 10
Apr 3, 2019 6:50 AM UTC

That doesnt sound right ! If you are getting right result in querydebug.hml, you should get the same with hit.getExcerpts aswell.. Did you see if there is any difference in the content between the pages where the correct excerpt is coming with the content on the other page ?

Can you provide a package with the sample content where you are seeing the wrong excerpt so that I can try to debug ?

Translate
kamalakannank62
Level 3
Apr 2, 2019 8:48 PM UTC

Yeah, I just added to check, Its not consistent, When tried the same with querydebug.html i was able to see consistent result, but here for some pages am getting proper result but for some pages i am not getting excerpt.

Translate
Lokesh_Shivalingaiah
Level 10
Apr 2, 2019 8:31 PM UTC

Hi,

I see you have already set "p.excerpt":"true", so you dont have to say q.setExcerpt(true); again.. you can remove that.

Also, is this output consistent for every result or only for few result ?

Translate
kamalakannank62
Level 3
Apr 2, 2019 7:54 PM UTC

bsloki​,

Please find the query snippet

Map<String, String> map = new HashMap<>();

  map.put("type", "nt:unstructured");

  map.put("fulltext", fulltextSearchTerm);

  map.put("path", localeRootPath);

  map.put("p.excerpt", "true");

  map.put("orderby", "@jcr:score");

  map.put("orderby.sort", "desc");

  map.put("p.limit", "-1");

  final QueryBuilder queryBuilder = getSling().getService(QueryBuilder.class);

  Query q = queryBuilder.createQuery(PredicateGroup.create(map),

                      getSling().getRequest().getResourceResolver().adaptTo(Session.class));

   q.setExcerpt(true);

  result = q.getResult();

for (Hit hit : result.getHits()) {

String excerpt = hit.getExcerpt(); //output is // {relevant_links}

}

Translate