Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Extracting excerpts from SearchResult when using either fuzzy search string or wildcard search string

Avatar

Level 4

Hi All,

Does anyone know how I can configure the Java code shown below so that I can get correct Excerpts from SearchResult when using either fuzzy search string or wildcard search string.

It returns correct Excerpts if the search string is neither fuzzy search nor wildcard search , but it returns incorrect Excerpts if the search string is either fuzzy search or wildcard search.

Thank you for your time.

public static void debugExecuteSearch(final QueryBuilder queryBuilder, final Session session) { debugExecuteSearch("searchString", queryBuilder, session); debugExecuteSearch("searchString~", queryBuilder, session); debugExecuteSearch("*searchString*", queryBuilder, session); } public static void debugExecuteSearch(final String searchString, final QueryBuilder queryBuilder, final Session session) { try { final PredicateGroup createQueryPredicateGroup = new PredicateGroup("searchPredicates"); final Predicate pathPredicate = new Predicate("path"); pathPredicate.set(PathPredicateEvaluator.PATH, "/content/corporate/en_US"); createQueryPredicateGroup.add(pathPredicate); final Predicate fulltextPredicate = new Predicate("fulltext"); fulltextPredicate.set(FulltextPredicateEvaluator.FULLTEXT, searchString); createQueryPredicateGroup.add(fulltextPredicate); final Query query = queryBuilder.createQuery(createQueryPredicateGroup, session); final SearchResult searchResult = query.getResult(); final String firstExcerpt = searchResult.getHits().get(0).getExcerpt(); LOG.debug("debugExecuteSearch: searchString = '" + searchString + "'  ,  firstExcerpt = '" + firstExcerpt + "'"); } catch (final Exception e) { LOG.debug("debugExecuteSearch: FAILED"); } }
3 Replies

Avatar

Level 10

This would be a good example to get into an article - we will place this on our list. 

In mean time - look at this SVF thread: 

http://stackoverflow.com/questions/29741814/how-to-implement-search-using-query-builder-api-for-part...

It may help.

Thank you smacdonald2008 for your reply.  This gives me a clue.

The URL below , which is neither fuzzy nor wildcard , returns correct excerpt :-

http://localhost:4522/bin/querybuilder.json?path=/content/corporate/en_US&fulltext=searchString

But the URLs below , which are fuzzy and wildcard respectively , return incorrect excerpt (same as Java) :-

http://localhost:4522/bin/querybuilder.json?path=/content/corporate/en_US&fulltext=searchString~
http://localhost:4522/bin/querybuilder.json?path=/content/corporate/en_US&fulltext=*searchString*

Do you know how I can configure these URLs to return the correct excerpt ?

Thank you for your time.

Avatar

Community Advisor

I tried few queries with wildcard, fuzzy search and fulltext, it returned correct excerpt all the time.

http://localhost:4502/bin/querybuilder.json?path=/content/geometrixx/en&fulltext=geometrixx~&p.limit...

http://localhost:4502/bin/querybuilder.json?path=/content/geometrixx/en&fulltext=*company*&p.limit=5

http://localhost:4502/bin/querybuilder.json?path=/content/geometrixx/en&fulltext=geometrixx&p.limit=...

All of the above returns the same Excerpt in search Results. I tried many other combinations and all worked giving me correct excerpts as expected.

Could it be an issue with your search result filtering? for e.g. when I hit http://localhost:4502/bin/querybuilder.json?path=/content/geometrixx/en&fulltext=*company*&p.limit=5 and see first 3 results, then even though they belong to same page, still the 1st result lacked the excerpt which is "/content/geometrixx/en/company/jcr:content/rightpar/title_0", while the other 2 showed the excerpt in the search.

Excerpt doesn't get inherited to child node but parent node can read excerpt from any of the child node under it, this is the reason why 1st result is missing the excerpt while the other 2 results shows the excerpt.

Which property search should consider for showing excerpts can be configured here - http://localhost:4502/system/console/configMgr/com.day.cq.search.impl.builder.QueryBuilderImpl

- Runal