Search in sources :

Example 1 with Node

use of org.alfresco.repo.domain.node.Node in project alfresco-repository by Alfresco.

the class SOLRDAOTest method testGetNodesForStore.

public void testGetNodesForStore() {
    List<Transaction> txns = getTransactions(null, null, null, null, 500);
    List<Long> txnIds = toTxnIds(txns);
    NodeParameters nodeParameters = new NodeParameters();
    nodeParameters.setTransactionIds(txnIds);
    List<Node> nodes = getNodes(nodeParameters);
    assertTrue("Expect 'some' nodes associated with txns", nodes.size() > 0);
}
Also used : Transaction(org.alfresco.repo.solr.Transaction) NodeParameters(org.alfresco.repo.solr.NodeParameters) Node(org.alfresco.repo.domain.node.Node)

Example 2 with Node

use of org.alfresco.repo.domain.node.Node in project alfresco-repository by Alfresco.

the class SOLRDAOTest method testGetNodesSimple.

public void testGetNodesSimple() {
    long startTime = 0L;
    List<Transaction> txns = getTransactions(null, startTime, null, null, 500);
    List<Long> txnIds = toTxnIds(txns);
    NodeParameters nodeParameters = new NodeParameters();
    nodeParameters.setTransactionIds(txnIds);
    nodeParameters.setStoreProtocol(StoreRef.PROTOCOL_WORKSPACE);
    nodeParameters.setStoreIdentifier(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.getIdentifier());
    List<Node> nodes = getNodes(nodeParameters);
    assertTrue("Expect 'some' nodes associated with txns", nodes.size() > 0);
}
Also used : Transaction(org.alfresco.repo.solr.Transaction) NodeParameters(org.alfresco.repo.solr.NodeParameters) Node(org.alfresco.repo.domain.node.Node)

Example 3 with Node

use of org.alfresco.repo.domain.node.Node in project alfresco-repository by Alfresco.

the class SOLRDAOTest method testGetNodesFromTxnId.

/**
 * MNT-12798
 */
public void testGetNodesFromTxnId() {
    final StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.nanoTime());
    try {
        RetryingTransactionCallback<Long> createNodeWork1 = new RetryingTransactionCallback<Long>() {

            @Override
            public Long execute() throws Throwable {
                createTestNode(nodeService.getRootNode(storeRef));
                return nodeDAO.getCurrentTransactionId(true);
            }
        };
        RetryingTransactionCallback<Long> createNodeWork2 = new RetryingTransactionCallback<Long>() {

            @Override
            public Long execute() throws Throwable {
                createTestNode(nodeService.getRootNode(storeRef));
                return nodeDAO.getCurrentTransactionId(true);
            }
        };
        Long txnId1 = transactionService.getRetryingTransactionHelper().doInTransaction(createNodeWork1);
        Long txnId2 = transactionService.getRetryingTransactionHelper().doInTransaction(createNodeWork2);
        NodeParameters nodeParameters = new NodeParameters();
        nodeParameters.setFromTxnId(txnId1);
        nodeParameters.setToTxnId(null);
        List<Node> nodes1 = getNodes(nodeParameters);
        assertTrue("Expect 'some' nodes associated with txns", nodes1.size() > 0);
        NodeParameters nodeParameters2 = new NodeParameters();
        nodeParameters2.setFromTxnId(txnId2);
        nodeParameters2.setToTxnId(null);
        List<Node> nodes2 = getNodes(nodeParameters2);
        assertTrue("Higher 'fromTxnId' param should yield fewer results", nodes2.size() < nodes1.size());
    } finally {
        nodeService.deleteStore(storeRef);
    }
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) NodeParameters(org.alfresco.repo.solr.NodeParameters) Node(org.alfresco.repo.domain.node.Node)

Example 4 with Node

use of org.alfresco.repo.domain.node.Node in project alfresco-repository by Alfresco.

the class DbOrIndexSwitchingQueryLanguage method executeHybridQuery.

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");
    }
    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);
    // merge result sets
    stopWatch.stop();
    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;
}
Also used : NodeParameters(org.alfresco.repo.solr.NodeParameters) Node(org.alfresco.repo.domain.node.Node) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException) ArrayList(java.util.ArrayList) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) StopWatch(org.springframework.util.StopWatch) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResultSet(org.alfresco.service.cmr.search.ResultSet) ChildAssocRefResultSet(org.alfresco.repo.search.results.ChildAssocRefResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) ChildAssocRefResultSet(org.alfresco.repo.search.results.ChildAssocRefResultSet) HashSet(java.util.HashSet)

