Java Code Examples for org.alfresco.service.cmr.search.SearchParameters#setSinceTxId()

The following examples show how to use org.alfresco.service.cmr.search.SearchParameters#setSinceTxId() . 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: DbOrIndexSwitchingQueryLanguage.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private ResultSet executeHybridQuery(SearchParameters searchParameters)
{        
    if (indexQueryLanguage == null || dbQueryLanguage == null)
    {
        throw new QueryModelException("Both index and DB query language required for hybrid search [index=" +
                                      indexQueryLanguage + ", DB=" + dbQueryLanguage + "]");
    }
    
    StopWatch stopWatch = new StopWatch("hybrid search");
    if (logger.isDebugEnabled())
    {
        logger.debug("Hybrid search, using SOLR query: "+dbQueryLanguage.getName()+" for "+searchParameters);
    }
    stopWatch.start("index query");
    ResultSet indexResults = indexQueryLanguage.executeQuery(searchParameters);
    stopWatch.stop();
    if (logger.isDebugEnabled())
    {
        logger.debug("SOLR query returned " + indexResults.length() + " results in " +
                     stopWatch.getLastTaskTimeMillis() + "ms");
    }
    // TODO: if the results are up-to-date, then nothing more to do - return the results.
    
    if (!(indexResults instanceof SolrJSONResultSet))
    {
        if (logger.isWarnEnabled())
        {
            logger.warn("Hybrid search can only use database when SOLR is also in use. " +
                        "Skipping DB search, returning results from index.");
        }
        return indexResults;            
    }
    
    long lastTxId = ((SolrJSONResultSet) indexResults).getLastIndexedTxId();
    searchParameters.setSinceTxId(lastTxId);
    if(logger.isDebugEnabled())
    {
        logger.debug("Hybrid search, using DB query: "+dbQueryLanguage.getName()+" for "+searchParameters);
    }
    stopWatch.start("database query");
    ResultSet dbResults = dbQueryLanguage.executeQuery(searchParameters);
    stopWatch.stop();
    if (logger.isDebugEnabled())
    {
        logger.debug("DB query returned " + dbResults.length() + " results in " +
                     stopWatch.getLastTaskTimeMillis() + "ms");
    }
    // Merge result sets
    List<ChildAssociationRef> childAssocs = new ArrayList<>();
    NodeParameters nodeParameters = new NodeParameters();
    nodeParameters.setFromTxnId(lastTxId+1);
    // TODO: setToTxnId(null) when SolrDAO behaviour is fixed.
    nodeParameters.setToTxnId(Long.MAX_VALUE);
    stopWatch.start("get changed nodes");
    List<Node> changedNodeList = solrDao.getNodes(nodeParameters, null, null);
    stopWatch.stop();
    if (logger.isDebugEnabled())
    {
        logger.debug("Nodes changed since last indexed transaction (ID " + lastTxId + ") = " +
                     changedNodeList.size() + " (took " + stopWatch.getLastTaskTimeMillis() + "ms)");
    }
    stopWatch.start("merge result sets");
    Set<NodeRef> nodeRefs = new HashSet<>(changedNodeList.size());
    for (Node n : changedNodeList)
    {
        nodeRefs.add(n.getNodeRef());
    }
    // Only use the SOLR results for nodes that haven't changed since indexing.
    for (ChildAssociationRef car : indexResults.getChildAssocRefs())
    {
        if (!nodeRefs.contains(car.getChildRef()))
        {
            childAssocs.add(car);
        }
    }
    // Merge in all the database results.
    childAssocs.addAll(dbResults.getChildAssocRefs());
    
    ResultSet results = new ChildAssocRefResultSet(nodeService, childAssocs);
    stopWatch.stop(); // merge result sets
    if (logger.isDebugEnabled())
    {
        String stats = String.format("SOLR=%d, DB=%d, total=%d",
                    indexResults.length(), dbResults.length(), results.length());
        logger.debug("Hybrid search returning combined results with counts: " + stats);
        logger.debug(stopWatch.prettyPrint());
    }
    return results;
}
 
Example 2
Source File: QueryOptions.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @return SearchParameters
 */
