List of usage examples for org.apache.solr.common.params ShardParams SHARDS
String SHARDS
To view the source code for org.apache.solr.common.params ShardParams SHARDS.
Click Source Link
From source file:edu.harvard.gis.hhypermap.bop.solrplugins.DateShardRoutingSearchHandler.java
License:Apache License
private void addShardsParamIfWeCan(SolrQueryRequest req) { CoreDescriptor coreDescriptor = req.getCore().getCoreDescriptor(); CoreContainer coreContainer = coreDescriptor.getCoreContainer(); if (!coreContainer.isZooKeeperAware()) { return;/*from w ww .j ava2 s . c o m*/ } if (!req.getParams().getBool("distrib", true)) { return; } final String shards = req.getParams().get(ShardParams.SHARDS); if (shards != null) { return; // we already have the shards } String startStrParam = req.getParams().get(START_PARAM); String endStrParam = req.getParams().get(END_PARAM); Instant startInst = // null means open-ended ('*') startStrParam == null ? null : DateMathParser.parseMath(null, startStrParam).toInstant(); Instant endInst = endStrParam == null ? null : DateMathParser.parseMath(null, endStrParam).toInstant(); if (startInst == null && endInst == null) { return; } ZkController zkController = coreContainer.getZkController(); String collection = req.getParams().get("collection", coreDescriptor.getCollectionName()); List<Slice> slices = getOrderedSlices(zkController, collection); if (slices.size() <= 1) { return; } List<String> routeShardNames = new ArrayList<>(); // the result boolean findingStart = (startInst != null); String prevShardName = null; Instant prevShardStartKey = null; for (Slice slice : slices) { String name = slice.getName(); Instant shardStartKey = parseStartKeyFromShardName(name); if (prevShardStartKey != null && prevShardStartKey.isAfter(shardStartKey)) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "shards not in order? " + slice); } if (findingStart) { // As we advance shards, is this one finally > the 'start'? If so, accept it. if (shardStartKey.isAfter(startInst)) { if (prevShardName != null) { routeShardNames.add(prevShardName); } findingStart = false; // thus findingEnd } } if (!findingStart && endInst == null) { // take all the remainder since 'end' is null routeShardNames.add(name); } else if (!findingStart) { // findingEnd if (shardStartKey.isAfter(endInst)) { break; } routeShardNames.add(name); } prevShardName = name; prevShardStartKey = shardStartKey; } if (findingStart) { routeShardNames.add(prevShardName); } if (routeShardNames.size() == slices.size()) { return; } ModifiableSolrParams params = new ModifiableSolrParams(req.getParams()); String shardsValue = StrUtils.join(routeShardNames, ','); params.set(ShardParams.SHARDS, shardsValue); req.setParams(params); log.debug("Set shards: {}", shardsValue); }
From source file:lux.solr.SolrDocWriter.java
License:Mozilla Public License
private void writeToCloud(SolrInputDocument solrDoc, String uri) { ArrayList<String> urls = xqueryComponent.getShardURLs(true); LoggerFactory.getLogger(getClass()).debug("writing " + uri + " to cloud at " + urls); SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryRequest req = UpdateDocCommand.makeSolrRequest(core); ((ModifiableSolrParams) req.getParams()).add(ShardParams.SHARDS, urls.toArray(new String[urls.size()])); UpdateRequest updateReq = new UpdateRequest(); updateReq.add(solrDoc);/* w w w .j ava2 s . co m*/ UpdateDocCommand cmd = new UpdateDocCommand(req, solrDoc, null, uri); UpdateRequestProcessorChain updateChain = xqueryComponent.getCore() .getUpdateProcessingChain("lux-update-chain"); try { UpdateRequestProcessor processor = updateChain.createProcessor(req, rsp); processor.processAdd(cmd); processor.finish(); } catch (IOException e) { throw new LuxException(e); } }
From source file:org.alfresco.solr.component.AsyncBuildSuggestComponent.java
License:Open Source License
/** Dispatch shard request in <code>STAGE_EXECUTE_QUERY</code> stage */ @Override/* w w w.ja v a 2 s . c o m*/ public int distributedProcess(ResponseBuilder rb) { SolrParams params = rb.req.getParams(); LOG.debug("SuggestComponent distributedProcess with : " + params); if (rb.stage < ResponseBuilder.STAGE_EXECUTE_QUERY) return ResponseBuilder.STAGE_EXECUTE_QUERY; if (rb.stage == ResponseBuilder.STAGE_EXECUTE_QUERY) { ShardRequest sreq = new ShardRequest(); sreq.purpose = ShardRequest.PURPOSE_GET_TOP_IDS; sreq.params = new ModifiableSolrParams(rb.req.getParams()); sreq.params.remove(ShardParams.SHARDS); rb.addRequest(this, sreq); return ResponseBuilder.STAGE_GET_FIELDS; } return ResponseBuilder.STAGE_DONE; }
From source file:org.dspace.statistics.SolrLogger.java
License:BSD License
private static void addAdditionalSolrYearCores(SolrQuery solrQuery) { //Only add if needed if (0 < statisticYearCores.size()) { //The shards are a comma separated list of the urls to the cores solrQuery.add(ShardParams.SHARDS, StringUtils.join(statisticYearCores.iterator(), ",")); }/*from w ww . j a v a 2s.c om*/ }
From source file:org.dspace.statistics.SolrLoggerServiceImpl.java
License:BSD License
protected void addAdditionalSolrYearCores(SolrQuery solrQuery) { //Only add if needed if (0 < statisticYearCores.size()) { //The shards are a comma separated list of the urls to the cores solrQuery.add(ShardParams.SHARDS, StringUtils.join(statisticYearCores.iterator(), ",")); }/* www . j ava 2 s . com*/ }