UpdateResponse response = getSolr().getSolrClient().add(batch, COMMIT_INTERVAL); if (response.getStatus() != 0) { LOGGER.warn("Bad response code indexing documents: " + response.getStatus());
@Override public void start(ILifecycleProgressMonitor monitor) throws SiteWhereException { LOGGER.info("Solr search provider starting."); if (getSolr() == null) { throw new SiteWhereException("No Solr configuration provided to " + getClass().getName()); } try { LOGGER.info("Attempting to ping Solr server to verify availability..."); SolrPingResponse response = getSolr().getSolrClient().ping(); int pingTime = response.getQTime(); LOGGER.info("Solr server location verified. Ping responded in " + pingTime + " ms."); } catch (SolrServerException e) { throw new SiteWhereException("Ping failed. Verify that Solr server is available.", e); } catch (IOException e) { throw new SiteWhereException("Exception in ping. Verify that Solr server is available.", e); } LOGGER.info("Solr search provider started."); }
@Override public void start(ILifecycleProgressMonitor monitor) throws SiteWhereException { // Required for filters. super.start(monitor); if (getSolr() == null) { throw new SiteWhereException("No Solr configuration provided to " + getClass().getName()); } try { LOGGER.info("Attempting to ping Solr server to verify availability..."); SolrPingResponse response = getSolr().getSolrClient().ping(); int pingTime = response.getQTime(); LOGGER.info("Solr server location verified. Ping responded in " + pingTime + " ms."); } catch (SolrServerException e) { throw new SiteWhereException("Ping failed. Verify that Solr server is available.", e); } catch (IOException e) { throw new SiteWhereException("Exception in ping. Verify that Solr server is available.", e); } LOGGER.info("Solr event processor indexing events to server at: " + getSolr().getSolrServerUrl()); executor.execute(new SolrDocumentQueueProcessor()); }
@Override public List<IDeviceEvent> executeQuery(String queryString) throws SiteWhereException { try { LOGGER.debug("About to execute Solr search with query string: " + queryString); List<IDeviceEvent> results = new ArrayList<IDeviceEvent>(); SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(queryString); QueryResponse response = getSolr().getSolrClient().query(solrQuery); SolrDocumentList docs = response.getResults(); for (SolrDocument doc : docs) { results.add(SiteWhereSolrFactory.parseDocument(doc)); } return results; } catch (SolrServerException e) { throw new SiteWhereException("Unable to execute query.", e); } catch (IOException e) { throw new SiteWhereException("Unable to execute query.", e); } }
@Override public List<IDeviceLocation> getLocationsNear(double latitude, double longitude, double distance, IDateRangeSearchCriteria criteria) throws SiteWhereException { ModifiableSolrParams params = new ModifiableSolrParams(); try { QueryResponse response = getSolr().getSolrClient().query(params); SolrDocumentList docs = response.getResults(); while (docs.iterator().hasNext()) { SolrDocument doc = docs.iterator().next(); doc.getFieldNames(); } List<IDeviceLocation> results = new ArrayList<IDeviceLocation>(); return results; } catch (SolrServerException e) { throw new SiteWhereException("Unable to execute 'getLocationsNear' query.", e); } catch (IOException e) { throw new SiteWhereException("Unable to execute query.", e); } }
@Override public JsonNode executeQueryWithRawResponse(String queryString) throws SiteWhereException { try { LOGGER.debug("About to execute Solr search with query string: " + queryString); NoOpResponseParser rawJsonResponseParser = new NoOpResponseParser(); rawJsonResponseParser.setWriterType("json"); SolrQuery query = new SolrQuery(); query.add(createParamsFromQueryString(queryString)); QueryRequest request = new QueryRequest(query); request.setResponseParser(rawJsonResponseParser); NamedList<?> results = getSolr().getSolrClient().request(request); return MAPPER.readTree((String) results.get("response")); } catch (SolrServerException e) { throw new SiteWhereException("Unable to execute query.", e); } catch (IOException e) { throw new SiteWhereException("Unable to execute query.", e); } }