use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class TaggingServiceImpl method findTaggedNodes.
/**
* @see org.alfresco.service.cmr.tagging.TaggingService#findTaggedNodes(StoreRef, java.lang.String)
*/
public List<NodeRef> findTaggedNodes(StoreRef storeRef, String tag) {
// Lower the case of the tag
tag = tag.toLowerCase();
ResultSet resultSet = null;
try {
// Do the search for nodes
resultSet = this.searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "+PATH:\"/cm:taggable/cm:" + ISO9075.encode(tag) + "/member\"");
List<NodeRef> nodeRefs = resultSet.getNodeRefs();
return nodeRefs;
} finally {
if (resultSet != null) {
resultSet.close();
}
}
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class BaseSearchResultsMap method query.
/**
* Perform a SearchService query with the given Lucene search string
*/
protected List<TemplateNode> query(String search) {
List<TemplateNode> nodes = null;
HashSet<NodeRef> nodeRefs = new HashSet<NodeRef>();
// check if a full Lucene search string has been supplied or extracted from XML
if (search != null && search.length() != 0) {
// perform the search against the repo
ResultSet results = null;
try {
results = this.services.getSearchService().query(this.parent.getNodeRef().getStoreRef(), SearchService.LANGUAGE_LUCENE, search);
if (results.length() != 0) {
NodeService nodeService = this.services.getNodeService();
nodes = new ArrayList<TemplateNode>(results.length());
for (ResultSetRow row : results) {
NodeRef nodeRef = row.getNodeRef();
if (!nodeRefs.contains(nodeRef) && (nodeService.exists(nodeRef))) {
nodes.add(new TemplateNode(nodeRef, services, this.parent.getImageResolver()));
nodeRefs.add(nodeRef);
}
}
}
} catch (Throwable err) {
throw new AlfrescoRuntimeException("Failed to execute search: " + search, err);
} finally {
if (results != null) {
results.close();
}
}
}
return nodes != null ? nodes : (List) Collections.emptyList();
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class DiscussionServiceImpl method findTopics.
@Override
public PagingResults<TopicInfo> findTopics(NodeRef nodeRef, String username, String tag, boolean sortAscending, PagingRequest paging) {
// Build the query
StringBuilder luceneQuery = new StringBuilder();
luceneQuery.append(" +TYPE:\"" + ForumModel.TYPE_TOPIC + "\"");
luceneQuery.append(" +PATH:\"" + nodeService.getPath(nodeRef).toPrefixString(namespaceService) + "/*\"");
if (username != null) {
luceneQuery.append(" +@cm\\:creator:\"" + username + "\"");
}
if (tag != null) {
luceneQuery.append(" +PATH:\"/cm:taggable/cm:" + ISO9075.encode(tag) + "/member\"");
}
String sortOn = "@{http://www.alfresco.org/model/content/1.0}created";
// Query
SearchParameters sp = new SearchParameters();
sp.addStore(nodeRef.getStoreRef());
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery(luceneQuery.toString());
sp.addSort(sortOn, sortAscending);
if (paging.getSkipCount() > 0) {
sp.setSkipCount(paging.getSkipCount());
}
// Build the results
PagingResults<TopicInfo> pagedResults = new EmptyPagingResults<TopicInfo>();
ResultSet results = null;
try {
results = searchService.query(sp);
pagedResults = wrap(results, nodeRef, paging);
} finally {
if (results != null) {
results.close();
}
}
return pagedResults;
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class TaggingServiceImpl method findTaggedNodesAndCountByTagName.
/**
* @see org.alfresco.service.cmr.tagging.TaggingService#findTaggedNodesAndCountByTagName(StoreRef)
*/
@Override
public List<Pair<String, Integer>> findTaggedNodesAndCountByTagName(StoreRef storeRef) {
String queryTaggeble = "ASPECT:\"" + ContentModel.ASPECT_TAGGABLE + "\"" + "-ASPECT:\"" + ContentModel.ASPECT_WORKING_COPY + "\"";
SearchParameters sp = new SearchParameters();
sp.setQuery(queryTaggeble);
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.addStore(storeRef);
sp.addFieldFacet(new FieldFacet("TAG"));
ResultSet resultSet = null;
try {
// Do the search for nodes
resultSet = this.searchService.query(sp);
return resultSet.getFieldFacet("TAG");
} finally {
if (resultSet != null) {
resultSet.close();
}
}
}
use of org.alfresco.service.cmr.search.ResultSet in project alfresco-repository by Alfresco.
the class DBQueryTest method queryWithCount.
public void queryWithCount(String ql, String query, int count, QName property, Boolean ascending) {
SearchParameters sp = new SearchParameters();
sp.setLanguage(ql);
sp.setQueryConsistency(QueryConsistency.TRANSACTIONAL);
sp.setQuery(query);
sp.addStore(rootNodeRef.getStoreRef());
ResultSet results = serviceRegistry.getSearchService().query(sp);
HashSet<NodeRef> found = new HashSet<NodeRef>();
Comparable last = null;
for (ResultSetRow row : results) {
assertFalse(found.contains(row.getNodeRef()));
found.add(row.getNodeRef());
if (property != null) {
Comparable current = (Comparable) nodeService.getProperty(row.getNodeRef(), property);
if (last != null) {
if ((ascending == null) || (ascending)) {
assert (last.compareTo(current) >= 0);
} else {
assert (last.compareTo(current) <= 0);
}
}
last = current;
}
}
assertEquals(count, results.length());
results.getResultSetMetaData();
results.close();
}
Aggregations