@SuppressWarnings("unchecked") public NamedList getStatistics() { NamedList lst = new SimpleOrderedMap(); lst.add("rollbacks", rollbackCommands.get()); lst.add("adds", addCommands.get()); lst.add("deletesById", deleteByIdCommands.get()); lst.add("deletesByQuery", deleteByQueryCommands.get()); lst.add("errors", numErrors.get()); lst.add("cumulative_adds", addCommandsCumulative.get()); lst.add("cumulative_deletesById", deleteByIdCommandsCumulative.get()); lst.add("cumulative_deletesByQuery", deleteByQueryCommandsCumulative.get()); lst.add("cumulative_errors", numErrorsCumulative.get()); return lst; }
private SolrRequest createtSolrRequest(String json) { final ContentStreamUpdateRequest request = new ContentStreamUpdateRequest(jsonUpdateUrl); final ContentStream cs = new ContentStreamBase.StringStream(json, CONTENT_TYPE); request.addContentStream(cs); if (logger.isDebugEnabled()) { logger.debug("Request generated with JSON: " + json); } return request; }
public static void writeSchema(String indexName, String schemaXml) throws IOException { writeCoreResource(indexName, CassandraUtils.schemaKey, schemaXml); logger.info("Wrote Schema for " + indexName); //remove any existing cores cache.remove(indexName); }
private String getFieldNameOfUniqueKey() { final SolrQuery solrQuery = new SolrQuery(); try { solrQuery.setRequestHandler("/schema/uniquekey"); final QueryRequest req = new QueryRequest(solrQuery); if (isBasicAuthEnabled()) { req.setBasicAuthCredentials(getUsername(), getPassword()); } return(req.process(getSolrClient()).getResponse().get("uniqueKey").toString()); } catch (SolrServerException | IOException e) { getLogger().error("Solr query to retrieve uniqueKey-field failed due to {}", new Object[]{solrQuery.toString(), e}, e); throw new ProcessException(e); } }
@Override @SuppressWarnings("unchecked") public Map<String, SolrJSONFacet> resolveJSONFacetResponse(QueryResponse response) { Map<String, SolrJSONFacet> jsonFacetMap = new HashMap<>(); NamedList facetResponse = (NamedList) response.getResponse().get("facets"); if (facetResponse != null) { Iterator<Map.Entry<String, Object>> facetIterator = facetResponse.iterator(); while (facetIterator.hasNext()) { Map.Entry<String, Object> entry = facetIterator.next(); if (NamedList.class.isAssignableFrom(entry.getValue().getClass())) { jsonFacetMap.put(entry.getKey(), resolveJSONFacet((NamedList) entry.getValue())); } } } return jsonFacetMap; }
public SimpleOrderedMap<Object> readOrderedMap(DataInputInputStream dis) throws IOException { int sz = readSize(dis); SimpleOrderedMap<Object> nl = new SimpleOrderedMap<>(sz); for (int i = 0; i < sz; i++) { String name = (String) readVal(dis); Object val = readVal(dis); nl.add(name, val); } return nl; }
@SuppressWarnings("unchecked") protected SolrJSONFacet resolveJSONFacet(NamedList facetNamedList) { SolrJSONFacet jsonFacet = new SolrJSONFacet(); Iterator<Map.Entry<String, Object>> iterator = facetNamedList.iterator(); while (iterator.hasNext()) { Map.Entry<String, Object> entry = iterator.next(); if (entry.getValue() != null) { if (NamedList.class.isAssignableFrom(entry.getValue().getClass())) { jsonFacet.getMap().put(entry.getKey(), resolveJSONFacet((NamedList) entry.getValue())); } else if (List.class.isAssignableFrom(entry.getValue().getClass())) { jsonFacet.getMap().put(entry.getKey(), resolveJSONFacetList((List<NamedList>) entry.getValue())); } else { jsonFacet.getMap().put(entry.getKey(), String.valueOf(entry.getValue())); } } } return jsonFacet; }
public String readStr(DataInputInputStream dis, StringCache stringCache) throws IOException { int sz = readSize(dis); if (bytes == null || bytes.length < sz) bytes = new byte[sz]; dis.readFully(bytes, 0, sz); if (stringCache != null) { return stringCache.get(bytesRef.reset(bytes, 0, sz)); } else { arr.reset(); ByteUtils.UTF8toUTF16(bytes, 0, sz, arr); return arr.toString(); } }
public synchronized SolrCore readSchema(String indexName) throws IOException, ParserConfigurationException, SAXException { SolrCore core = cache.get(indexName); if (core == null) { // get from cassandra if (logger.isDebugEnabled()) logger.debug("loading index schema for: " + indexName); ByteBuffer buf = readCoreResource(indexName, CassandraUtils.schemaKey); //Schema resource not found for the core if (buf == null) { throw new IOException(String.format("invalid core '%s'", indexName)); } InputStream stream = new ByteArrayInputStream(ByteBufferUtil.getArray(buf)); SolrResourceLoader resourceLoader = new SolandraResourceLoader(indexName, null); SolrConfig solrConfig = new SolrConfig(resourceLoader, solrConfigFile, null); IndexSchema schema = new IndexSchema(solrConfig, indexName, new InputSource(stream)); core = new SolrCore(indexName, "/tmp", solrConfig, schema, null); if (logger.isDebugEnabled()) logger.debug("Loaded core from cassandra: " + indexName); cache.put(indexName, core); } return core; }
/** * Create a cached thread pool using a named thread factory */ public static ExecutorService newMDCAwareCachedThreadPool(String name) { return newMDCAwareCachedThreadPool(new SolrjNamedThreadFactory(name)); }
public Map getMap(String key, Map def) { Object o = getMapVal(key); if (o == null) return def; if (!(o instanceof Map)) { addError(StrUtils.formatString("''{0}'' must be a map", key)); return def; } else { return (Map) o; } }
@Override public Object put(String key, Object val) { ensureNotClosed(); return super.put(key, val); }
@Override public void clear() { ensureNotClosed(); super.clear(); }
@SuppressWarnings("unchecked") public List<String> listCollections() throws IOException, SolrServerException { NamedList<Object> response = request(getListCollectionsRequest(), null); return (List<String>) response.get(SolrConstants.RESPONSE_COLLECTIONS); }
List<String> collectionNames = listResponse.get("collections") == null ? collectionNames = new ArrayList<>() : (List<String>) listResponse.get("collections"); collectionNames = listResponse.get("collections") == null ? collectionNames = new ArrayList<>() : (List<String>) listResponse.get("collections");
/** * Build a group response. * @param groupRequest The original group request. * @param response The search response. * @return A group response. */ protected GroupResponse buildGroupResponse( GroupRequest groupRequest, QueryResponse response) { String groupNames = groupRequest.getGroups().stream().map(Group::getField).collect( Collectors.joining(",")); List<PivotField> pivotFields = response.getFacetPivot().get(groupNames); GroupResponse groupResponse = new GroupResponse(); groupResponse.setGroupedBy(groupRequest.getGroups().get(0).getField()); groupResponse.setGroupResults(getGroupResults(groupRequest, 0, pivotFields)); return groupResponse; }