Hi everybody!
I'm using com.day.cq.search.QueryBuilder to search for pages and documents. The page search (type=cq:Page) works just fine and results hits return excerpts just fine via getExcerpt(). But I have an issue with getting excerpts (that show a part of the text where the search term was found) after searching for DAM assets (type=dam:Asset). The assets are PDFs, DOCs, PPTs and XLSs, so there actually is no issue with getting the results I was looking for. The right files with the term within the files are found - so it DOES the "inner" search, I just can't get where it finds it. The problem is that the hits' excerpts are blank, empty strings (""). I tried getExcerpts() method that returns a Map<String, String> of excerpts, but nothing useful was inside. I can't use com.day.cq.wcm.foundation.Search because of other issues and because it's not as modifiable as QueryBuilder. Can anybody help me with this please?
Solved! Go to Solution.
Views
Replies
Total Likes
How you are calling getExcerpt method ? Note that for page and DAM, way getExcerpt() is called is different,
something like,
/**
* Get Highlighted title
* @return
* @throws Exception
*/
public String getTitle() throws Exception {
if (isPage()) {
return null!=getExcerpt(JcrConstants.JCR_TITLE) ? getExcerpt(JcrConstants.JCR_TITLE): this.valueMap.get(JcrConstants.JCR_TITLE, "");
} else {
return null!=getExcerpt(DamConstants.METADATA_FOLDER+"/"+DamConstants.DC_TITLE) ? getExcerpt(DamConstants.METADATA_FOLDER+"/"+DamConstants.DC_TITLE): this.valueMap.get(DamConstants.METADATA_FOLDER+"/"+DamConstants.DC_TITLE, "");
}
}
/**
* Get Highlighted description
* @return
* @throws Exception
*/
public String getDescription() throws Exception {
if (isPage()) {
return null!=getExcerpt(JcrConstants.JCR_DESCRIPTION) ? getExcerpt(JcrConstants.JCR_DESCRIPTION): this.valueMap.get(JcrConstants.JCR_DESCRIPTION, "");
} else {
return null!=getExcerpt(DamConstants.METADATA_FOLDER+"/"+DamConstants.DC_DESCRIPTION) ? getExcerpt(DamConstants.METADATA_FOLDER+"/"+DamConstants.DC_DESCRIPTION): this.valueMap.get(DamConstants.METADATA_FOLDER+"/"+DamConstants.DC_DESCRIPTION, "");
}
}
/**
* @return the default excerpt for this hit.
* @throws RepositoryException if an error occurs while building the
* excerpt.
*/
private String getExcerpt(String input) {
try{
return null!=input && !"".equals(input) ? this.hit.getExcerpts().get(input):null;
}catch(RepositoryException e){
}catch (Exception e) {
// TODO: handle exception
}
return null;
}
Yogesh
Views
Replies
Total Likes
Can you show use your QueryBuilder API code that returns your results please.
Views
Replies
Total Likes
Map<String, String> map = new HashMap<String, String>(); map.put("path", searchPath); if (searchType != null && !"".equals(searchType)) { map.put("type", searchType); } if (extensionFilter != null) { map.put("group.p.or", "true"); for (int i = 0; i < extensionFilter.length; i++) { map.put("group." + i + 1 + "_nodename", "*.".concat(extensionFilter[i])); } } if (escapedQueryForAttr != null && !"".equals(escapedQueryForAttr)) { map.put("fulltext", escapedQueryForAttr); } Query query = this.getService(QueryBuilder.class).createQuery(PredicateGroup.create(map), this.slingRequest.getResource().getResourceResolver().adaptTo(Session.class)); query.setHitsPerPage(0); SearchResult result = query.getResult();
Views
Replies
Total Likes
How you are calling getExcerpt method ? Note that for page and DAM, way getExcerpt() is called is different,
something like,
/**
* Get Highlighted title
* @return
* @throws Exception
*/
public String getTitle() throws Exception {
if (isPage()) {
return null!=getExcerpt(JcrConstants.JCR_TITLE) ? getExcerpt(JcrConstants.JCR_TITLE): this.valueMap.get(JcrConstants.JCR_TITLE, "");
} else {
return null!=getExcerpt(DamConstants.METADATA_FOLDER+"/"+DamConstants.DC_TITLE) ? getExcerpt(DamConstants.METADATA_FOLDER+"/"+DamConstants.DC_TITLE): this.valueMap.get(DamConstants.METADATA_FOLDER+"/"+DamConstants.DC_TITLE, "");
}
}
/**
* Get Highlighted description
* @return
* @throws Exception
*/
public String getDescription() throws Exception {
if (isPage()) {
return null!=getExcerpt(JcrConstants.JCR_DESCRIPTION) ? getExcerpt(JcrConstants.JCR_DESCRIPTION): this.valueMap.get(JcrConstants.JCR_DESCRIPTION, "");
} else {
return null!=getExcerpt(DamConstants.METADATA_FOLDER+"/"+DamConstants.DC_DESCRIPTION) ? getExcerpt(DamConstants.METADATA_FOLDER+"/"+DamConstants.DC_DESCRIPTION): this.valueMap.get(DamConstants.METADATA_FOLDER+"/"+DamConstants.DC_DESCRIPTION, "");
}
}
/**
* @return the default excerpt for this hit.
* @throws RepositoryException if an error occurs while building the
* excerpt.
*/
private String getExcerpt(String input) {
try{
return null!=input && !"".equals(input) ? this.hit.getExcerpts().get(input):null;
}catch(RepositoryException e){
}catch (Exception e) {
// TODO: handle exception
}
return null;
}
Yogesh
Views
Replies
Total Likes
I use it simply like this:
excerpt = hit.getExcerpt();
But I also tried this hit.getExcerpts() method to get this Map<String, String> and logged it whole, but nothing useful was inside. Just to be sure, I tried yours:
hit.getExcerpts().get(DamConstants.METADATA_FOLDER + "/" + DamConstants.DC_DESCRIPTION);
and unfortunatelly, it's null...
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies