当前位置: 首页>>代码示例>>Java>>正文


Java SearchParameters.addSort方法代码示例

本文整理汇总了Java中org.alfresco.service.cmr.search.SearchParameters.addSort方法的典型用法代码示例。如果您正苦于以下问题:Java SearchParameters.addSort方法的具体用法?Java SearchParameters.addSort怎么用?Java SearchParameters.addSort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.alfresco.service.cmr.search.SearchParameters的用法示例。


在下文中一共展示了SearchParameters.addSort方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: query

import org.alfresco.service.cmr.search.SearchParameters; //导入方法依赖的package包/类
/**
 * Execute the query
 * 
 * Removes any duplicates that may be present (ID search can cause duplicates -
 * it is better to remove them here)
 * 
 * @param store         StoreRef to search against - null for default configured store
 * @param search        Lucene search to execute
 * @param sort          Columns to sort by
 * @param language      Search language to use e.g. SearchService.LANGUAGE_LUCENE
 * @param maxResults    Maximum results to return if > 0
 * @param skipResults   Results to skip in the result set
 * 
 * @return Array of Node objects
 */
protected Object[] query(String store, String search, SortColumn[] sort, String language, int maxResults, int skipResults)
{   
    SearchParameters sp = new SearchParameters();
    sp.addStore(store != null ? new StoreRef(store) : this.storeRef);
    sp.setLanguage(language != null ? language : SearchService.LANGUAGE_LUCENE);
    sp.setQuery(search);
    if (maxResults > 0)
    {
        sp.setLimit(maxResults);
        sp.setLimitBy(LimitBy.FINAL_SIZE);
    }
    if (skipResults > 0)
    {
        sp.setSkipCount(skipResults);
    }
    if (sort != null)
    {
        for (SortColumn sd : sort)
        {
            sp.addSort(sd.column, sd.asc);
        }
    }
    
    return query(sp, true);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:41,代码来源:Search.java

示例2: applyDecorations

import org.alfresco.service.cmr.search.SearchParameters; //导入方法依赖的package包/类
@Override
protected SearchParameters applyDecorations(ActualEnvironment environment, SearchParameters searchParameters,
            VirtualQuery query)
{
    SearchParameters searchParametersCopy = searchParameters.copy();
    for (Pair<QName, Boolean> sort : sortProps)
    {
        if (!IGNORED_SORT_PROPERTIES.contains(sort.getFirst()))
        {
            SortDefinition sortDefinition = new SortDefinition(SortType.FIELD,
                                                               sort.getFirst().getLocalName(),
                                                               sort.getSecond());
            searchParametersCopy.addSort(sortDefinition);
        }
    }
    return searchParametersCopy;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:18,代码来源:SortConstraint.java

示例3: fromSort

import org.alfresco.service.cmr.search.SearchParameters; //导入方法依赖的package包/类
/**
 * SearchParameters from List<SortDef>
 * @param sp SearchParameters
 * @param sort List<SortDef>
 */
public void fromSort(SearchParameters sp, List<SortDef> sort)
{
    if (sort != null && !sort.isEmpty())
    {
        if (LANGUAGE_CMIS_ALFRESCO.equals(sp.getLanguage()))
        {
            throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
                        new Object[] { ": sort {} not allowed with cmis language" });
        }
        for (SortDef sortDef:sort)
        {

            try
            {
                SortType sortType = SortType.valueOf(sortDef.getType());
                String field = sortDef.getField();
                sp.addSort(new SortDefinition(sortType, field, sortDef.isAscending()));
            }
            catch (IllegalArgumentException e)
            {
                throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { sortDef.getType() });
            }
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:31,代码来源:SearchMapper.java

示例4: addSortOrder

import org.alfresco.service.cmr.search.SearchParameters; //导入方法依赖的package包/类
/**
 * Adds sort order to the SearchParameters.
 */
protected void addSortOrder(Parameters parameters, Map<String, QName> sortParamsToQNames,
    List<SortColumn> defaultSortCols, SearchParameters sp)
{
    List<SortColumn> sortCols = getSorting(parameters, defaultSortCols);
    for (SortColumn sortCol : sortCols)
    {
        QName sortPropQName = sortParamsToQNames.get(sortCol.column);
        if (sortPropQName == null)
        {
            throw new InvalidArgumentException("Invalid sort field: "+sortCol.column);
        }
        sp.addSort("@" + sortPropQName,  sortCol.asc);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:18,代码来源:QueriesImpl.java

示例5: getChildren

import org.alfresco.service.cmr.search.SearchParameters; //导入方法依赖的package包/类
private Collection<ChildAssociationRef> getChildren(NodeRef categoryRef, Mode mode, Depth depth, boolean sortByName, String filter, int fetchSize)
{
    if (categoryRef == null)
    {
        return Collections.<ChildAssociationRef> emptyList();
    }
    
    categoryRef = tenantService.getBaseName(categoryRef); // for solr
    
    ResultSet resultSet = null;
    try
    {
        StringBuilder luceneQuery = new StringBuilder(64);

        switch (mode)
        {
        case ALL:
            luceneQuery.append("PATH:\"");
            luceneQuery.append(buildXPath(nodeService.getPath(categoryRef))).append("/");
            if (depth.equals(Depth.ANY))
            {
                luceneQuery.append("/");
            }
            luceneQuery.append("*").append("\" ");
            break;
        case MEMBERS:
            luceneQuery.append("PATH:\"");
            luceneQuery.append(buildXPath(nodeService.getPath(categoryRef))).append("/");
            if (depth.equals(Depth.ANY))
            {
                luceneQuery.append("/");
            }
            luceneQuery.append("member").append("\" ");
            break;
        case SUB_CATEGORIES:
            luceneQuery.append("+PATH:\"");
            luceneQuery.append(buildXPath(nodeService.getPath(categoryRef))).append("/");
            if (depth.equals(Depth.ANY))
            {
                luceneQuery.append("/");
            }
            luceneQuery.append("*").append("\" ");
            luceneQuery.append("+TYPE:\"" + ContentModel.TYPE_CATEGORY.toString() + "\"");
            break;
        }
        if (filter != null)
        {
            luceneQuery.append(" " + "[email protected]\\:name:\"*" + filter + "*\"");
        }

        // Get a searcher that will include Categories added in this transaction
        SearchService searcher = indexerAndSearcher.getSearcher(categoryRef.getStoreRef(), true);
        
        // Perform the search
        SearchParameters searchParameters = new SearchParameters();
        resultSet = searcher.query(categoryRef.getStoreRef(), "lucene", luceneQuery.toString(), null);
        searchParameters.setLanguage("lucene");
        if(sortByName)
        {
        	searchParameters.addSort("@" + ContentModel.PROP_NAME, true);
        }
        searchParameters.setQuery(luceneQuery.toString());
        searchParameters.setLimit(-1);
        searchParameters.setMaxItems(fetchSize);
        searchParameters.setLimitBy(LimitBy.FINAL_SIZE);
        searchParameters.addStore(categoryRef.getStoreRef());
        resultSet = searcher.query(searchParameters);

        // Convert from search results to the required Child Assocs
        return resultSetToChildAssocCollection(resultSet);
    }
    finally
    {
        if (resultSet != null)
        {
            resultSet.close();
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:80,代码来源:LuceneCategoryServiceImpl.java

示例6: findBlogPosts

import org.alfresco.service.cmr.search.SearchParameters; //导入方法依赖的package包/类
@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;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:81,代码来源:BlogServiceImpl.java

示例7: findLinks

import org.alfresco.service.cmr.search.SearchParameters; //导入方法依赖的package包/类
@Override
public PagingResults<LinkInfo> findLinks(String siteShortName, String user,
      Date from, Date to, String tag, PagingRequest paging) 
{
   NodeRef container = getSiteLinksContainer(siteShortName, false);
   if (container == null)
   {
      // No links
      return new EmptyPagingResults<LinkInfo>();
   }
   
   // Build the query
   StringBuilder luceneQuery = new StringBuilder();
   luceneQuery.append(" +TYPE:\"" + LinksModel.TYPE_LINK + "\"");
   luceneQuery.append(" +PATH:\"" + nodeService.getPath(container).toPrefixString(namespaceService) + "/*\"");

   if (user != null)
   {
      luceneQuery.append(" [email protected]\\:creator:\"" + user + "\"");
   }
   if (from != null && to != null)
   {
      luceneQuery.append(LuceneUtils.createDateRangeQuery(
            from, to, ContentModel.PROP_CREATED, dictionaryService, namespaceService));
   }
   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(container.getStoreRef());
   sp.setLanguage(SearchService.LANGUAGE_LUCENE);
   sp.setQuery(luceneQuery.toString());
   sp.addSort(sortOn, false);
   if (paging.getSkipCount() > 0)
   {
       sp.setSkipCount(paging.getSkipCount());
   }
   
   
   // Build the results
   PagingResults<LinkInfo> pagedResults = new EmptyPagingResults<LinkInfo>();
   ResultSet results = null;
   
   try 
   {
      results = searchService.query(sp);
      pagedResults = wrap(results, container, paging);
   }
   finally
   {
      if (results != null)
      {
         results.close();
      }
   }
   
   return pagedResults;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:64,代码来源:LinksServiceImpl.java

示例8: reindexMissingContent

import org.alfresco.service.cmr.search.SearchParameters; //导入方法依赖的package包/类
/**
 * @param storeRef the store to check for missing content
 * @return Returns the number of documents reindexed
 */
private int reindexMissingContent(StoreRef storeRef)
{
    SearchParameters sp = new SearchParameters();
    sp.addStore(storeRef);

    // search for it in the index, sorting with youngest first
    sp.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp.setQuery(
            "TEXT:" + AbstractLuceneIndexerImpl.NOT_INDEXED_CONTENT_MISSING +
            " TEXT: " + AbstractLuceneIndexerImpl.NOT_INDEXED_TRANSFORMATION_FAILED +
            " TEXT: " + AbstractLuceneIndexerImpl.NOT_INDEXED_NO_TRANSFORMATION);
    sp.addSort(SearchParameters.SORT_IN_DOCUMENT_ORDER_DESCENDING);
    ResultSet results = null;
    try
    {
        results = searcher.query(sp);
        
        int count = 0;
        // iterate over the nodes and prompt for reindexing
        for (ResultSetRow row : results)
        {
            final NodeRef childNodeRef = row.getNodeRef();
            // prompt for a reindex - it might fail again, but we just keep plugging away
            RetryingTransactionCallback<Object> reindexWork = new RetryingTransactionCallback<Object>()
            {
                public Object execute()
                {
                    indexer.updateNode(childNodeRef);
                    return null;
                }
            };
            transactionService.getRetryingTransactionHelper().doInTransaction(reindexWork, true);
            count++;
            // check if we have to break out
            if (isShuttingDown())
            {
                break;
            }
        }
        // done
        if (logger.isDebugEnabled())
        {
            logger.debug(
                    "Reindexed missing content: \n" +
                    "   store: " + storeRef + "\n" +
                    "   node count: " + count);
        }
        return count;
    }
    finally
    {
        if (results != null)
        {
            results.close();
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:62,代码来源:MissingContentReindexComponent.java

示例9: findTopics

import org.alfresco.service.cmr.search.SearchParameters; //导入方法依赖的package包/类
@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(" [email protected]\\: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;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:52,代码来源:DiscussionServiceImpl.java

示例10: doSearch

import org.alfresco.service.cmr.search.SearchParameters; //导入方法依赖的package包/类
/**
 * Do the actual search
 * 
 * @param searchQuery Pair with query string in first and query language in second
 * @param sortAscending boolean
 * @param paging PagingRequest
 */
protected PagingResults<TopicInfo> doSearch(Pair<String, String> searchQuery, boolean sortAscending, PagingRequest paging)
{
   ResultSet resultSet = null;
   PagingResults<TopicInfo> pagedResults = new EmptyPagingResults<TopicInfo>();

   String sortOn = "@{http://www.alfresco.org/model/content/1.0}created";

   // Setup the search parameters
   SearchParameters sp = new SearchParameters();
   sp.addStore(SPACES_STORE);
   sp.setQuery(searchQuery.getFirst());
   sp.setLanguage(searchQuery.getSecond());
   sp.addSort(sortOn, sortAscending);
   if (paging.getMaxItems() > 0)
   {
      //Multiply maxItems by 10.  This is to catch topics that have multiple replies and ensure that the maximum number of topics is shown.
      sp.setLimit(paging.getMaxItems()*10);
      sp.setLimitBy(LimitBy.FINAL_SIZE);
   }
   if (paging.getSkipCount() > 0)
   {
      sp.setSkipCount(paging.getSkipCount());
   }

   try
   {
      resultSet = searchService.query(sp);
      pagedResults = wrap(resultSet, paging);
   }
   finally
   {
      try
      {
         resultSet.close();
      }
      catch(Exception e)
      {
         //do nothing
      }
   }

   return pagedResults;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:51,代码来源:ForumTopicsFilteredGet.java

示例11: findLinks

import org.alfresco.service.cmr.search.SearchParameters; //导入方法依赖的package包/类
public CollectionWithPagingInfo<QuickShareLink> findLinks(Parameters parameters)
{
    checkEnabled();

    String queryString =
            "ASPECT:\"" + QuickShareModel.ASPECT_QSHARE.toString() + "\"";

    SearchParameters sp = new SearchParameters();

    // note: REST API query parameter (ie. where clause filter) - not to be confused with search query ;-)
    Query q = parameters.getQuery();
    if (q != null)
    {
        // filtering via "where" clause
        MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(FIND_SHARED_LINKS_QUERY_PROPERTIES, null);
        QueryHelper.walk(q, propertyWalker);

        String sharedByUserId = propertyWalker.getProperty(PARAM_SHAREDBY, WhereClauseParser.EQUALS, String.class);

        if (sharedByUserId != null)
        {
            if (People.DEFAULT_USER.equalsIgnoreCase(sharedByUserId))
            {
                sharedByUserId =  AuthenticationUtil.getFullyAuthenticatedUser();
            }

            QueryParameterDefinition qpd = new QueryParameterDefImpl(QuickShareModel.PROP_QSHARE_SHAREDBY, dictionaryService.getDataType(DataTypeDefinition.TEXT),
                    true, sharedByUserId);
            sp.addQueryParameterDefinition(qpd);

            String qsharedBy = QuickShareModel.PROP_QSHARE_SHAREDBY.toPrefixString(namespaceService);
            queryString += " [email protected]"+SearchLanguageConversion.escapeLuceneQuery(qsharedBy)+":\"${"+qsharedBy+"}\"";
        }
    }

    sp.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp.setQuery(queryString);
    sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);

    Paging paging = parameters.getPaging();
    PagingRequest pagingRequest = Util.getPagingRequest(paging);

    sp.setSkipCount(pagingRequest.getSkipCount());
    sp.setMaxItems(pagingRequest.getMaxItems());

    sp.addSort("@" + ContentModel.PROP_MODIFIED, false);

    ResultSet results = searchService.query(sp);

    List<QuickShareLink> qsLinks = new ArrayList<>(results.length());

    List<String> includeParam = parameters.getInclude();

    for (ResultSetRow row : results)
    {
        NodeRef nodeRef = row.getNodeRef();
        qsLinks.add(getQuickShareInfo(nodeRef, false, includeParam));
    }

    results.close();

    return CollectionWithPagingInfo.asPaged(paging, qsLinks, results.hasMore(), new Long(results.getNumberFound()).intValue());
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:64,代码来源:QuickShareLinksImpl.java


注:本文中的org.alfresco.service.cmr.search.SearchParameters.addSort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。