Refine search
/** * Initialize any state for this DB. Called once per DB instance; there is one DB instance per * client thread. */ @Override public void init() throws DBException { Properties props = getProperties(); commitTime = Integer .parseInt(props.getProperty("solr.commit.within.time", DEFAULT_COMMIT_WITHIN_TIME)); batchMode = Boolean.parseBoolean(props.getProperty("solr.batch.mode", DEFAULT_BATCH_MODE)); String jaasConfPath = props.getProperty("solr.jaas.conf.path"); if(jaasConfPath != null) { System.setProperty("java.security.auth.login.config", jaasConfPath); HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); } // Check if Solr cluster is running in SolrCloud or Stand-alone mode Boolean cloudMode = Boolean.parseBoolean(props.getProperty("solr.cloud", DEFAULT_CLOUD_MODE)); System.err.println("Solr Cloud Mode = " + cloudMode); if (cloudMode) { System.err.println("Solr Zookeeper Remote Hosts = " + props.getProperty("solr.zookeeper.hosts", DEFAULT_ZOOKEEPER_HOSTS)); client = new CloudSolrClient( props.getProperty("solr.zookeeper.hosts", DEFAULT_ZOOKEEPER_HOSTS)); } else { client = new HttpSolrClient(props.getProperty("solr.base.url", DEFAULT_SOLR_BASE_URL)); } }
protected String determineCoreName(HttpSolrClient httpSolrClient) { String url = httpSolrClient.getBaseURL(); String coreName = url.substring(url.lastIndexOf('/') + 1); return coreName; }
private SolrClient initializeWithExistingHttpServer() throws IOException, SolrServerException { // try basic Solr HTTP client HttpSolrClient httpSolrServer = new HttpSolrClient(remoteSolrServerConfiguration.getSolrHttpUrls()[0]); httpSolrServer.setConnectionTimeout(remoteSolrServerConfiguration.getConnectionTimeout()); httpSolrServer.setSoTimeout(remoteSolrServerConfiguration.getSocketTimeout()); SolrPingResponse ping = httpSolrServer.ping(); if (ping != null && 0 == ping.getStatus()) { return httpSolrServer; } else { httpSolrServer.close(); throw new IOException("the found HTTP Solr server is not alive"); } }
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()); }
@Bean public HttpSolrClient solrClient(@Value("${solr.url}") String solrUrl, @Value("${solr.pool.maxTotalConnections}") Integer maxTotalConnections) throws MalformedURLException { HttpSolrClient solrClient = new HttpSolrClient(solrUrl); solrClient.setParser(new TextXMLResponseParser()); solrClient.setMaxTotalConnections(maxTotalConnections); solrClient.setDefaultMaxConnectionsPerHost(maxTotalConnections); return solrClient; }
protected HttpSolrClient makeSolrClient(String server) { HttpSolrClient client = new HttpSolrClient(server, httpClient, parser); if (requestWriter != null) { client.setRequestWriter(requestWriter); } if (queryParams != null) { client.setQueryParams(queryParams); } return client; }
/** * Uses the supplied HttpClient to send documents to the Solr server. */ public ConcurrentUpdateSolrClient(String solrServerUrl, HttpClient client, int queueSize, int threadCount, ExecutorService es, boolean streamDeletes) { this.client = new HttpSolrClient(solrServerUrl, client); this.client.setFollowRedirects(false); queue = new LinkedBlockingQueue<>(queueSize); this.threadCount = threadCount; runners = new LinkedList<>(); scheduler = es; this.streamDeletes = streamDeletes; }
this.server = new Builder().withInvariantParams(params).build(); this.server.setSoTimeout(config.getSoTimeout()); this.server.setConnectionTimeout(config.getConnTimeout()); this.server.setMaxTotalConnections(config.getMaxConns()); this.server.setAllowCompression(config.getAllowCompression()); ((DefaultHttpClient)this.server.getHttpClient()).setHttpRequestRetryHandler(new SolrHttpRequestRetryHandler(config.getMaxRetries()));
private SolrClient getStandaloneIndexSolrClient() { if (StringUtils.isEmpty(solrMaster)) { try { throw new AEMSolrSearchException( "Initialization failed. The property 'solr-master' is missing for Standalone mode."); } catch (AEMSolrSearchException e) { LOG.error("Solr client initialization failed.", e); } } LOG.debug("Creating HttpSolrClient using solrMaster '{}'", solrMaster); HttpSolrClient client = new HttpSolrClient(solrMaster); client.setParser(new XMLResponseParser()); return client; }
this.adminServer = new HttpSolrClient(SolrClientUrl); this.server = new HttpSolrClient( SolrClientUrl + "/" + mapping.getCoreName() ); if (serverUserAuth) { HttpClientUtil.setBasicAuth( (DefaultHttpClient) ((HttpSolrClient) adminServer).getHttpClient(), serverUsername, serverPassword); HttpClientUtil.setBasicAuth( (DefaultHttpClient) ((HttpSolrClient) server).getHttpClient(), serverUsername, serverPassword);
/** * Creates the datastore. * * @param url The URL of SOLR server * @param layerMapper The document loader. */ public SolrDataStore(URL url, SolrLayerMapper layerMapper) { // TODO: make connection timeouts configurable this.url = url; this.layerMapper = layerMapper; this.solrServer = new HttpSolrClient.Builder() .withBaseSolrUrl(url.toString()) .allowCompression(true) .build(); this.solrServer.setConnectionTimeout(10000); this.solrServer.setFollowRedirects(true); this.solrServer.setSoTimeout(10000); }
HttpSolrClient solr = new HttpSolrClient.Builder(solrServer).build(); solr.deleteByQuery("*:*"); solr.add(solrDocumentList); solr.commit(); SolrQuery query = new SolrQuery("*:*"); QueryResponse response = solr.query(query); SolrDocumentList results = response.getResults(); System.out.printf("Retrieved %d of %d\n", results.size(), results.getNumFound());
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()); }
/** * Closes the Stream to a single Solr Instance * */ public void close() throws IOException { if (closeableHttpResponse != null) { closeableHttpResponse.close(); } if(cache == null) { client.close(); } }
requestParams.set(CommonParams.VERSION, client.parser.getVersion()); method = new HttpPost(client.getBaseURL() + "/update" + ClientUtils.toQueryString(requestParams, false)); method.setEntity(template); method.addHeader("Content-Type", contentType); response = client.getHttpClient().execute(method); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { } catch (Exception exc) { log.warn("Failed to parse error response from "+ client.getBaseURL()+" due to: "+exc);
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); } }
/** * set soTimeout (read timeout) on the underlying HttpConnectionManager. This is desirable for queries, but probably * not for indexing. */ public void setSoTimeout(int timeout) { HttpClientUtil.setSoTimeout(client.getHttpClient(), timeout); }
throws SolrServerException, IOException { if (!(request instanceof UpdateRequest)) { return client.request(request, collection); if (req.getDeleteQuery() == null) { blockUntilFinished(); return client.request(request, collection); if ((req.getDocuments() == null || req.getDocuments().isEmpty())) { blockUntilFinished(); return client.request(request, collection); log.info("blocking for commit/optimize"); return client.request(request, collection); MDC.put("ConcurrentUpdateSolrClient.url", client.getBaseURL()); try { Runner r = new Runner();
for (String url : urls) { HttpSolrClient server = new HttpSolrClient.Builder(url).build(); server.commit(); server.close();