RetrieveAndRank service = new RetrieveAndRank(); service.setUsernameAndPassword("{username}","{password}"); HttpSolrClient solrClient = new HttpSolrClient; solrClient = getSolrClient(service.getSolrUrl("scfaaf8903_02c1_4297_84c6_76b79537d849"), "{username}","{password}"); SolrQuery query = new SolrQuery("what is the basic mechanism of the transonic aileron buzz"); QueryResponse response = solrClient.query("example_collection", query); Ranking ranking = service.rank("B2E325-rank-67", response); System.out.println(ranking);
private static final Logger LOGGER = Logger.getLogger(SolrCient.class.getName()); private static final String SERVER_URL = "http://localhost:8983/solr/suggest"; public static void main(String[] args) throws IOException, SolrServerException { HttpSolrClient solr = new HttpSolrClient(SERVER_URL); QueryResponse response = solr.query(new SolrQuery("*:*")); System.out.println(response.toString()); }
@Override public QueryResponse query(SolrQuery params) throws TranslatorException { try { return server.query(params); } catch (SolrServerException e) { throw new TranslatorException(e); } catch (IOException e) { throw new TranslatorException(e); } }
@Override public QueryResponse query(SolrQuery params) throws TranslatorException { try { return server.query(params); } catch (SolrServerException e) { throw new TranslatorException(e); } catch (IOException e) { throw new TranslatorException(e); } }
RetrieveAndRank service = new RetrieveAndRank(); service.setUsernameAndPassword(USERNAME, PASSWORD); // create the solr client String solrUrl = service.getSolrUrl(SOLR_CLUSTER_ID); HttpClient client = createHttpClient(solrUrl, USERNAME, PASSWORD); HttpSolrClient solrClient = new HttpSolrClient(solrUrl, client); // build the query SolrQuery query = new SolrQuery("*:*"); query.setRequestHandler("/fcselect"); query.set("ranker_id", RANKER_ID); // execute the query QueryResponse response = solrClient.query(SOLR_COLLECTION_NAME, query); System.out.println("Found " + response.getResults().size() + " documents!"); System.out.println(response);
private QueryResponse query(SolrQuery query, int offset, int maxRows) throws ServiceException { query.set(CommonParams.START, offset) .set(CommonParams.ROWS, maxRows) .set(CommonParams.WT, solrClient.getParser().getWriterType()); try { Instant start = Instant.now(); QueryResponse queryResponse = solrClient.query(query); LOG.info("Responded in {}ms for query {}", new Duration(start, Instant.now()).getMillis(), query.getQuery()); return queryResponse; } catch (SolrServerException | IOException e) { StringBuilder sb = new StringBuilder() .append(e.getMessage()) .append(" for generated query: ") .append(query.getQuery()); throw new ServiceException(sb.toString(), e); } }
public List<Question> searchQuestion(String keyword, int offset, int count, String hlPre, String hlPos) throws IOException, SolrServerException { List<Question> questionList = new ArrayList<>(); SolrQuery query = new SolrQuery(keyword); query.setRows(count); query.setStart(offset); query.setHighlight(true); query.setHighlightSimplePre(hlPre); query.setHighlightSimplePost(hlPos); query.set("hl.fl", QUESTION_TITLE_FIELD + "," + QUESTION_CONTENT_FIELD); QueryResponse response = client.query(query); for (Map.Entry<String, Map<String, List<String>>> entry : response.getHighlighting().entrySet()) { Question q = new Question(); q.setId(Integer.parseInt(entry.getKey())); if (entry.getValue().containsKey(QUESTION_CONTENT_FIELD)) { List<String> contentList = entry.getValue().get(QUESTION_CONTENT_FIELD); if (contentList.size() > 0) { q.setContent(contentList.get(0)); } } if (entry.getValue().containsKey(QUESTION_TITLE_FIELD)) { List<String> titleList = entry.getValue().get(QUESTION_TITLE_FIELD); if (titleList.size() > 0) { q.setTitle(titleList.get(0)); } } questionList.add(q); } return questionList; }
try { zombieServer.lastChecked = currTime; QueryResponse resp = zombieServer.client.query(solrQuery); if (resp.getStatus() == 0) {
protected void logReplicationDetails(Replica replica, StringBuilder builder) throws IOException { try (HttpSolrClient client = new HttpSolrClient.Builder(replica.getCoreUrl()).build()) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("qt", "/replication"); params.set(ReplicationHandler.COMMAND, ReplicationHandler.CMD_DETAILS); try { QueryResponse response = client.query(params); builder.append(String.format(Locale.ROOT, "%s: %s%s", replica.getName(), response.getResponse(), System.lineSeparator())); } catch (SolrServerException e) { log.warn("Unable to ger replication details for replica {}", replica.getName(), e); } } }
QueryResponse resp = zombieServer.client.query(solrQuery); if (resp.getStatus() == 0) {
solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark); try { QueryResponse rsp = server.query(solrQuery); if (this.solrDataStore.getLogger().isLoggable(Level.FINE)) { this.solrDataStore.getLogger().log(Level.FINE, solrQuery.toString());
@Override public List<String> createTypeNames(HttpSolrClient solrServer) throws Exception { List<String> names = new ArrayList<>(); SolrQuery query = new SolrQuery(); query.setQuery("*:*"); query.addFacetField(field); query.setFacet(true); query.setFacetMinCount(1); query.setFacetSort(FacetParams.FACET_SORT_INDEX); query.setRows(0); query.setParam("omitHeader", true); QueryResponse rsp = solrServer.query(query); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "SOLR query done: " + query.toString()); } List<Count> uniqueFacetFields = rsp.getFacetFields().get(0).getValues(); for (Count field : uniqueFacetFields) { names.add(field.getName()); } return names; }
protected long getIndexVersion(Replica replica) throws IOException { try (HttpSolrClient client = new HttpSolrClient.Builder(replica.getCoreUrl()).build()) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("qt", "/replication"); params.set(ReplicationHandler.COMMAND, ReplicationHandler.CMD_SHOW_COMMITS); try { QueryResponse response = client.query(params); @SuppressWarnings("unchecked") List<NamedList<Object>> commits = (List<NamedList<Object>>)response.getResponse().get(ReplicationHandler.CMD_SHOW_COMMITS); Collections.max(commits, (a,b)->((Long)a.get("indexVersion")).compareTo((Long)b.get("indexVersion"))); return (long) Collections.max(commits, (a,b)->((Long)a.get("indexVersion")).compareTo((Long)b.get("indexVersion"))).get("indexVersion"); } catch (SolrServerException e) { log.warn("Exception getting version from {}, will return an invalid version to retry.", replica.getName(), e); return -1; } } }
QueryResponse rsp = solrServer.query(q); values = rsp.getGroupResponse()
private String getCursorMarkForStart(HttpSolrClient server, SolrQuery solrQuery) throws SolrServerException, IOException { Integer prevRows = solrQuery.getRows(); solrQuery.setRows(solrQuery.getStart()); solrQuery.setStart(0); solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, CursorMarkParams.CURSOR_MARK_START); QueryResponse rsp = server.query(solrQuery); if (this.solrDataStore.getLogger().isLoggable(Level.FINE)) { this.solrDataStore .getLogger() .log(Level.FINE, "SOLR query done: " + solrQuery.toString()); } String nextC = rsp.getNextCursorMark(); solrQuery.setRows(prevRows); return nextC; }
public static void waitForNon403or404or503(HttpSolrClient collectionClient) throws Exception { SolrException exp = null; final TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME); while (! timeout.hasTimedOut()) { boolean missing = false; try { collectionClient.query(new SolrQuery("*:*")); } catch (SolrException e) { if (!(e.code() == 403 || e.code() == 503 || e.code() == 404)) { throw e; } exp = e; missing = true; } if (!missing) { return; } Thread.sleep(50); } fail("Could not find the new collection - " + exp.code() + " : " + collectionClient.getBaseURL()); }
QueryResponse rsp = server.query(q); count = new Long(rsp.getResults().getNumFound() - rsp.getResults().getStart())
QueryResponse rsp = server.query(solrQuery); if (this.solrDataStore.getLogger().isLoggable(Level.FINE)) { this.solrDataStore
List<LogSearchResult.LogDocument> results = new ArrayList<>(); try { QueryResponse response = solr.query(query);
List<EventSearchResult.Event> results = new ArrayList<>(); try { QueryResponse response = solr.query(query);