当前位置: 首页>>代码示例>>Java>>正文


Java ErrorCode类代码示例

本文整理汇总了Java中org.apache.solr.common.SolrException.ErrorCode的典型用法代码示例。如果您正苦于以下问题:Java ErrorCode类的具体用法?Java ErrorCode怎么用?Java ErrorCode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ErrorCode类属于org.apache.solr.common.SolrException包,在下文中一共展示了ErrorCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getGroupedFacetQueryCount

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
/**
 * Returns a grouped facet count for the facet query
 *
 * @see FacetParams#FACET_QUERY
 */
public int getGroupedFacetQueryCount(Query facetQuery, DocSet docSet) throws IOException {
  // It is okay to retrieve group.field from global because it is never a local param
  String groupField = global.get(GroupParams.GROUP_FIELD);
  if (groupField == null) {
    throw new SolrException (
        SolrException.ErrorCode.BAD_REQUEST,
        "Specify the group.field as parameter or local parameter"
    );
  }

  TermAllGroupsCollector collector = new TermAllGroupsCollector(groupField);
  Filter mainQueryFilter = docSet.getTopFilter(); // This returns a filter that only matches documents matching with q param and fq params
  Query filteredFacetQuery = new BooleanQuery.Builder()
      .add(facetQuery, Occur.MUST)
      .add(mainQueryFilter, Occur.FILTER)
      .build();
  searcher.search(filteredFacetQuery, collector);
  return collector.getGroupCount();
}
 
开发者ID:upenn-libraries,项目名称:solrplugins,代码行数:25,代码来源:SimpleFacets.java

示例2: selectFacetMethod

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
/**
  * @param existsRequested facet.exists=true is passed for the given field
  * */
static FacetMethod selectFacetMethod(String fieldName, 
                                     SchemaField field, FacetMethod method, Integer mincount,
                                     boolean existsRequested) {
  if (existsRequested) {
    checkMincountOnExists(fieldName, mincount);
    if (method == null) {
      method = FacetMethod.ENUM;
    }
  }
  final FacetMethod facetMethod = selectFacetMethod(field, method, mincount);
  
  if (existsRequested && facetMethod!=FacetMethod.ENUM) {
    throw new SolrException (ErrorCode.BAD_REQUEST, 
        FacetParams.FACET_EXISTS + "=true is requested, but "+
        FacetParams.FACET_METHOD+"="+FacetParams.FACET_METHOD_enum+ " can't be used with "+fieldName
    );
  }
  return facetMethod;
}
 
开发者ID:upenn-libraries,项目名称:solrplugins,代码行数:23,代码来源:SimpleFacets.java

示例3: getHeatmapCounts

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
public NamedList getHeatmapCounts() throws IOException, SyntaxError {
  final NamedList<Object> resOuter = new SimpleOrderedMap<>();
  String[] unparsedFields = rb.req.getParams().getParams(FacetParams.FACET_HEATMAP);
  if (unparsedFields == null || unparsedFields.length == 0) {
    return resOuter;
  }
  if (global.getBool(GroupParams.GROUP_FACET, false)) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        "Heatmaps can't be used with " + GroupParams.GROUP_FACET);
  }
  for (String unparsedField : unparsedFields) {
    final ParsedParams parsed = parseParams(FacetParams.FACET_HEATMAP, unparsedField); // populates facetValue, rb, params, docs

    resOuter.add(parsed.key, SpatialHeatmapFacets.getHeatmapForField(parsed.key, parsed.facetValue, rb, parsed.params, parsed.docs));
  }
  return resOuter;
}
 
开发者ID:upenn-libraries,项目名称:solrplugins,代码行数:18,代码来源:SimpleFacets.java

示例4: getCollectionList

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
private Set<String> getCollectionList(ClusterState clusterState,
    String collection) {
  // Extract each comma separated collection name and store in a List.
  List<String> rawCollectionsList = StrUtils.splitSmart(collection, ",", true);
  Set<String> collectionsList = new HashSet<>();
  // validate collections
  for (String collectionName : rawCollectionsList) {
    if (!clusterState.getCollections().contains(collectionName)) {
      Aliases aliases = zkStateReader.getAliases();
      String alias = aliases.getCollectionAlias(collectionName);
      if (alias != null) {
        List<String> aliasList = StrUtils.splitSmart(alias, ",", true); 
        collectionsList.addAll(aliasList);
        continue;
      }
      
      throw new SolrException(ErrorCode.BAD_REQUEST, "Collection not found: " + collectionName);
    }
    
    collectionsList.add(collectionName);
  }
  return collectionsList;
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:CloudSolrServer.java

示例5: ZkStateReader

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
public ZkStateReader(String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout) throws InterruptedException, TimeoutException, IOException {
  closeClient = true;
  initZkCmdExecutor(zkClientTimeout);
  zkClient = new SolrZkClient(zkServerAddress, zkClientTimeout, zkClientConnectTimeout,
      // on reconnect, reload cloud info
      new OnReconnect() {

        @Override
        public void command() {
          try {
            ZkStateReader.this.createClusterStateWatchersAndUpdate();
          } catch (KeeperException e) {
            log.error("", e);
            throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
                "", e);
          } catch (InterruptedException e) {
            // Restore the interrupted status
            Thread.currentThread().interrupt();
            log.error("", e);
            throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
                "", e);
          } 

        }
      });
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:ZkStateReader.java

