Example usage for org.apache.solr.update DeleteUpdateCommand setQuery

List of usage examples for org.apache.solr.update DeleteUpdateCommand setQuery

Introduction

In this page you can find the example usage for org.apache.solr.update DeleteUpdateCommand setQuery.

Prototype

public void setQuery(String query) 

Source Link

Usage

From source file:de.qaware.chronix.solr.compaction.SolrUpdateService.java

License:Apache License

/**
 * Deletes documents identified by the given documents.
 *
 * @param docs the documents// w w  w.j av  a  2 s . c  o m
 * @throws IOException iff something goes wrong
 */
public void delete(Collection<Document> docs) throws IOException {
    DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
    cmd.commitWithin = COMMIT_WITHIN;
    cmd.setFlags(DeleteUpdateCommand.BUFFERING);
    cmd.setQuery("{!terms f=" + ID + "}" + docs.stream().map(it -> it.get(ID)).collect(joining(",")));
    updateProcessor.processDelete(cmd);
}

From source file:de.qaware.chronix.solr.retention.ChronixRetentionHandler.java

License:Apache License

/**
 * Triggers the deletion//from   w w w.  j a  v  a  2s .  c  o  m
 *
 * @param processor - the update processor do process deletions
 * @param req       - the solr query request information
 * @throws Exception
 */