public SearchParameters getAsSearchParmeters()
{
    SearchParameters searchParameters = new SearchParameters();
    searchParameters.setDefaultFieldName(this.getDefaultFieldName());
    searchParameters.setDefaultFTSFieldConnective(this.getDefaultFTSFieldConnective() == Connective.OR ? SearchParameters.Operator.OR : SearchParameters.Operator.AND);
    searchParameters.setDefaultFTSOperator(this.getDefaultFTSConnective() == Connective.OR ? SearchParameters.Operator.OR : SearchParameters.Operator.AND);
    searchParameters.setDefaultOperator(this.getDefaultFTSConnective() == Connective.OR ? SearchParameters.Operator.OR : SearchParameters.Operator.AND);
    searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
    if(this.getMaxItems() > 0)
    {
        searchParameters.setLimit(this.getMaxItems());
        searchParameters.setLimitBy(LimitBy.FINAL_SIZE);
        searchParameters.setMaxItems(this.getMaxItems());
    }
    searchParameters.setMaxPermissionChecks(this.getMaxPermissionChecks());
    searchParameters.setMaxPermissionCheckTimeMillis(this.getMaxPermissionCheckTimeMillis());
    searchParameters.setMlAnalaysisMode(this.getMlAnalaysisMode());
    //searchParameters.setNamespace()   TODO: Fix
    //searchParameters.setPermissionEvaluation()
    searchParameters.setQuery(this.getQuery());
    searchParameters.setSkipCount(this.getSkipCount());
    //searchParameters.addAllAttribute()
    for(Locale locale : this.getLocales())
    {
        searchParameters.addLocale(locale);
    }
    for(QueryParameterDefinition queryParameterDefinition: this.getQueryParameterDefinitions())
    {
        searchParameters.addQueryParameterDefinition(queryParameterDefinition);
    }
    //searchParameters.addQueryTemplate(name, template)
    //searchParameters.addSort()
    for(StoreRef storeRef : this.getStores())
    {
        searchParameters.addStore(storeRef);
    }
    //searchParameters.addTextAttribute()
    searchParameters.setQueryConsistency(this.getQueryConsistency());
    searchParameters.setSinceTxId(getSinceTxId());
    for(String name : getQueryTemplates().keySet())
    {
    	String template = getQueryTemplates().get(name);
    	searchParameters.addQueryTemplate(name, template);
    }
    
    return searchParameters;
}
 
Example 3
Source File: CMISQueryOptions.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @return SearchParameters
 */
public SearchParameters getAsSearchParmeters()
{
    SearchParameters searchParameters = new SearchParameters();
    searchParameters.setDefaultFieldName(this.getDefaultFieldName());
    searchParameters.setDefaultFTSFieldConnective(this.getDefaultFTSFieldConnective() == Connective.OR ? SearchParameters.Operator.OR : SearchParameters.Operator.AND);
    searchParameters.setDefaultFTSOperator(this.getDefaultFTSConnective() == Connective.OR ? SearchParameters.Operator.OR : SearchParameters.Operator.AND);
    searchParameters.setDefaultOperator(this.getDefaultFTSConnective() == Connective.OR ? SearchParameters.Operator.OR : SearchParameters.Operator.AND);
    searchParameters.setLanguage(SearchService.LANGUAGE_CMIS_ALFRESCO);
    if(this.getMaxItems() > 0)
    {
        searchParameters.setLimit(this.getMaxItems());
        searchParameters.setLimitBy(LimitBy.FINAL_SIZE);
        searchParameters.setMaxItems(this.getMaxItems());
    }
    searchParameters.setMaxPermissionChecks(this.getMaxPermissionChecks());
    searchParameters.setMaxPermissionCheckTimeMillis(this.getMaxPermissionCheckTimeMillis());
    searchParameters.setMlAnalaysisMode(this.getMlAnalaysisMode());
    //searchParameters.setNamespace()   TODO: Fix
    //searchParameters.setPermissionEvaluation()
    searchParameters.setQuery(this.getQuery());
    searchParameters.setSkipCount(this.getSkipCount());
    //searchParameters.addAllAttribute()
    for(Locale locale : this.getLocales())
    {
        searchParameters.addLocale(locale);
    }
    for(QueryParameterDefinition queryParameterDefinition: this.getQueryParameterDefinitions())
    {
        searchParameters.addQueryParameterDefinition(queryParameterDefinition);
    }
    //searchParameters.addQueryTemplate(name, template)
    //searchParameters.addSort()
    for(StoreRef storeRef : this.getStores())
    {
        searchParameters.addStore(storeRef);
    }
    //searchParameters.addTextAttribute()
    searchParameters.setBulkFetchEnabled(isBulkFetchEnabled());
    searchParameters.setQueryConsistency(this.getQueryConsistency());
    searchParameters.setSinceTxId(getSinceTxId());
    for(String name : getQueryTemplates().keySet())
    {
    	String template = getQueryTemplates().get(name);
    	searchParameters.addQueryTemplate(name, template);
    }
    return searchParameters;
}