Search in sources :

Example 46 with CharsRefBuilder

use of org.apache.lucene.util.CharsRefBuilder in project lucene-solr by apache.

the class DistributedUpdateProcessor method processDelete.

@Override
public void processDelete(DeleteUpdateCommand cmd) throws IOException {
    assert TestInjection.injectFailUpdateRequests();
    updateCommand = cmd;
    if (!cmd.isDeleteById()) {
        doDeleteByQuery(cmd);
        return;
    }
    if (zkEnabled) {
        zkCheck();
        nodes = setupRequest(cmd.getId(), null, cmd.getRoute());
    } else {
        isLeader = getNonZkLeaderAssumption(req);
    }
    boolean dropCmd = false;
    if (!forwardToLeader) {
        dropCmd = versionDelete(cmd);
    }
    if (dropCmd) {
        // TODO: do we need to add anything to the response?
        return;
    }
    if (zkEnabled && isLeader && !isSubShardLeader) {
        DocCollection coll = zkController.getClusterState().getCollection(collection);
        List<Node> subShardLeaders = getSubShardLeaders(coll, cloudDesc.getShardId(), cmd.getId(), null);
        // the list<node> will actually have only one element for an add request
        if (subShardLeaders != null && !subShardLeaders.isEmpty()) {
            ModifiableSolrParams params = new ModifiableSolrParams(filterParams(req.getParams()));
            params.set(DISTRIB_UPDATE_PARAM, DistribPhase.FROMLEADER.toString());
            params.set(DISTRIB_FROM, ZkCoreNodeProps.getCoreUrl(zkController.getBaseUrl(), req.getCore().getName()));
            params.set(DISTRIB_FROM_PARENT, cloudDesc.getShardId());
            cmdDistrib.distribDelete(cmd, subShardLeaders, params, true);
        }
        final List<Node> nodesByRoutingRules = getNodesByRoutingRules(zkController.getClusterState(), coll, cmd.getId(), null);
        if (nodesByRoutingRules != null && !nodesByRoutingRules.isEmpty()) {
            ModifiableSolrParams params = new ModifiableSolrParams(filterParams(req.getParams()));
            params.set(DISTRIB_UPDATE_PARAM, DistribPhase.FROMLEADER.toString());
            params.set(DISTRIB_FROM, ZkCoreNodeProps.getCoreUrl(zkController.getBaseUrl(), req.getCore().getName()));
            params.set(DISTRIB_FROM_COLLECTION, req.getCore().getCoreDescriptor().getCloudDescriptor().getCollectionName());
            params.set(DISTRIB_FROM_SHARD, req.getCore().getCoreDescriptor().getCloudDescriptor().getShardId());
            for (Node nodesByRoutingRule : nodesByRoutingRules) {
                cmdDistrib.distribDelete(cmd, Collections.singletonList(nodesByRoutingRule), params, true);
            }
        }
    }
    ModifiableSolrParams params = null;
    if (nodes != null) {
        params = new ModifiableSolrParams(filterParams(req.getParams()));
        params.set(DISTRIB_UPDATE_PARAM, (isLeader || isSubShardLeader ? DistribPhase.FROMLEADER.toString() : DistribPhase.TOLEADER.toString()));
        params.set(DISTRIB_FROM, ZkCoreNodeProps.getCoreUrl(zkController.getBaseUrl(), req.getCore().getName()));
        cmdDistrib.distribDelete(cmd, nodes, params);
    }
    // TODO: what to do when no idField?
    if (returnVersions && rsp != null && cmd.getIndexedId() != null && idField != null) {
        if (deleteResponse == null) {
            deleteResponse = new NamedList<String>(1);
            rsp.add("deletes", deleteResponse);
        }
        if (scratch == null)
            scratch = new CharsRefBuilder();
        idField.getType().indexedToReadable(cmd.getIndexedId(), scratch);
        // we're returning the version of the delete.. not the version of the doc we deleted.
        deleteResponse.add(scratch.toString(), cmd.getVersion());
    }
}
Also used : RetryNode(org.apache.solr.update.SolrCmdDistributor.RetryNode) Node(org.apache.solr.update.SolrCmdDistributor.Node) StdNode(org.apache.solr.update.SolrCmdDistributor.StdNode) DocCollection(org.apache.solr.common.cloud.DocCollection) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 47 with CharsRefBuilder

use of org.apache.lucene.util.CharsRefBuilder in project lucene-solr by apache.

the class TestSynonymMapFilter method add.

private void add(String input, String output, boolean keepOrig) {
    if (VERBOSE) {
        System.out.println("  add input=" + input + " output=" + output + " keepOrig=" + keepOrig);
    }
    CharsRefBuilder inputCharsRef = new CharsRefBuilder();
    SynonymMap.Builder.join(input.split(" +"), inputCharsRef);
    CharsRefBuilder outputCharsRef = new CharsRefBuilder();
    SynonymMap.Builder.join(output.split(" +"), outputCharsRef);
    b.add(inputCharsRef.get(), outputCharsRef.get(), keepOrig);
}
Also used : CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder)

Example 48 with CharsRefBuilder

use of org.apache.lucene.util.CharsRefBuilder in project lucene-solr by apache.

the class FieldType method marshalStringSortValue.

/**
   * Marshals a string-based field value.
   */
protected static Object marshalStringSortValue(Object value) {
    if (null == value) {
        return null;
    }
    CharsRefBuilder spare = new CharsRefBuilder();
    spare.copyUTF8Bytes((BytesRef) value);
    return spare.toString();
}
Also used : CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder)

