private SearchResults parse(Response response) { SearchResults sr = new SearchResults(); ObjectMapper m = new ObjectMapper(); try { JsonNode rootNode = m.readValue(response.getBody(), JsonNode.class); Iterator<JsonNode> i = rootNode.get("businesses").getElements(); while (i.hasNext()) { try { JsonNode j = i.next(); Venue v = new Venue(); // TODO:protect the code,man String address = j.get("location").get("address").getElementValue(0).getTextValue(); v.setAddress(address); v.setName(j.get("name").getTextValue()); v.setPhone(j.get("phone").getTextValue()); v.setPhoto(j.get("image_url").getTextValue()); sr.getResults().add(v); } catch (Exception e) { // TODO: handle exception } } return sr; } catch (Exception e) { return null; } }
@Before public void initSearcher() throws Exception { service = new SolrSearchService(); System.setProperty( "solr.solr.home", SolrTest.class.getClassLoader().getResource(".").getPath() + "solr-test"); SolrServer solrServer = SolrServerFactory.newEmbeddedInstance( new File( SolrTest.class.getClassLoader().getResource(".").getPath() + "/solr-test/venues/conf"), new File("/tmp/solrdataDir")); solrServer.deleteById("1"); solrServer.commit(); Venue v = new Venue(); v.setId(1l); v.setName("La nueva galicia"); v.setAddress("Calle del pozo,13"); v.setSlug("nueva-galicia"); solrServer.addBean(v); solrServer.commit(); service.setSolr(solrServer); }