fieldList = fields.toArray(new String[fields.size()]); SolrQuery query = new SolrQuery(); query.setQuery("*:*"); query.setParam("fq", "id:[ " + startkey + " TO * ]"); if (returnFields) { query.setFields(fieldList); query.setRows(recordcount); final QueryResponse response = client.query(table, query); SolrDocumentList results = response.getResults(); entry = new HashMap<String, ByteIterator>((int) results.getNumFound()); for (String field : hit.getFieldNames()) { entry.put(field, new StringByteIterator(String.valueOf(hit.getFirstValue(field)))); return checkStatus(response.getStatus()); } catch (IOException | SolrServerException e) { e.printStackTrace();
String collection = query.getStore(); String keyIdField = getKeyFieldId(collection); SolrQuery solrQuery = new SolrQuery("*:*"); String queryFilter = buildQueryFilter(query.getCondition(), informations.get(collection)); solrQuery.addFilterQuery(queryFilter); if (!query.getOrder().isEmpty()) { List<IndexQuery.OrderEntry> orders = query.getOrder(); String item = order1.getKey(); SolrQuery.ORDER order = order1.getOrder() == Order.ASC ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc; solrQuery.addSort(new SolrQuery.SortClause(item, order)); QueryResponse response = solrClient.query(collection, solrQuery); logger.debug("Executed query [{}] in {} ms", query.getCondition(), response.getElapsedTime()); int totalHits = response.getResults().size(); for (SolrDocument hit : response.getResults()) { result.add(hit.getFieldValue(keyIdField).toString());
fieldList = fields.toArray(new String[fields.size()]); SolrQuery query = new SolrQuery(); query.setQuery("id:" + key); if (returnFields) { query.setFields(fieldList); final QueryResponse response = client.query(table, query); SolrDocumentList results = response.getResults(); if ((results != null) && (results.getNumFound() > 0)) { for (String field : results.get(0).getFieldNames()) { result.put(field, new StringByteIterator(String.valueOf(results.get(0).getFirstValue(field)))); return checkStatus(response.getStatus()); } catch (IOException | SolrServerException e) { e.printStackTrace();
final SolrQuery solrQuery = new SolrQuery(); stateMap.putAll(context.getStateManager().getState(Scope.CLUSTER).toMap()); solrQuery.setQuery("*:*"); final String query = context.getProperty(SOLR_QUERY).getValue(); if (!StringUtils.isBlank(query) && !query.equals("*:*")) { solrQuery.addFilterQuery(query); logger.debug(solrQuery.toQueryString()); final QueryResponse response = req.process(getSolrClient()); final SolrDocumentList documentList = response.getResults(); if (response.getResults().size() > 0) { final SolrDocument lastSolrDocument = documentList.get(response.getResults().size()-1); final String latestDateValue = df.format(lastSolrDocument.get(dateField)); final String newCursorMark = response.getNextCursorMark(); if (dateFieldNotInSpecifiedFieldsList.get()) { for (SolrDocument doc : response.getResults()) { doc.removeFields(dateField); continuePaging.set(response.getResults().size() == Integer.parseInt(context.getProperty(BATCH_SIZE).getValue()));
final SolrQuery solrQuery = new SolrQuery(); final boolean isSolrCloud = SOLR_TYPE_CLOUD.equals(context.getProperty(SOLR_TYPE).getValue()); final String collection = context.getProperty(COLLECTION).evaluateAttributeExpressions(flowFileResponse).getValue(); solrQuery.setQuery(context.getProperty(SOLR_PARAM_QUERY).evaluateAttributeExpressions(flowFileResponse).getValue()); solrQuery.setRequestHandler(context.getProperty(SOLR_PARAM_REQUEST_HANDLER).evaluateAttributeExpressions(flowFileResponse).getValue()); timer.stop(); final Long totalNumberOfResults = response.getResults().getNumFound(); responseAttributes.put(ATTRIBUTE_CURSOR_MARK, response.getNextCursorMark()); responseAttributes.put(ATTRIBUTE_SOLR_STATUS, String.valueOf(response.getStatus())); responseAttributes.put(ATTRIBUTE_QUERY_TIME, String.valueOf(response.getQTime())); flowFileResponse = session.putAllAttributes(flowFileResponse, responseAttributes); if (response.getResults().size() > 0) {
public boolean existsInIndex(String username) { SolrQuery solrQuery = new SolrQuery().setQuery("name:" + username); try { return 1 == solrClient.query(solrQuery).getResults().getNumFound(); } catch (SolrServerException | IOException e) { throw new RuntimeException(e); } }
SolrQuery solrQuery = new SolrQuery() .setQuery(searchCriteria.getQuery()) .setRows(searchCriteria.getPageSize()) .setStart((start) * searchCriteria.getPageSize()) .setRequestHandler(searchCriteria.getRequestHandler()); int numResults = 0; try { response = solrConfiguration.getServer().query(solrQuery, getSolrQueryMethod()); responseDocuments = getResponseDocuments(response); numResults = (int) response.getResults().getNumFound(); LOG.trace(response.toString());
public List<DSpaceObject> search(Context context, String query, String orderfield, boolean ascending, int offset, int max, String... filterquery) { SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(query); solrQuery.setFields("search.resourceid", "search.resourcetype"); solrQuery.setStart(offset); solrQuery.setRows(max); SolrDocumentList docs = rsp.getResults(); Iterator iter = docs.iterator(); List<DSpaceObject> result = new ArrayList<DSpaceObject>(); while (iter.hasNext()) { SolrDocument doc = (SolrDocument) iter.next(); DSpaceObject o = DSpaceObject.find(context, (Integer) doc.getFirstValue("search.resourcetype"), (Integer) doc.getFirstValue("search.resourceid"));
String collection = query.getStore(); String keyIdField = getKeyFieldId(collection); SolrQuery solrQuery = new SolrQuery(query.getQuery()) .addField(keyIdField) .setIncludeScore(true) .setStart(query.getOffset()) .setRows(query.hasLimit() ? query.getLimit() : maxResults); QueryResponse response = solrClient.query(collection, solrQuery); if (logger.isDebugEnabled()) logger.debug("Executed query [{}] in {} ms", query.getQuery(), response.getElapsedTime()); int totalHits = response.getResults().size(); if (!query.hasLimit() && totalHits >= maxResults) { logger.warn("Query result set truncated to first [{}] elements for query: {}", maxResults, query); for (SolrDocument hit : response.getResults()) { double score = Double.parseDouble(hit.getFieldValue("score").toString()); result.add(new RawQuery.Result<String>(hit.getFieldValue(keyIdField).toString(), score));
public String getDocText(String id) throws SolrServerException { String q = "id:" + id; SolrQuery query = new SolrQuery(); query.setQuery(q); query.setFields("text"); QueryResponse rsp = server.query(query); String docText = ""; if (rsp.getResults().getNumFound() > 0) { @SuppressWarnings({ "unchecked", "rawtypes" }) ArrayList<String> results = (ArrayList) rsp.getResults().get(0) .getFieldValues("text"); docText = results.get(0); } return docText; }
private long countDocs(SolrServer ontologiesSolrServer) throws SolrServerException { SolrQuery countQuery = new SolrQuery("*:*"); countQuery.setRows(0); QueryResponse queryResponse = ontologiesSolrServer.query(countQuery); long count = queryResponse.getResults().getNumFound(); return count; }
/** * @param id * @return SolrDocument with the given identifier or null if the * SolrDocument is not in the index. * @throws SolrServerException * @throws IOException */ public SolrDocument lookupSolrDocument(String id) throws IOException, SolrServerException { if (id == null) { return null; } SolrQuery q = new SolrQuery(SolrQueryUtil.createLiteralQuery( EntityField.ID.solrName(), id)); QueryResponse resp = server.query(q); SolrDocumentList result = resp.getResults(); if (result.getNumFound() == 0) { return null; } else if (result.getNumFound() > 1) { throw new IOException("More than one entity with id: " + id); } else { return result.get(0); } }
public static void doQuery(SolrClient ss, String id) throws SolrServerException, IOException { SolrParams p = new SolrQuery("id:\"" + id + "\""); QueryResponse r = ss.query(p); System.out.println("GOT collection " + r.getResults().get(0).getFieldValue("collection")); System.out.println("GOT collections " + r.getResults().get(0).getFieldValue("collections")); System.out.println("STILL GOT crawl_date " + r.getResults().get(0).getFieldValue("crawl_date")); }
private ServerDetail fetchServerDetails(String hostname, String coreName, SolrServer realTimeThoth) throws SolrServerException { System.out.println("Fetching server details for hostname("+hostname+") coreName("+coreName+")"); QueryResponse qr = realTimeThoth.query(new SolrQuery("hostname_s:\"" + hostname + "\"" +" AND " + "coreName_s:\"" +coreName + "\" AND NOT exception_b:true AND NOT slowQuery_b:true").setRows(1)); SolrDocumentList solrDocumentList = qr.getResults(); ServerDetail sd = null; if (qr.getResults().getNumFound() > 0) { String pool = (String)solrDocumentList.get(0).getFieldValue(POOL); String port = solrDocumentList.get(0).getFieldValue(PORT).toString(); sd = new ServerDetail(hostname, pool, port, coreName); } return sd; }
@Override public String getVersion() { final SolrQuery query = new SolrQuery(); query.setQuery("version:*"); query.set(CommonParams.ROWS, "1"); try { final QueryResponse response = this.externalServicesAccess.getSolrConnection(this).query(query); final SolrDocumentList termList = response.getResults(); if (!termList.isEmpty()) { final SolrDocument firstDoc = termList.get(0); return firstDoc.getFieldValue(VERSION_FIELD_NAME).toString(); } } catch (SolrServerException | SolrException | IOException ex) { this.logger.warn("Failed to query ontology version: {}", ex.getMessage()); } return null; }
@Override public OrcidSolrResult findByOrcid(String orcid) { OrcidSolrResult orcidSolrResult = null; SolrQuery query = new SolrQuery(); query.setQuery(ORCID + ":\"" + orcid + "\"").setFields(SCORE, ORCID, PUBLIC_PROFILE); try { QueryResponse queryResponse = solrServerReadOnly.query(query); if (!queryResponse.getResults().isEmpty()) { SolrDocument solrDocument = queryResponse.getResults().get(0); orcidSolrResult = new OrcidSolrResult(); orcidSolrResult.setRelevancyScore((Float) solrDocument.get(SCORE)); orcidSolrResult.setOrcid((String) solrDocument.get(ORCID)); orcidSolrResult.setPublicProfileMessage((String) solrDocument.getFieldValue(PUBLIC_PROFILE)); } } catch (SolrServerException se) { String errorMessage = MessageFormat.format("Error when attempting to retrieve orcid {0}", new Object[] { orcid }); throw new NonTransientDataAccessResourceException(errorMessage, se); } return orcidSolrResult; }
throw new OaiSetException("Invalid search query."); SolrQuery solrQuery = new SolrQuery(); String restrictedQuery = addQueryRestrictions(query); solrQuery.setQuery(restrictedQuery); solrQuery.setRows(Integer.MAX_VALUE); queryResponse = getSolrServer().query(solrQuery); } catch (RemoteSolrException ex) { String messageFromSolr = ex.getLocalizedMessage(); SolrDocumentList docs = queryResponse.getResults(); Iterator<SolrDocument> iter = docs.iterator(); List<Long> resultIds = new ArrayList<>(); Long entityid = (Long) solrDocument.getFieldValue(SearchFields.ENTITY_ID); resultIds.add(entityid);
@Override public String getVersion() { QueryResponse response; SolrQuery query = new SolrQuery(); SolrDocumentList termList; SolrDocument firstDoc; query.setQuery("version:*"); query.set("rows", "1"); try { response = this.externalServicesAccess.getServer().query(query); termList = response.getResults(); if (!termList.isEmpty()) { firstDoc = termList.get(0); return firstDoc.getFieldValue(VERSION_FIELD_NAME).toString(); } } catch (SolrServerException | SolrException ex) { this.logger.warn("Failed to query ontology version: {}", ex.getMessage()); } return null; } }
String qry="*:*"; SolrQuery query = new SolrQuery(); query.setQuery("*:*"); query.setRows(Integer.MAX_VALUE); //Add me to avoid IndexOutOfBoundExc CommonsHttpSolrServer server = new CommonsHttpSolrServer("http://localhost:8983/solr"); QueryResponse rsp=server.query(query); SolrDocumentList docs=rsp.getResults(); for(int i=0;i<docs.getNumFound();i++){ System.out.println(docs.get(i)); }
@Override public Document getLatest(String guid, String sensorType) throws IOException { if (MetaAlertConstants.METAALERT_TYPE.equals(sensorType)) { // Unfortunately, we can't just defer to the indexDao for this. Child alerts in Solr end up // having to be dug out. String guidClause = Constants.GUID + ":" + guid; SolrQuery query = new SolrQuery(); query.setQuery(guidClause) .setFields("*", "[child parentFilter=" + guidClause + " limit=999]"); try { QueryResponse response = solrDao.getSolrClient(solrDao.getZkHosts()) .query(METAALERTS_COLLECTION, query); // GUID is unique, so it's definitely the first result if (response.getResults().size() == 1) { SolrDocument result = response.getResults().get(0); return SolrUtilities.toDocument(result); } else { return null; } } catch (SolrServerException e) { throw new IOException("Unable to retrieve metaalert", e); } } else { return solrDao.getLatest(guid, sensorType); } }