Search in sources :

Example 11 with NodeMetaData

use of org.alfresco.solr.client.NodeMetaData in project SearchServices by Alfresco.

the class AbstractAlfrescoSolrTests method indexTransaction.

public void indexTransaction(Transaction transaction, List<Node> nodes, List<NodeMetaData> nodeMetaDatas) {
    // First map the nodes to a transaction.
    SOLRAPIQueueClient.nodeMap.put(transaction.getId(), nodes);
    // Next map a node to the NodeMetaData
    for (NodeMetaData nodeMetaData : nodeMetaDatas) {
        SOLRAPIQueueClient.nodeMetaDataMap.put(nodeMetaData.getId(), nodeMetaData);
    }
    // Next add the transaction to the queue
    SOLRAPIQueueClient.transactionQueue.add(transaction);
}
Also used : NodeMetaData(org.alfresco.solr.client.NodeMetaData)

Example 12 with NodeMetaData

use of org.alfresco.solr.client.NodeMetaData in project SearchServices by Alfresco.

the class AlfrescoSolrReloadTest method testReload.

@Test
public void testReload() throws Exception {
    long localId = 0L;
    logger.info("######### Starting tracker reload test NODES ###########");
    AclChangeSet aclChangeSet = getAclChangeSet(1, ++localId);
    Acl acl = getAcl(aclChangeSet);
    AclReaders aclReaders = getAclReaders(aclChangeSet, acl, list("joel"), list("phil"), null);
    indexAclChangeSet(aclChangeSet, list(acl), list(aclReaders));
    int numNodes = 1000;
    List<Node> nodes = new ArrayList();
    List<NodeMetaData> nodeMetaDatas = new ArrayList();
    Transaction bigTxn = getTransaction(0, numNodes, ++localId);
    for (int i = 0; i < numNodes; i++) {
        Node node = getNode(bigTxn, acl, Node.SolrApiNodeStatus.UPDATED);
        nodes.add(node);
        NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn, acl, "mike", null, false);
        nodeMetaDatas.add(nodeMetaData);
    }
    indexTransaction(bigTxn, nodes, nodeMetaDatas);
    waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 1000, 100000);
    Collection<Tracker> trackers = getTrackers();
    int numOfTrackers = trackers.size();
    int jobs = getJobsCount();
    reloadAndAssertCorrect(trackers, numOfTrackers, jobs);
    Transaction bigTxn2 = getTransaction(0, numNodes, ++localId);
    for (int i = 0; i < numNodes; i++) {
        Node node = getNode(bigTxn2, acl, Node.SolrApiNodeStatus.UPDATED);
        nodes.add(node);
        NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn2, acl, "mike", null, false);
        nodeMetaDatas.add(nodeMetaData);
    }
    indexTransaction(bigTxn2, nodes, nodeMetaDatas);
    waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 2000, 100000);
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Tracker(org.alfresco.solr.tracker.Tracker) NodeMetaData(org.alfresco.solr.client.NodeMetaData) AlfrescoSolrUtils.getNodeMetaData(org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData) Node(org.alfresco.solr.client.Node) AlfrescoSolrUtils.getNode(org.alfresco.solr.AlfrescoSolrUtils.getNode) ArrayList(java.util.ArrayList) Acl(org.alfresco.solr.client.Acl) AlfrescoSolrUtils.getAcl(org.alfresco.solr.AlfrescoSolrUtils.getAcl) Term(org.apache.lucene.index.Term) Transaction(org.alfresco.solr.client.Transaction) AlfrescoSolrUtils.getTransaction(org.alfresco.solr.AlfrescoSolrUtils.getTransaction) AlfrescoSolrUtils.getAclChangeSet(org.alfresco.solr.AlfrescoSolrUtils.getAclChangeSet) AlfrescoSolrUtils.indexAclChangeSet(org.alfresco.solr.AlfrescoSolrUtils.indexAclChangeSet) AclChangeSet(org.alfresco.solr.client.AclChangeSet) AlfrescoSolrUtils.getAclReaders(org.alfresco.solr.AlfrescoSolrUtils.getAclReaders) AclReaders(org.alfresco.solr.client.AclReaders) Test(org.junit.Test)

