本文整理汇总了Java中org.apache.solr.common.params.ShardParams类的典型用法代码示例。如果您正苦于以下问题:Java ShardParams类的具体用法?Java ShardParams怎么用?Java ShardParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ShardParams类属于org.apache.solr.common.params包,在下文中一共展示了ShardParams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
@Test
@ShardsFixed(num = 2)
public void test() throws Exception {
handle.clear();
handle.put("QTime", SKIPVAL);
handle.put("timestamp", SKIPVAL);
handle.put("maxScore", SKIPVAL);
handle.put("responseHeader", SKIP);
handle.put("spellchecked_response", UNORDERED);
query(CommonParams.QT, "standardResWithCommonMisspellings",
ShardParams.SHARDS_QT, "standardResWithCommonMisspellings",
CommonParams.Q, "foo:bobo AND foo:marley",
SpellingParams.SPELLCHECK_COLLATE, "true",
SpellingParams.SPELLCHECK_BUILD, "true",
SpellingParams.SPELLCHECK_COUNT, "10",
SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true",
DymReSearcher.COMPONENT_NAME, "true",
SpellCheckComponent.COMPONENT_NAME, "true");
}
示例2: process
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
@Override
public void process(ResponseBuilder rb) throws IOException {
Boolean isFusionQuery = rb.req.getParams().getBool(IS_FUSION_QUERY_PARAM);
if (isFusionQuery != null) {
if (isFusionQuery) {
log.info("Skipping the logging to Fusion as this is a Fusion query");
return;
}
}
SolrParams params = rb.req.getParams();
boolean isShard = params.getBool(ShardParams.IS_SHARD, false);
if (isShard) {
return;
}
sendSearchLogsToFusion(rb, false);
}
示例3: finishStage
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
@Override
public void finishStage(ResponseBuilder rb) {
SolrParams params = rb.req.getParams();
boolean isShard = params.getBool(ShardParams.IS_SHARD, false);
if (isShard) {
return;
}
Boolean isFusionQuery = params.getBool(IS_FUSION_QUERY_PARAM);
if (isFusionQuery != null) {
if (isFusionQuery) {
log.info("Skipping the logging to Fusion as this a Fusion query");
return;
}
}
if (rb.stage != ResponseBuilder.STAGE_GET_FIELDS) {
return;
}
sendSearchLogsToFusion(rb, true);
}
示例4: getParams
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
@Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
if (shardName == null || shardName.isEmpty()) {
params.remove("shard");
if (routeKey == null) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Either shard or routeKey must be provided");
}
params.add(ShardParams._ROUTE_, routeKey);
}
if (node != null) {
params.add("node", node);
}
if (instanceDir != null) {
params.add("instanceDir", instanceDir);
}
if (dataDir != null) {
params.add("dataDir", dataDir);
}
return params;
}
示例5: distributedProcess
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
/** Dispatch shard request in <code>STAGE_EXECUTE_QUERY</code> stage */
@Override
public int distributedProcess(ResponseBuilder rb) {
SolrParams params = rb.req.getParams();
LOG.info("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;
}
示例6: doTest
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
@Override
public void doTest() throws Exception {
waitForRecoveriesToFinish(false);
assertEquals(4, cloudClient.getZkStateReader().getClusterState().getCollection(DEFAULT_COLLECTION).getSlices().size());
index("id", "a!doc1"); // shard3
index("id", "b!doc1"); // shard1
index("id", "c!doc1"); // shard2
index("id", "e!doc1"); // shard4
commit();
doQuery("a!doc1", "q", "*:*", ShardParams._ROUTE_, "a!"); // can go to any random node
// query shard3 directly with _route_=a! so that we trigger the short circuited request path
Replica shard3 = cloudClient.getZkStateReader().getClusterState().getLeader(DEFAULT_COLLECTION, "shard3");
String nodeName = shard3.getNodeName();
SolrServer shard3Client = getClient(nodeName);
QueryResponse response = shard3Client.query(new SolrQuery("*:*").add(ShardParams._ROUTE_, "a!").add(ShardParams.SHARDS_INFO, "true"));
assertEquals("Could not find doc", 1, response.getResults().getNumFound());
NamedList<?> sinfo = (NamedList<?>) response.getResponse().get(ShardParams.SHARDS_INFO);
assertNotNull("missing shard info for short circuited request", sinfo);
}
示例7: distributedProcess
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
/** Dispatch shard request in <code>STAGE_EXECUTE_QUERY</code> stage */
@Override
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;
}
示例8: prepare
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
@Override
public void prepare(ResponseBuilder rb) throws IOException {
checkNotNull(rb, "Pre-condition violated: rb must not be null.");
SolrParams solrParams = rb.req.getParams();
// Only run this component if it is active and this is not a subrequest (we want to add the boost terms
// only on the initial request that Solr receives from the outside).
if (solrParams.getBool(COMPONENT_NAME, false) && !solrParams.getBool(ShardParams.IS_SHARD, false)) {
// check preconditions
String q = solrParams.get(CommonParams.Q);
String sort = solrParams.get(CommonParams.SORT);
if (q != null
&& !"*:*".equals(q)
&& (sort == null || (StringUtils.containsIgnoreCase(sort, "score") && StringUtils.containsIgnoreCase(
sort, "desc")))) {
prepareInternal(rb);
}
}
}
示例9: getAndPrepShardHandler
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
private ShardHandler getAndPrepShardHandler(SolrQueryRequest req, ResponseBuilder rb, ShardHandlerFactory shardHandlerFactory) {
ShardHandler shardHandler = null;
boolean isZkAware = false;
CoreContainer cc = null;
if (req.getCore() != null) {
cc = req.getCore().getCoreContainer();
isZkAware = cc.isZooKeeperAware();
}
rb.isDistrib = req.getParams().getBool("distrib", isZkAware);
if (!rb.isDistrib) {
// for back compat, a shards param with URLs like localhost:8983/solr will mean that this
// search is distributed.
final String shards = req.getParams().get(ShardParams.SHARDS);
rb.isDistrib = ((shards != null) && (shards.indexOf('/') > 0));
}
if (rb.isDistrib) {
shardHandler = shardHandlerFactory.getShardHandler();
shardHandler.prepDistributed(rb);
if (!rb.isDistrib) {
shardHandler = null; // request is not distributed after all and so the shard handler is not needed
}
}
if(isZkAware) {
ZkController zkController = cc.getZkController();
NamedList<Object> headers = rb.rsp.getResponseHeader();
if(headers != null) {
headers.add("zkConnected",
zkController != null
? !zkController.getZkClient().getConnectionManager().isLikelyExpired()
: false);
}
}
return shardHandler;
}
示例10: create
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
@Override
public DocTransformer create(String field, SolrParams params, SolrQueryRequest req) {
String v = req.getParams().get(ShardParams.SHARD_URL);
if( v == null ) {
if( req.getParams().getBool(ShardParams.IS_SHARD, false) ) {
v = "[unknown]";
}
else {
v = "[not a shard request]";
}
}
return new ValueAugmenter( field, v );
}
示例11: handleAddReplica
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
private void handleAddReplica(SolrQueryRequest req, SolrQueryResponse rsp) throws KeeperException, InterruptedException {
log.info("Add replica action invoked: " + req.getParamString());
Map<String,Object> props = new HashMap<>();
props.put(Overseer.QUEUE_OPERATION, CollectionAction.ADDREPLICA.toString());
copyIfNotNull(req.getParams(), props, COLLECTION_PROP, "node", SHARD_ID_PROP, ShardParams._ROUTE_,
CoreAdminParams.NAME, CoreAdminParams.INSTANCE_DIR, CoreAdminParams.DATA_DIR, ASYNC);
ZkNodeProps m = new ZkNodeProps(props);
handleResponse(CollectionAction.ADDREPLICA.toString(), m, rsp);
}
示例12: handleResponses
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
@Override
public void handleResponses(ResponseBuilder rb, ShardRequest sreq) {
if (!rb.doStats || (sreq.purpose & ShardRequest.PURPOSE_GET_STATS) == 0) return;
StatsInfo si = rb._statsInfo;
for (ShardResponse srsp : sreq.responses) {
NamedList stats = null;
try {
stats = (NamedList) srsp.getSolrResponse().getResponse().get("stats");
} catch (Exception e) {
if (rb.req.getParams().getBool(ShardParams.SHARDS_TOLERANT, false)) {
continue; // looks like a shard did not return anything
}
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
"Unable to read stats info for shard: " + srsp.getShard(), e);
}
NamedList stats_fields = (NamedList) stats.get("stats_fields");
if (stats_fields != null) {
for (int i = 0; i < stats_fields.size(); i++) {
String field = stats_fields.getName(i);
StatsValues stv = si.statsFields.get(field);
NamedList shardStv = (NamedList) stats_fields.get(field);
stv.accumulate(shardStv);
}
}
}
}
示例13: getStatsFields
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
public NamedList<Object> getStatsFields() throws IOException, SyntaxError {
NamedList<Object> res = new SimpleOrderedMap<>();
String[] statsFs = params.getParams(StatsParams.STATS_FIELD);
boolean isShard = params.getBool(ShardParams.IS_SHARD, false);
if (null != statsFs) {
final IndexSchema schema = searcher.getSchema();
for (String f : statsFs) {
boolean calcDistinct = params.getFieldBool(f, StatsParams.STATS_CALC_DISTINCT, false);
parseParams(f);
String[] facets = params.getFieldParams(key, StatsParams.STATS_FACET);
if (facets == null) {
facets = new String[0]; // make sure it is something...
}
SchemaField sf = schema.getField(statsField);
FieldType ft = sf.getType();
NamedList<?> stv;
if (sf.multiValued() || ft.multiValuedFieldCache()) {
if(sf.hasDocValues()) {
stv = DocValuesStats.getCounts(searcher, sf.getName(), base, calcDistinct, facets).getStatsValues();
} else {
//use UnInvertedField for multivalued fields
UnInvertedField uif = UnInvertedField.getUnInvertedField(statsField, searcher);
stv = uif.getStats(searcher, base, calcDistinct, facets).getStatsValues();
}
} else {
stv = getFieldCacheStats(statsField, calcDistinct, facets);
}
if (isShard == true || (Long) stv.get("count") > 0) {
res.add(key, stv);
} else {
res.add(key, null);
}
}
}
return res;
}
示例14: buildShardQuery
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
ShardRequest buildShardQuery(ResponseBuilder rb, String q, String key) {
ShardRequest s = new ShardRequest();
s.params = new ModifiableSolrParams(rb.req.getParams());
s.purpose |= ShardRequest.PURPOSE_GET_MLT_RESULTS;
// Maybe unnecessary, but safe.
s.purpose |= ShardRequest.PURPOSE_PRIVATE;
s.params.remove(ShardParams.SHARDS);
// s.params.remove(MoreLikeThisComponent.COMPONENT_NAME);
// needed to correlate results
s.params.set(MoreLikeThisComponent.DIST_DOC_ID, key);
s.params.set(CommonParams.START, 0);
int mltcount = s.params.getInt(MoreLikeThisParams.DOC_COUNT, 20); // overrequest
s.params.set(CommonParams.ROWS, mltcount);
// adding score to rank moreLikeThis
s.params.remove(CommonParams.FL);
// Should probably add something like this:
// String fl = s.params.get(MoreLikeThisParams.RETURN_FL, "*");
// if(fl != null){
// s.params.set(CommonParams.FL, fl + ",score");
// }
String id = rb.req.getSchema().getUniqueKeyField()
.getName();
s.params.set(CommonParams.FL, "score," + id);
s.params.set("sort", "score desc");
// MLT Query is submitted as normal query to shards.
s.params.set(CommonParams.Q, q);
return s;
}
示例15: comparePartialResponses
import org.apache.solr.common.params.ShardParams; //导入依赖的package包/类
protected void comparePartialResponses(QueryResponse rsp, QueryResponse controlRsp, List<String> upShards)
{
NamedList<?> sinfo = (NamedList<?>) rsp.getResponse().get(ShardParams.SHARDS_INFO);
assertNotNull("missing shard info", sinfo);
assertEquals("should have an entry for each shard ["+sinfo+"] "+shards, shardsArr.length, sinfo.size());
// identify each one
for (Map.Entry<String,?> entry : sinfo) {
String shard = entry.getKey();
NamedList<?> info = (NamedList<?>) entry.getValue();
boolean found = false;
for(int i=0; i<shardsArr.length; i++) {
String s = shardsArr[i];
if (shard.contains(s)) {
found = true;
// make sure that it responded if it's up
if (upShards.contains(s)) {
assertTrue("Expected to find numFound in the up shard info",info.get("numFound") != null);
assertTrue("Expected to find shardAddress in the up shard info",info.get("shardAddress") != null);
}
else {
assertEquals("Expected to find the partialResults header set if a shard is down", Boolean.TRUE, rsp.getHeader().get("partialResults"));
assertTrue("Expected to find error in the down shard info",info.get("error") != null);
}
}
}
assertTrue("Couldn't find shard " + shard + " represented in shards info", found);
}
}