Example 49 with CharsRefBuilder

use of org.apache.lucene.util.CharsRefBuilder in project lucene-solr by apache.

the class TopGroupsShardRequestFactory method createRequest.

private ShardRequest[] createRequest(ResponseBuilder rb, String[] shards) {
    ShardRequest sreq = new ShardRequest();
    sreq.shards = shards;
    sreq.purpose = ShardRequest.PURPOSE_GET_TOP_IDS;
    sreq.params = new ModifiableSolrParams(rb.req.getParams());
    // If group.format=simple group.offset doesn't make sense
    Grouping.Format responseFormat = rb.getGroupingSpec().getResponseFormat();
    if (responseFormat == Grouping.Format.simple || rb.getGroupingSpec().isMain()) {
        sreq.params.remove(GroupParams.GROUP_OFFSET);
    }
    sreq.params.remove(ShardParams.SHARDS);
    // results from the start.
    if (rb.shards_start > -1) {
        // if the client set shards.start set this explicitly
        sreq.params.set(CommonParams.START, rb.shards_start);
    } else {
        sreq.params.set(CommonParams.START, "0");
    }
    if (rb.shards_rows > -1) {
        // if the client set shards.rows set this explicitly
        sreq.params.set(CommonParams.ROWS, rb.shards_rows);
    } else {
        sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount());
    }
    sreq.params.set(GroupParams.GROUP_DISTRIBUTED_SECOND, "true");
    final IndexSchema schema = rb.req.getSearcher().getSchema();
    for (Map.Entry<String, Collection<SearchGroup<BytesRef>>> entry : rb.mergedSearchGroups.entrySet()) {
        for (SearchGroup<BytesRef> searchGroup : entry.getValue()) {
            String groupValue;
            if (searchGroup.groupValue != null) {
                FieldType fieldType = schema.getField(entry.getKey()).getType();
                groupValue = fieldType.indexedToReadable(searchGroup.groupValue, new CharsRefBuilder()).toString();
            } else {
                groupValue = GROUP_NULL_VALUE;
            }
            sreq.params.add(GroupParams.GROUP_DISTRIBUTED_TOPGROUPS_PREFIX + entry.getKey(), groupValue);
        }
    }
    if ((rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0 || rb.getSortSpec().includesScore()) {
        sreq.params.set(CommonParams.FL, schema.getUniqueKeyField().getName() + ",score");
    } else {
        sreq.params.set(CommonParams.FL, schema.getUniqueKeyField().getName());
    }
    int origTimeAllowed = sreq.params.getInt(CommonParams.TIME_ALLOWED, -1);
    if (origTimeAllowed > 0) {
        sreq.params.set(CommonParams.TIME_ALLOWED, Math.max(1, origTimeAllowed - rb.firstPhaseElapsedTime));
    }
    return new ShardRequest[] { sreq };
}
Also used : Grouping(org.apache.solr.search.Grouping) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) FieldType(org.apache.solr.schema.FieldType) Collection(java.util.Collection) ShardRequest(org.apache.solr.handler.component.ShardRequest) IndexSchema(org.apache.solr.schema.IndexSchema) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) Map(java.util.Map) BytesRef(org.apache.lucene.util.BytesRef)

Example 50 with CharsRefBuilder

use of org.apache.lucene.util.CharsRefBuilder in project lucene-solr by apache.

the class SearchGroupsResultTransformer method serializeSearchGroup.

private NamedList serializeSearchGroup(Collection<SearchGroup<BytesRef>> data, SearchGroupsFieldCommand command) {
    final NamedList<Object[]> result = new NamedList<>(data.size());
    for (SearchGroup<BytesRef> searchGroup : data) {
        Object[] convertedSortValues = new Object[searchGroup.sortValues.length];
        for (int i = 0; i < searchGroup.sortValues.length; i++) {
            Object sortValue = searchGroup.sortValues[i];
            SchemaField field = command.getGroupSort().getSort()[i].getField() != null ? searcher.getSchema().getFieldOrNull(command.getGroupSort().getSort()[i].getField()) : null;
            convertedSortValues[i] = ShardResultTransformerUtils.marshalSortValue(sortValue, field);
        }
        SchemaField field = searcher.getSchema().getFieldOrNull(command.getKey());
        String groupValue = searchGroup.groupValue != null ? field.getType().indexedToReadable(searchGroup.groupValue, new CharsRefBuilder()).toString() : null;
        result.add(groupValue, convertedSortValues);
    }
    return result;
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) NamedList(org.apache.solr.common.util.NamedList) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

CharsRefBuilder (org.apache.lucene.util.CharsRefBuilder)52 BytesRef (org.apache.lucene.util.BytesRef)30 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)10 NamedList (org.apache.solr.common.util.NamedList)10 FieldType (org.apache.solr.schema.FieldType)10 TermsEnum (org.apache.lucene.index.TermsEnum)9 SchemaField (org.apache.solr.schema.SchemaField)7 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 TokenStream (org.apache.lucene.analysis.TokenStream)4 PostingsEnum (org.apache.lucene.index.PostingsEnum)4 Terms (org.apache.lucene.index.Terms)4 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)4 LeafReader (org.apache.lucene.index.LeafReader)3 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)3 CharsRef (org.apache.lucene.util.CharsRef)3 Util (org.apache.lucene.util.fst.Util)3 SolrException (org.apache.solr.common.SolrException)3