Example 13 with NodeMetaData

use of org.alfresco.solr.client.NodeMetaData in project SearchServices by Alfresco.

the class CascadeTracker method processCascades.

private void processCascades() throws IOException {
    // System.out.println("######### processCascades()");
    int num = 50;
    List<Transaction> txBatch = null;
    do {
        try {
            getWriteLock().acquire();
            txBatch = infoSrv.getCascades(num);
            if (txBatch.size() == 0) {
                // No transactions to process for cascades.
                return;
            }
            ArrayList<Long> txIds = new ArrayList<Long>();
            Set<Long> txIdSet = new HashSet<Long>();
            for (Transaction tx : txBatch) {
                txIds.add(tx.getId());
                txIdSet.add(tx.getId());
            }
            List<NodeMetaData> nodeMetaDatas = infoSrv.getCascadeNodes(txIds);
            // System.out.println("########### Cascade node meta datas:"+nodeMetaDatas.size());
            if (nodeMetaDatas.size() > 0) {
                LinkedList<NodeMetaData> stack = new LinkedList<NodeMetaData>();
                stack.addAll(nodeMetaDatas);
                int batchSize = 10;
                do {
                    List<NodeMetaData> batch = new ArrayList<NodeMetaData>();
                    while (batch.size() < batchSize && stack.size() > 0) {
                        batch.add(stack.removeFirst());
                    }
                    CascadeIndexWorkerRunnable worker = new CascadeIndexWorkerRunnable(this.threadHandler, batch, infoSrv);
                    this.threadHandler.scheduleTask(worker);
                } while (stack.size() > 0);
            }
            // Update the transaction records.
            updateTransactionsAfterAsynchronous(txBatch);
        // System.out.println("######################: Finished Cascade Run #########");
        } catch (AuthenticationException e) {
            throw new IOException(e);
        } catch (JSONException e) {
            throw new IOException(e);
        } catch (InterruptedException e) {
            throw new IOException(e);
        } finally {
            // System.out.println("###################: Releasing Cascade write lock");
            getWriteLock().release();
        }
    } while (txBatch.size() > 0);
}
Also used : NodeMetaData(org.alfresco.solr.client.NodeMetaData) AuthenticationException(org.alfresco.httpclient.AuthenticationException) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Transaction(org.alfresco.solr.client.Transaction) HashSet(java.util.HashSet)

Example 14 with NodeMetaData

use of org.alfresco.solr.client.NodeMetaData in project SearchServices by Alfresco.

the class AlfrescoSolrUtils method indexTransaction.

/**
 * @param transaction
 * @param nodes
 * @param nodeMetaDatas
 */
public void indexTransaction(Transaction transaction, List<Node> nodes, List<NodeMetaData> nodeMetaDatas) {
    // First map the nodes to a transaction.
    SOLRAPIQueueClient.nodeMap.put(transaction.getId(), nodes);
    // Next map a node to the NodeMetaData
    for (NodeMetaData nodeMetaData : nodeMetaDatas) {
        SOLRAPIQueueClient.nodeMetaDataMap.put(nodeMetaData.getId(), nodeMetaData);
    }
    // Next add the transaction to the queue
    SOLRAPIQueueClient.transactionQueue.add(transaction);
}
Also used : NodeMetaData(org.alfresco.solr.client.NodeMetaData)

Example 15 with NodeMetaData

use of org.alfresco.solr.client.NodeMetaData in project SearchServices by Alfresco.

the class AlfrescoSolrUtils method getNodeMetaData.