示例6: createFromLocale

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
/**
 * Create a locale from language, with optional country and variant.
 * Then return the appropriate collator for the locale.
 */
private Collator createFromLocale(String language, String country, String variant) {
  Locale locale;
  
  if (language != null && country == null && variant != null)
    throw new SolrException(ErrorCode.SERVER_ERROR, 
        "To specify variant, country is required");
  else if (language != null && country != null && variant != null)
    locale = new Locale(language, country, variant);
  else if (language != null && country != null)
    locale = new Locale(language, country);
  else 
    locale = new Locale(language);
  
  return Collator.getInstance(locale);
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:CollationField.java

示例7: retryOnThrowable

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
public static void retryOnThrowable(Class clazz, long timeoutms, long intervalms, RetryCmd cmd) throws Throwable {
  long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeoutms, TimeUnit.MILLISECONDS);
  while (true) {
    try {
      cmd.execute();
    } catch (Throwable t) {
      if (clazz.isInstance(t) && System.nanoTime() < timeout) {
        Thread.sleep(intervalms);
        continue;
      }
      throw new SolrException(ErrorCode.SERVER_ERROR, t);
    }
    // success
    break;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:RetryUtil.java

示例8: testSolrExceptionCodeNotFromSolr

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
/**
 * test that SolrExceptions thrown by HttpSolrServer can
 * correctly encapsulate http status codes even when not on the list of
 * ErrorCodes solr may return.
 */
public void testSolrExceptionCodeNotFromSolr() throws IOException, SolrServerException {
  final int status = 527;
  assertEquals(status + " didn't generate an UNKNOWN error code, someone modified the list of valid ErrorCode's w/o changing this test to work a different way",
               ErrorCode.UNKNOWN, ErrorCode.getErrorCode(status));

  HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() +
                                             "/debug/foo");
  try {
    DebugServlet.setErrorCode(status);
    try {
      SolrQuery q = new SolrQuery("foo");
      server.query(q, METHOD.GET);
      fail("Didn't get excepted exception from oversided request");
    } catch (SolrException e) {
      System.out.println(e);
      assertEquals("Unexpected exception status code", status, e.code());
    }
  } finally {
    server.shutdown();
    DebugServlet.clear();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:28,代码来源:BasicHttpSolrServerTest.java

示例9: getFieldsForClustering

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
/**
 * Returns the names of fields that will be delivering the actual
 * content for clustering. Currently, there are two such fields: document
 * title and document content.
 */
private Set<String> getFieldsForClustering(SolrQueryRequest sreq) {
  SolrParams solrParams = sreq.getParams();

  String titleFieldSpec = solrParams.get(CarrotParams.TITLE_FIELD_NAME, "title");
  String snippetFieldSpec = solrParams.get(CarrotParams.SNIPPET_FIELD_NAME, titleFieldSpec);
  if (StringUtils.isBlank(snippetFieldSpec)) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, CarrotParams.SNIPPET_FIELD_NAME
            + " must not be blank.");
  }
  
  final Set<String> fields = Sets.newHashSet();
  fields.addAll(Arrays.asList(titleFieldSpec.split("[, ]")));
  fields.addAll(Arrays.asList(snippetFieldSpec.split("[, ]")));
  return fields;
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:CarrotClusteringEngine.java

示例10: getCollectionStatus

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
/**
 * Get collection status from cluster state.
 * Can return collection status by given shard name.
 *
 *
 * @param clusterState cloud state map parsed from JSON-serialized {@link ClusterState}
 * @param name  collection name
 * @param shardStr comma separated shard names
 * @return map of collection properties
 */
private Map<String, Object> getCollectionStatus(Map<String, Object> clusterState, String name, String shardStr) {
  Map<String, Object> docCollection = (Map<String, Object>) clusterState.get(name);
  if (docCollection == null)  {
    throw new SolrException(ErrorCode.BAD_REQUEST, "Collection: " + name + " not found");
  }
  if (shardStr == null) {
    return docCollection;
  } else {
    Map<String, Object> shards = (Map<String, Object>) docCollection.get("shards");
    Map<String, Object>  selected = new HashMap<>();
    List<String> selectedShards = Arrays.asList(shardStr.split(","));
    for (String selectedShard : selectedShards) {
      if (!shards.containsKey(selectedShard)) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "Collection: " + name + " shard: " + selectedShard + " not found");
      }
      selected.put(selectedShard, shards.get(selectedShard));
      docCollection.put("shards", selected);
    }
    return docCollection;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:32,代码来源:OverseerCollectionProcessor.java

示例11: parseParamsAndFillStreams

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
@Override
public SolrParams parseParamsAndFillStreams( 
    final HttpServletRequest req, ArrayList<ContentStream> streams ) throws Exception
{
  String method = req.getMethod().toUpperCase(Locale.ROOT);
  if ("GET".equals(method) || "HEAD".equals(method) 
      || (("PUT".equals(method) || "DELETE".equals(method))
          && (req.getRequestURI().contains("/schema")
              || req.getRequestURI().contains("/config")))) {
    return parseQueryString(req.getQueryString());
  }
  if ("POST".equals( method ) ) {
    if (formdata.isFormData(req)) {
      return formdata.parseParamsAndFillStreams(req, streams);
    }
    if (ServletFileUpload.isMultipartContent(req)) {
      return multipart.parseParamsAndFillStreams(req, streams);
    }
    if (req.getContentType() != null) {
      return raw.parseParamsAndFillStreams(req, streams);
    }
    throw new SolrException(ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Must specify a Content-Type header with POST requests");
  }
  throw new SolrException(ErrorCode.BAD_REQUEST, "Unsupported method: " + method + " for request " + req);
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:SolrRequestParsers.java

示例12: create

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
@Override
public DocTransformer create(String field, SolrParams params, SolrQueryRequest req) {
  Object val = value;
  if( val == null ) {
    String v = params.get("v");
    if( v == null ) {
      val = defaultValue;
    }
    else {
      val = getObjectFrom(v, params.get("t"));
    }
    if( val == null ) {
      throw new SolrException( ErrorCode.BAD_REQUEST,
          "ValueAugmenter is missing a value -- should be defined in solrconfig or inline" );
    }
  }
  return new ValueAugmenter( field, val );
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:ValueAugmenterFactory.java

示例13: openIndexWriter

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
@Override
public synchronized void openIndexWriter(SolrCore core) throws IOException {
  log.info("Creating new IndexWriter...");
  synchronized (writerPauseLock) {
    if (closed) {
      throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "Already closed");
    }
    
    try {
      indexWriter = createMainIndexWriter(core, "DirectUpdateHandler2");
      log.info("New IndexWriter is ready to be used.");
      // we need to null this so it picks up the new writer next get call
      refCntWriter = null;
    } finally {
      pauseWriter = false;
      writerPauseLock.notifyAll();
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:DefaultSolrCoreState.java

示例14: getExchangeRate

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
/**
 * Returns the currently known exchange rate between two currencies. If a direct rate has been loaded,
 * it is used. Otherwise, if a rate is known to convert the target currency to the source, the inverse
 * exchange rate is computed.
 *
 * @param sourceCurrencyCode The source currency being converted from.
 * @param targetCurrencyCode The target currency being converted to.
 * @return The exchange rate.
 * @throws SolrException if the requested currency pair cannot be found
 */
@Override
public double getExchangeRate(String sourceCurrencyCode, String targetCurrencyCode) {
  if (sourceCurrencyCode == null || targetCurrencyCode == null) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cannot get exchange rate; currency was null.");
  }
  
  if (sourceCurrencyCode.equals(targetCurrencyCode)) {
    return 1.0;
  }

  Double directRate = lookupRate(sourceCurrencyCode, targetCurrencyCode);

  if (directRate != null) {
    return directRate;
  }

  Double symmetricRate = lookupRate(targetCurrencyCode, sourceCurrencyCode);

  if (symmetricRate != null) {
    return 1.0 / symmetricRate;
  }

  throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No available conversion rate between " + sourceCurrencyCode + " to " + targetCurrencyCode);
}
 
开发者ID:europeana,项目名称:search,代码行数:35,代码来源:CurrencyField.java

示例15: getCollectionUrls

import org.apache.solr.common.SolrException.ErrorCode; //导入依赖的package包/类
private List<Node> getCollectionUrls(SolrQueryRequest req, String collection) {
  ClusterState clusterState = req.getCore().getCoreDescriptor()
      .getCoreContainer().getZkController().getClusterState();
  List<Node> urls = new ArrayList<>();
  Map<String,Slice> slices = clusterState.getSlicesMap(collection);
  if (slices == null) {
    throw new ZooKeeperException(ErrorCode.BAD_REQUEST,
        "Could not find collection in zk: " + clusterState);
  }
  for (Map.Entry<String,Slice> sliceEntry : slices.entrySet()) {
    Slice replicas = slices.get(sliceEntry.getKey());

    Map<String,Replica> shardMap = replicas.getReplicasMap();
    
    for (Entry<String,Replica> entry : shardMap.entrySet()) {
      ZkCoreNodeProps nodeProps = new ZkCoreNodeProps(entry.getValue());
      if (clusterState.liveNodesContain(nodeProps.getNodeName())) {
        urls.add(new StdNode(nodeProps, collection, replicas.getName()));
      }
    }
  }
  if (urls.size() == 0) {
    return null;
  }
  return urls;
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:DistributedUpdateProcessor.java


注:本文中的org.apache.solr.common.SolrException.ErrorCode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。