public String toString() { return solrServer.getBaseURL(); } }
public String removeSolrServer(String server) { try { server = new URL(server).toExternalForm(); } catch (MalformedURLException e) { throw new RuntimeException(e); } if (server.endsWith("/")) { server = server.substring(0, server.length() - 1); } this.checkLock.lock(); try { for (ServerWrapper serverWrapper : aliveServers) { if (serverWrapper.solrServer.getBaseURL().equals(server)) { aliveServers.remove(serverWrapper); return serverWrapper.solrServer.getBaseURL(); } } if (zombieServers.isEmpty()) return null; for (ServerWrapper serverWrapper : zombieServers) { if (serverWrapper.solrServer.getBaseURL().equals(server)) { zombieServers.remove(serverWrapper); return serverWrapper.solrServer.getBaseURL(); } } } finally { checkLock.unlock(); } return null; }
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; }
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);
public InputStream searchJSON(DiscoverQuery query, String jsonIdentifier) throws SearchServiceException { Map<String, String> params = new HashMap<String, String>(); String solrRequestUrl = solr.getBaseURL() + "/select";
/** * Perform a Solr search and stream the results into the provided output * * @param request : A prepared SearchRequest object * @param response : The OutputStream to send results to * @throws IndexerException if there were errors during the search */ @Override public void search(SearchRequest request, OutputStream response) throws IndexerException { SolrSearcher searcher = new SolrSearcher( ((CommonsHttpSolrServer) solr).getBaseURL()); String username = usernameMap.get("solr"); String password = passwordMap.get("solr"); if (username != null && password != null) { searcher.authenticate(username, password); } InputStream result; try { request.addParam("wt", "json"); result = searcher.get(request.getQuery(), request.getParamsMap(), false); IOUtils.copy(result, response); result.close(); } catch (IOException ioe) { throw new IndexerException(ioe); } }
SolrSearcher searcher = new SolrSearcher( ((CommonsHttpSolrServer) solrServerMap.get(indexName)) .getBaseURL()); String username = usernameMap.get(indexName); String password = passwordMap.get(indexName);
/** * Search for annotations and return the result to the provided stream * * @param request : The SearchRequest object * @param response : The OutputStream to send responses to * @throws IndexerException if there were errors during indexing */ @Override public void annotateSearch(SearchRequest request, OutputStream response) throws IndexerException { SolrSearcher searcher = new SolrSearcher( ((CommonsHttpSolrServer) anotar).getBaseURL()); String username = usernameMap.get("anotar"); String password = passwordMap.get("anotar"); if (username != null && password != null) { searcher.authenticate(username, password); } InputStream result; try { request.addParam("wt", "json"); result = searcher.get(request.getQuery(), request.getParamsMap(), false); IOUtils.copy(result, response); result.close(); } catch (IOException ioe) { throw new IndexerException(ioe); } }
String format) throws IndexerException { SolrSearcher searcher = new SolrSearcher( ((CommonsHttpSolrServer) solr).getBaseURL()); String username = usernameMap.get("solr"); String password = passwordMap.get("solr");
params.put(CommonParams.START, String.valueOf(i)); String solrRequestUrl = solr.getBaseURL() + "/select"; solrRequestUrl = generateURL(solrRequestUrl, params);
public IFeedResults getIFeedResults(IFeed iFeed) { addFeedFilters(iFeed); addUnPublishedFilter(); SortDirection direction = isBlank(iFeed.getSortDirection()) ? DEFAULT_SORT_DIRECTION : SortDirection .valueOf(iFeed.getSortDirection()); IFeedResults results = new IFeedResults(); if (solrServer instanceof CommonsHttpSolrServer) { CommonsHttpSolrServer chss = (CommonsHttpSolrServer) solrServer; results.setQueryUrl(chss.getBaseURL() + "/select" + ClientUtils.toQueryString(this, false)); } else { results.setQueryUrl(ClientUtils.toQueryString(this, false)); } results.addAll(prepareAndPerformQuery(iFeed.getSortField(), direction)); return results; }