Search in sources :

Example 41 with ResultSet

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();
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Example 42 with ResultSet

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();
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeService(org.alfresco.service.cmr.repository.NodeService) ResultSet(org.alfresco.service.cmr.search.ResultSet) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) HashSet(java.util.HashSet)

Example 43 with ResultSet

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;
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) ResultSet(org.alfresco.service.cmr.search.ResultSet) EmptyPagingResults(org.alfresco.query.EmptyPagingResults) TopicInfo(org.alfresco.service.cmr.discussion.TopicInfo)

Example 44 with ResultSet

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();
        }
    }
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) FieldFacet(org.alfresco.service.cmr.search.SearchParameters.FieldFacet) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Example 45 with ResultSet

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();
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResultSet(org.alfresco.service.cmr.search.ResultSet) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) HashSet(java.util.HashSet)

Aggregations

ResultSet (org.alfresco.service.cmr.search.ResultSet)112 NodeRef (org.alfresco.service.cmr.repository.NodeRef)57 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)49 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)22 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)20 Test (org.junit.Test)20 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)17 QName (org.alfresco.service.namespace.QName)16 StoreRef (org.alfresco.service.cmr.repository.StoreRef)14 ResultSetRow (org.alfresco.service.cmr.search.ResultSetRow)14 HashSet (java.util.HashSet)13 EmptyResultSet (org.alfresco.repo.search.EmptyResultSet)13 SearchService (org.alfresco.service.cmr.search.SearchService)13 NodeService (org.alfresco.service.cmr.repository.NodeService)12 IOException (java.io.IOException)11 List (java.util.List)11 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)11 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)10 PagingLuceneResultSet (org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet)10