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);
}
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);
}
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);
}
}
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;
}
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);
}
Aggregations