Java Code Examples for org.alfresco.service.cmr.search.ResultSet#getNumberFound()

The following examples show how to use org.alfresco.service.cmr.search.ResultSet#getNumberFound() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DetachedResultSet.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Detached result set based on that provided
 * @param resultSet ResultSet
 */
public DetachedResultSet(ResultSet resultSet)
{
    super();
    rsmd = resultSet.getResultSetMetaData();
    rows = new ArrayList<ResultSetRow>(resultSet.length());
    for (ResultSetRow row : resultSet)
    {
        rows.add(new DetachedResultSetRow(this, row));
    }
    numberFound = resultSet.getNumberFound();
}
 
Example 2
Source File: CMISResultSet.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public long getNumberFound()
{
    for (ResultSet resultSet : wrapped.values())
    {
        return resultSet.getNumberFound();
    }
    throw new IllegalStateException();
}
 
Example 3
Source File: ResultMapper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Sets the total number found.
 * @param results
 * @return An integer total
 */
public Integer setTotal(ResultSet results)
{
    Long totalItems = results.getNumberFound();
    Integer total = totalItems.intValue();
    return total;
}
 
Example 4
Source File: ResultMapperTests.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testToCollectionWithPagingInfo() throws Exception
{
    ResultSet results = mockResultset(Arrays.asList(514l), Arrays.asList(566l, VERSIONED_ID));
    SearchRequestContext searchRequest = SearchRequestContext.from(SearchQuery.EMPTY);
    CollectionWithPagingInfo<Node> collectionWithPage =  mapper.toCollectionWithPagingInfo(EMPTY_PARAMS, searchRequest, SearchQuery.EMPTY, results);
    assertNotNull(collectionWithPage);
    Long found = results.getNumberFound();
    assertEquals(found.intValue(), collectionWithPage.getTotalItems().intValue());
    Node firstNode = collectionWithPage.getCollection().stream().findFirst().get();
    assertNotNull(firstNode.getSearch().getScore());
    assertEquals(StoreMapper.LIVE_NODES, firstNode.getLocation());
    collectionWithPage.getCollection().stream().forEach(aNode -> {
        List<HighlightEntry> high = aNode.getSearch().getHighlight();
        if (high != null)
        {
            assertEquals(2, high.size());
            HighlightEntry first = high.get(0);
            assertNotNull(first.getField());
            assertNotNull(first.getSnippets());
        }
    });
    //1 deleted node in the test data
    assertEquals(1l, collectionWithPage.getCollection().stream().filter(node -> StoreMapper.DELETED.equals(node.getLocation())).count());

    //1 version nodes in the test data (and 1 is not shown because it is in the archive store)
    assertEquals(1l, collectionWithPage.getCollection().stream().filter(node -> StoreMapper.VERSIONS.equals(node.getLocation())).count());
}
 
Example 5
Source File: BlogServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public PagingResults<BlogPostInfo> findBlogPosts(
      final NodeRef blogContainerNode, final RangedDateProperty dateRange, 
      final String tag, final PagingRequest pagingReq)
{
    StringBuilder luceneQuery = new StringBuilder();
    luceneQuery.append("+TYPE:\"").append(ContentModel.TYPE_CONTENT).append("\" ")
               .append("+PARENT:\"").append(blogContainerNode.toString()).append("\" ");
    if (tag != null && !tag.trim().isEmpty())
    {
        luceneQuery.append("+PATH:\"/cm:taggable/cm:").append(ISO9075.encode(tag)).append("/member\"");
    }
    if (dateRange != null)
    {
        luceneQuery.append(createDateRangeQuery(dateRange.getFromDate(), dateRange.getToDate(), dateRange.getDateProperty()));
    }

    SearchParameters sp = new SearchParameters();
    sp.addStore(blogContainerNode.getStoreRef());
    sp.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp.setQuery(luceneQuery.toString());
    sp.addSort(ContentModel.PROP_PUBLISHED.toString(), false);

    sp.setMaxItems(pagingReq.getMaxItems() * MIN_NUMBER_OF_PAGES_FOR_THE_USER_TO_LOOP_THROUGH); 
    sp.setSkipCount(pagingReq.getSkipCount());
    ResultSet luceneResults = null;
    PagingResults<BlogPostInfo> results = null;
    try
    {
        luceneResults = searchService.query(sp);
        final ResultSet finalLuceneResults = luceneResults;
        
        final List<NodeRef> nodeRefs = finalLuceneResults.getNodeRefs().subList(0, min(pagingReq.getMaxItems(), finalLuceneResults.length()));
        
        results = new PagingResults<BlogPostInfo>()
        {
            
            @Override
            public List<BlogPostInfo> getPage()
            {
                List<BlogPostInfo> blogPostInfos = new ArrayList<BlogPostInfo>(nodeRefs.size());
                for (NodeRef nodeRef : nodeRefs)
                {
                    String postName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); 
                    blogPostInfos.add(new BlogPostInfoImpl(nodeRef, blogContainerNode, postName));
                }
                return blogPostInfos;
            }
            
            @Override
            public String getQueryExecutionId()
            {
                return null;
            }
            
            @Override
            public Pair<Integer, Integer> getTotalResultCount()
            { 
                long totalResultCount = finalLuceneResults.getNumberFound();
                /*if (finalLuceneResults.hasMore()){
                    totalResultCount++;
                }*/ 
                return new Pair<Integer, Integer>((int)totalResultCount, (int)totalResultCount);
            }
            
            @Override
            public boolean hasMoreItems()
            {
                return finalLuceneResults.length() > pagingReq.getMaxItems();
            }
        };
    }
    finally
    {
        if (luceneResults != null) luceneResults.close();
    }
    
    
    return results;
}
 
Example 6
Source File: VirtualQueryImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private PagingResults<Reference> asPagingResults(ActualEnvironment environment, PagingRequest pagingRequest,
            ResultSet result, Reference parentReference) throws ActualEnvironmentException
{
    final List<Reference> page = new LinkedList<Reference>();

    for (ResultSetRow row : result)
    {
        page.add(NodeProtocol.newReference(row.getNodeRef(),
                                           parentReference));
    }

    final boolean hasMore = result.hasMore();
    final int totalFirst = (int) result.getNumberFound();
    int start;
    try
    {
        start = result.getStart();
    }
    catch (UnsupportedOperationException e)
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("Unsupported ResultSet.getStart() when trying to create query paging result");
        }
        if (pagingRequest != null)
        {
            start = pagingRequest.getSkipCount();
        }
        else
        {
            start = 0;
        }
    }
    final int totlaSecond = !hasMore ? (int) result.getNumberFound() : (int) (start + result.getNumberFound() + 1);
    final Pair<Integer, Integer> total = new Pair<Integer, Integer>(totalFirst,
                                                                    totlaSecond);
    return new PagingResults<Reference>()
    {

        @Override
        public List<Reference> getPage()
        {
            return page;
        }

        @Override
        public boolean hasMoreItems()
        {
            return hasMore;
        }

        @Override
        public Pair<Integer, Integer> getTotalResultCount()
        {

            return total;
        }

        @Override
        public String getQueryExecutionId()
        {
            return null;
        }

    };
}