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

Avatar

Avatar

RobertBailey201

Avatar

RobertBailey201

RobertBailey201

05-01-2017

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"); } }

Replies

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

05-01-2017

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.

Avatar

Avatar

RobertBailey201

Avatar

RobertBailey201

RobertBailey201

05-01-2017

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

Avatar

Runal_Trivedi

MVP

Avatar

Runal_Trivedi

MVP

Runal_Trivedi
MVP

05-01-2017

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