private void deleteOldDocuments(String deletionQuery, UpdateRequestProcessor processor, SolrQueryRequest req)
        throws IOException {
    DeleteUpdateCommand delete = new DeleteUpdateCommand(req);
    delete.setQuery(deletionQuery);
    processor.processDelete(delete);
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

@Override
public void indexNodes(List<Node> nodes, boolean overwrite, boolean cascade) throws IOException, JSONException {
    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest()) {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());

        Map<Long, Node> nodeIdsToNodes = new HashMap<>();
        EnumMap<SolrApiNodeStatus, List<Long>> nodeStatusToNodeIds = new EnumMap<>(SolrApiNodeStatus.class);
        categorizeNodes(nodes, nodeIdsToNodes, nodeStatusToNodeIds);
        List<Long> deletedNodeIds = mapNullToEmptyList(nodeStatusToNodeIds.get(SolrApiNodeStatus.DELETED));
        List<Long> shardDeletedNodeIds = mapNullToEmptyList(
                nodeStatusToNodeIds.get(SolrApiNodeStatus.NON_SHARD_DELETED));
        List<Long> shardUpdatedNodeIds = mapNullToEmptyList(
                nodeStatusToNodeIds.get(SolrApiNodeStatus.NON_SHARD_UPDATED));
        List<Long> unknownNodeIds = mapNullToEmptyList(nodeStatusToNodeIds.get(SolrApiNodeStatus.UNKNOWN));
        List<Long> updatedNodeIds = mapNullToEmptyList(nodeStatusToNodeIds.get(SolrApiNodeStatus.UPDATED));

        if (!deletedNodeIds.isEmpty() || !shardDeletedNodeIds.isEmpty() || !shardUpdatedNodeIds.isEmpty()
                || !unknownNodeIds.isEmpty()) {
            // fix up any secondary paths
            List<NodeMetaData> nodeMetaDatas = new ArrayList<>();

            // For all deleted nodes, fake the node metadata
            for (Long deletedNodeId : deletedNodeIds) {
                Node node = nodeIdsToNodes.get(deletedNodeId);
                NodeMetaData nodeMetaData = createDeletedNodeMetaData(node);
                nodeMetaDatas.add(nodeMetaData);
            }//from  ww w .  j  a va2s  .  c  o m

            if (!unknownNodeIds.isEmpty()) {
                NodeMetaDataParameters nmdp = new NodeMetaDataParameters();
                nmdp.setNodeIds(unknownNodeIds);
                nodeMetaDatas.addAll(repositoryClient.getNodesMetaData(nmdp, Integer.MAX_VALUE));
            }

            for (NodeMetaData nodeMetaData : nodeMetaDatas) {
                Node node = nodeIdsToNodes.get(nodeMetaData.getId());
                if (nodeMetaData.getTxnId() > node.getTxnId()) {
                    // the node has moved on to a later transaction
                    // it will be indexed later
                    continue;
                }

                try {
                    lock(nodeMetaData.getId());

                    solrContentStore.removeDocFromContentStore(nodeMetaData);
                } finally {
                    unlock(nodeMetaData.getId());
                }
            }

            LOGGER.debug("Deleting");
            DeleteUpdateCommand delDocCmd = new DeleteUpdateCommand(request);
            String query = this.cloud.getQuery(FIELD_DBID, OR, deletedNodeIds, shardDeletedNodeIds,
                    shardUpdatedNodeIds, unknownNodeIds);
            delDocCmd.setQuery(query);
            processor.processDelete(delDocCmd);
        }

        if (!updatedNodeIds.isEmpty() || !unknownNodeIds.isEmpty() || !shardUpdatedNodeIds.isEmpty()) {
            LOGGER.info("Updating");
            NodeMetaDataParameters nmdp = new NodeMetaDataParameters();
            List<Long> nodeIds = new LinkedList<>();
            nodeIds.addAll(updatedNodeIds);
            nodeIds.addAll(unknownNodeIds);
            nodeIds.addAll(shardUpdatedNodeIds);
            nmdp.setNodeIds(nodeIds);

            // Fetches bulk metadata
            List<NodeMetaData> nodeMetaDatas = repositoryClient.getNodesMetaData(nmdp, Integer.MAX_VALUE);

            NEXT_NODE: for (NodeMetaData nodeMetaData : nodeMetaDatas) {
                long start = System.nanoTime();

                Node node = nodeIdsToNodes.get(nodeMetaData.getId());
                long nodeId = node.getId();
                try {
                    lock(nodeId);

                    if (nodeMetaData.getTxnId() > node.getTxnId()) {
                        // the node has moved on to a later transaction
                        // it will be indexed later
                        continue;
                    }

                    if (nodeIdsToNodes.get(nodeMetaData.getId())
                            .getStatus() == SolrApiNodeStatus.NON_SHARD_UPDATED) {
                        if (nodeMetaData.getProperties().get(ContentModel.PROP_CASCADE_TX) != null) {
                            indexNonShardCascade(nodeMetaData);
                        }

                        continue;
                    }

                    AddUpdateCommand addDocCmd = new AddUpdateCommand(request);
                    addDocCmd.overwrite = overwrite;

                    // check index control
                    Map<QName, PropertyValue> properties = nodeMetaData.getProperties();
                    StringPropertyValue pValue = (StringPropertyValue) properties
                            .get(ContentModel.PROP_IS_INDEXED);
                    if (pValue != null) {
                        boolean isIndexed = Boolean.valueOf(pValue.getValue());
                        if (!isIndexed) {
                            LOGGER.debug("Clearing unindexed");
                            deleteNode(processor, request, node);

                            SolrInputDocument doc = createNewDoc(nodeMetaData, DOC_TYPE_UNINDEXED_NODE);
                            addDocCmd.solrDoc = doc;
                            if (recordUnindexedNodes) {
                                solrContentStore.storeDocOnSolrContentStore(nodeMetaData, doc);
                                processor.processAdd(addDocCmd);
                            }

                            long end = System.nanoTime();
                            this.trackerStats.addNodeTime(end - start);
                            continue NEXT_NODE;
                        }
                    }

                    // Make sure any unindexed or error doc is removed.
                    deleteNode(processor, request, node);

                    SolrInputDocument doc = createNewDoc(nodeMetaData, DOC_TYPE_NODE);
                    addToNewDocAndCache(nodeMetaData, doc);
                    addDocCmd.solrDoc = doc;
                    processor.processAdd(addDocCmd);

                    long end = System.nanoTime();
                    this.trackerStats.addNodeTime(end - start);
                } finally {
                    unlock(nodeId);
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("SolrInformationServer problem.", e);
        // Bulk version failed, so do one at a time.
        for (Node node : nodes) {
            this.indexNode(node, true);
        }
    } finally {
        if (processor != null) {
            processor.finish();
        }
    }
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

private void deleteNode(UpdateRequestProcessor processor, SolrQueryRequest request, long dbid)
        throws IOException {
    DeleteUpdateCommand delDocCmd = new DeleteUpdateCommand(request);
    delDocCmd.setQuery(FIELD_DBID + ":" + dbid);
    processor.processDelete(delDocCmd);//from  w  ww . j a va2s.c o m
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

private void deleteByQuery(String query) throws IOException {
    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest()) {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());
        DeleteUpdateCommand delDocCmd = new DeleteUpdateCommand(request);
        delDocCmd.setQuery(query);
        processor.processDelete(delDocCmd);
    } finally {//from   w  w  w .  j  av  a 2  s . com
        if (processor != null) {
            processor.finish();
        }
    }
}