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