public WikipediaWexIndexer() throws MalformedURLException { this.server = new CommonsHttpSolrServer(DEFAULT_SOLR_URL); }
public String toString() { return solrServer.getBaseURL(); } }
public QueryResponse basicQuery(ModifiableSolrParams params) { try { QueryResponse response = server.query(params); return response; } catch(SolrServerException e) { return null; } }
CommonsHttpSolrServer solrj = new CommonsHttpSolrServer("http://" + addr.getHostAddress() + ":" + CassandraUtils.port + "/solandra/" + subIndex, new HttpClient(httpConnections)); solrj.deleteByQuery(cmd.query);
/** * Delete data from the index, as described by a query. * * @param query description of the records to be deleted. * @throws IOException * @throws SolrServerException */ public static void removeIndex(String query) throws IOException, SolrServerException { solr.deleteByQuery(query); solr.commit(); }
/** * Constructor. Prepares solr connection. * * @param url * the connection url to the solr server */ public static SolrServer newRemoteInstance(URL url) { try { CommonsHttpSolrServer server = new CommonsHttpSolrServer(url); server.setSoTimeout(5000); server.setConnectionTimeout(5000); server.setDefaultMaxConnectionsPerHost(100); server.setMaxTotalConnections(100); server.setFollowRedirects(false); // defaults to false server.setAllowCompression(true); server.setMaxRetries(1); // defaults to 0. > 1 not recommended. server.setParser(new XMLResponseParser()); // binary parser is used by default return server; } catch (Exception e) { throw new RuntimeException(e); } }
HttpClient httpClient = httpClientFactory.getHttpClient(); server = new CommonsHttpSolrServer(solrUrl, httpClient); server.setParser(new XMLResponseParser()); server.getHttpClient().getState().setCredentials(new AuthScope(solrHost, solrPort, AuthScope.ANY_REALM), defaultcreds); server.setConnectionTimeout(solrConnectTimeout); server.setSoTimeout(20000);
CommonsHttpSolrServer thisCore = new CommonsHttpSolrServer( solrUri.toURL()); String username = config.getString(null, "indexer", coreName, UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( username, password); HttpClient hc = (thisCore).getHttpClient(); hc.getParams().setAuthenticationPreemptive(true); hc.getState().setCredentials(AuthScope.ANY, credentials);
@Test public void testSolr() throws IOException, SolrServerException { Set<Cluster.Instance> instances = cluster.getInstancesMatching(role(SOLR_ROLE)); for (Cluster.Instance instance : instances) { String publicIp = instance.getPublicIp(); LOG.info("Adding a document to instance " + instance.getId() + " @ " + publicIp); CommonsHttpSolrServer solrServer = new CommonsHttpSolrServer(String.format("http://%s:%s/solr/core0", instance.getPublicHostName(), SOLR_PORT)); SolrInputDocument doc = new SolrInputDocument(); doc.addField("name", "Apache Whirr"); doc.addField("inceptionYear", "2010"); solrServer.add(doc); solrServer.commit(); LOG.info("Committed document to instance " + instance.getId() + " @ " + publicIp); LOG.info("Performing a search on instance " + instance.getId() + " @ " + publicIp); SolrQuery query = new SolrQuery("name:whirr"); QueryResponse response = solrServer.query(query); SolrDocumentList results = response.getResults(); assertEquals("Search on instance " + instance.getId() + " did NOT return a document!" , 1, results.size()); SolrDocument resultDoc = results.get(0); assertEquals("name field on document of instance " + instance.getId() + " is incorrect", "Apache Whirr", resultDoc.get("name")); } }
CommonsHttpSolrServer solr = new CommonsHttpSolrServer( ConfigurationManager.getProperty("solr-statistics", "server")); solr.deleteByQuery("*:*"); solr.commit(); solr.add(doc1); solr.commit();
CommonsHttpSolrServer commonsHttpSolrServer = new CommonsHttpSolrServer("solr_path_url"); commonsHttpSolrServer.setParser(new XMLResponseParser()); ModifiableSolrParams params = new ModifiableSolrParams(); // Specify the Request handler params.add("qt", "dismax_request_handler"); params.add("q", "query_string"); QueryResponse response = commonsHttpSolrServer.query(params);
solr = new CommonsHttpSolrServer(solrService); solr.setBaseURL(solrService); solr.query(solrQuery);
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)); }
long totalRecords = solr.query(query).getResults().getNumFound(); params.put(CommonParams.START, String.valueOf(i)); String solrRequestUrl = solr.getBaseURL() + "/select"; solrRequestUrl = generateURL(solrRequestUrl, params); contentStreamUpdateRequest.addFile(tempCsv); solr.request(contentStreamUpdateRequest); solr.deleteByQuery("-bundleName:[* TO *] AND type:" + Constants.BITSTREAM); solr.commit(true, true);
this.container = null; log.debug("Instantiating new SolrService (CommonsHttpSolrServer) with solr.solr.home '{}'", solrhome); CommonsHttpSolrServer httpserv = new CommonsHttpSolrServer(solrhome); httpserv.setAllowCompression(true); this.server = httpserv;
throw new SubscriberException("No Solr URI provided"); core = new CommonsHttpSolrServer(uri.toURL()); core.ping(); serverOnline = true; } catch (Exception ex) {
public static SchemaInfo retrieveSchemaInfo(SolrServer solrServer) throws IOException { SchemaInfo schemaInfo = new SchemaInfo(); if (solrServer instanceof CommonsHttpSolrServer) { final CommonsHttpSolrServer solr = (CommonsHttpSolrServer) solrServer; final String url = solr.getBaseURL()+"/admin/file/?file=schema.xml"; final GetMethod method = new GetMethod(url); final int code = solr.getHttpClient().executeMethod(method); XPath xpath = XPathFactory.newInstance().newXPath(); String expression = "/schema/fields/field"; InputStream stream = method.getResponseBodyAsStream(); InputSource inputSource = new InputSource(stream); try { NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET); for (int i=0; i<nodes.getLength(); i++) { final String fieldName = nodes.item(i).getAttributes().getNamedItem("name").getNodeValue(); schemaInfo.addFieldName(fieldName); } } catch (XPathExpressionException e) { e.printStackTrace(); } finally { stream.close(); } } else { throw new IllegalArgumentException("Cannot get schema for SolrServer with class: "+solrServer.getClass().getName()); } return schemaInfo; }
solr.deleteByQuery(query); solr.add(newInput); solr.commit();
getSolr().deleteByQuery("*:*"); } else { SolrQuery query = new SolrQuery(); query.setQuery("*:*"); QueryResponse rsp = getSolr().query(query); SolrDocumentList docs = rsp.getResults();