/**
 * Get a nodes meta data.
 * @param node
 * @param txn
 * @param acl
 * @param owner
 * @param ancestors
 * @param createError
 * @return {@link NodeMetaData}
 */
public static NodeMetaData getNodeMetaData(Node node, Transaction txn, Acl acl, String owner, Set<NodeRef> ancestors, boolean createError) {
    NodeMetaData nodeMetaData = new NodeMetaData();
    nodeMetaData.setId(node.getId());
    nodeMetaData.setAclId(acl.getId());
    nodeMetaData.setTxnId(txn.getId());
    nodeMetaData.setOwner(owner);
    nodeMetaData.setAspects(new HashSet<QName>());
    nodeMetaData.setAncestors(ancestors);
    Map<QName, PropertyValue> props = new HashMap<QName, PropertyValue>();
    props.put(ContentModel.PROP_IS_INDEXED, new StringPropertyValue("true"));
    props.put(ContentModel.PROP_CONTENT, new ContentPropertyValue(Locale.US, 0l, "UTF-8", "text/plain", null));
    nodeMetaData.setProperties(props);
    // If create createError is true then we leave out the nodeRef which will cause an error
    if (!createError) {
        NodeRef nodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID());
        nodeMetaData.setNodeRef(nodeRef);
    }
    nodeMetaData.setType(QName.createQName(TEST_NAMESPACE, "testSuperType"));
    nodeMetaData.setAncestors(ancestors);
    nodeMetaData.setPaths(new ArrayList<Pair<String, QName>>());
    nodeMetaData.setNamePaths(new ArrayList<List<String>>());
    return nodeMetaData;
}
Also used : StringPropertyValue(org.alfresco.solr.client.StringPropertyValue) StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeMetaData(org.alfresco.solr.client.NodeMetaData) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) QName(org.alfresco.service.namespace.QName) ContentPropertyValue(org.alfresco.solr.client.ContentPropertyValue) PropertyValue(org.alfresco.solr.client.PropertyValue) StringPropertyValue(org.alfresco.solr.client.StringPropertyValue) ContentPropertyValue(org.alfresco.solr.client.ContentPropertyValue) NodeRef(org.alfresco.service.cmr.repository.NodeRef) List(java.util.List) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) Pair(org.alfresco.util.Pair)

Aggregations

NodeMetaData (org.alfresco.solr.client.NodeMetaData)25 ArrayList (java.util.ArrayList)11 AclChangeSet (org.alfresco.solr.client.AclChangeSet)10 Term (org.apache.lucene.index.Term)10 TermQuery (org.apache.lucene.search.TermQuery)10 Test (org.junit.Test)10 Node (org.alfresco.solr.client.Node)9 Transaction (org.alfresco.solr.client.Transaction)9 AlfrescoSolrUtils.getAcl (org.alfresco.solr.AlfrescoSolrUtils.getAcl)8 AlfrescoSolrUtils.getAclChangeSet (org.alfresco.solr.AlfrescoSolrUtils.getAclChangeSet)8 AlfrescoSolrUtils.getAclReaders (org.alfresco.solr.AlfrescoSolrUtils.getAclReaders)8 AlfrescoSolrUtils.getNode (org.alfresco.solr.AlfrescoSolrUtils.getNode)8 AlfrescoSolrUtils.getNodeMetaData (org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData)8 AlfrescoSolrUtils.getTransaction (org.alfresco.solr.AlfrescoSolrUtils.getTransaction)8 AlfrescoSolrUtils.indexAclChangeSet (org.alfresco.solr.AlfrescoSolrUtils.indexAclChangeSet)8 Acl (org.alfresco.solr.client.Acl)8 AclReaders (org.alfresco.solr.client.AclReaders)8 SolrInputDocument (org.apache.solr.common.SolrInputDocument)8 IOException (java.io.IOException)6 NodeMetaDataParameters (org.alfresco.solr.client.NodeMetaDataParameters)6