Example 5 with Node

use of org.alfresco.repo.domain.node.Node in project alfresco-repository by Alfresco.

the class DBQueryEngine method executeQuery.

/*
     * (non-Javadoc)
     * @see
     * org.alfresco.repo.search.impl.querymodel.QueryEngine#executeQuery(org.alfresco.repo.search.impl.querymodel.Query,
     * org.alfresco.repo.search.impl.querymodel.QueryOptions,
     * org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext)
     */
@Override
public QueryEngineResults executeQuery(Query query, QueryOptions options, FunctionEvaluationContext functionContext) {
    Set<String> selectorGroup = null;
    if (query.getSource() != null) {
        List<Set<String>> selectorGroups = query.getSource().getSelectorGroups(functionContext);
        if (selectorGroups.size() == 0) {
            throw new QueryModelException("No selectors");
        }
        if (selectorGroups.size() > 1) {
            throw new QueryModelException("Advanced join is not supported");
        }
        selectorGroup = selectorGroups.get(0);
    }
    HashSet<String> key = new HashSet<String>();
    key.add("");
    Map<Set<String>, ResultSet> answer = new HashMap<Set<String>, ResultSet>();
    DBQuery dbQuery = (DBQuery) query;
    if (options.getStores().size() > 1) {
        throw new QueryModelException("Multi-store queries are not supported");
    }
    // MT
    StoreRef storeRef = options.getStores().get(0);
    storeRef = storeRef != null ? tenantService.getName(storeRef) : null;
    Pair<Long, StoreRef> store = nodeDAO.getStore(storeRef);
    if (store == null) {
        throw new QueryModelException("Unknown store: " + storeRef);
    }
    dbQuery.setStoreId(store.getFirst());
    Pair<Long, QName> sysDeletedType = qnameDAO.getQName(ContentModel.TYPE_DELETED);
    if (sysDeletedType == null) {
        dbQuery.setSysDeletedType(-1L);
    } else {
        dbQuery.setSysDeletedType(sysDeletedType.getFirst());
    }
    Long sinceTxId = options.getSinceTxId();
    if (sinceTxId == null) {
        // By default, return search results for all transactions.
        sinceTxId = -1L;
    }
    dbQuery.setSinceTxId(sinceTxId);
    dbQuery.prepare(namespaceService, dictionaryService, qnameDAO, nodeDAO, tenantService, selectorGroup, null, functionContext, metadataIndexCheck2.getPatchApplied());
    List<Node> nodes = template.selectList(SELECT_BY_DYNAMIC_QUERY, dbQuery);
    LinkedHashSet<Long> set = new LinkedHashSet<Long>(nodes.size());
    for (Node node : nodes) {
        set.add(node.getId());
    }
    List<Long> nodeIds = new ArrayList<Long>(set);
    ResultSet rs = new DBResultSet(options.getAsSearchParmeters(), nodeIds, nodeDAO, nodeService, tenantService, Integer.MAX_VALUE);
    ResultSet paged = new PagingLuceneResultSet(rs, options.getAsSearchParmeters(), nodeService);
    answer.put(key, paged);
    return new QueryEngineResults(answer);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) QueryEngineResults(org.alfresco.repo.search.impl.querymodel.QueryEngineResults) HashSet(java.util.HashSet) PagingLuceneResultSet(org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet) LinkedHashSet(java.util.LinkedHashSet) ResultSet(org.alfresco.service.cmr.search.ResultSet) Set(java.util.Set) HashMap(java.util.HashMap) Node(org.alfresco.repo.domain.node.Node) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException) ArrayList(java.util.ArrayList) PagingLuceneResultSet(org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet) ResultSet(org.alfresco.service.cmr.search.ResultSet) PagingLuceneResultSet(org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) StoreRef(org.alfresco.service.cmr.repository.StoreRef) QName(org.alfresco.service.namespace.QName)

Aggregations

Node (org.alfresco.repo.domain.node.Node)9 NodeParameters (org.alfresco.repo.solr.NodeParameters)5 QName (org.alfresco.service.namespace.QName)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Transaction (org.alfresco.repo.solr.Transaction)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 VisitedNode (org.alfresco.repo.node.db.NodeHierarchyWalker.VisitedNode)2 QueryModelException (org.alfresco.repo.search.impl.querymodel.QueryModelException)2 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 StoreRef (org.alfresco.service.cmr.repository.StoreRef)2 ResultSet (org.alfresco.service.cmr.search.ResultSet)2 Date (java.util.Date)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 MimetypeMap (org.alfresco.repo.content.MimetypeMap)1