1 17 package org.alfresco.repo.template; 18 19 import java.util.ArrayList ; 20 import java.util.Collections ; 21 import java.util.List ; 22 23 import org.alfresco.error.AlfrescoRuntimeException; 24 import org.alfresco.service.ServiceRegistry; 25 import org.alfresco.service.cmr.repository.NodeRef; 26 import org.alfresco.service.cmr.repository.TemplateNode; 27 import org.alfresco.service.cmr.search.ResultSet; 28 import org.alfresco.service.cmr.search.ResultSetRow; 29 import org.alfresco.service.cmr.search.SearchService; 30 31 37 public abstract class BaseSearchResultsMap extends BaseTemplateMap 38 { 39 45 public BaseSearchResultsMap(TemplateNode parent, ServiceRegistry services) 46 { 47 super(parent, services); 48 } 49 50 53 protected List <TemplateNode> query(String search) 54 { 55 List <TemplateNode> nodes = null; 56 57 if (search != null && search.length() != 0) 59 { 60 ResultSet results = null; 62 try 63 { 64 results = this.services.getSearchService().query( 65 this.parent.getNodeRef().getStoreRef(), 66 SearchService.LANGUAGE_LUCENE, 67 search); 68 69 if (results.length() != 0) 70 { 71 nodes = new ArrayList <TemplateNode>(results.length()); 72 for (ResultSetRow row: results) 73 { 74 NodeRef nodeRef = row.getNodeRef(); 75 nodes.add(new TemplateNode(nodeRef, services, this.parent.getImageResolver())); 76 } 77 } 78 } 79 catch (Throwable err) 80 { 81 throw new AlfrescoRuntimeException("Failed to execute search: " + search, err); 82 } 83 finally 84 { 85 if (results != null) 86 { 87 results.close(); 88 } 89 } 90 } 91 92 return nodes != null ? nodes : (List )Collections.emptyList(); 93 } 94 } 95 | Popular Tags |