public void insertOneDoc() throws SolrServerException, IOException { Item item = new Item(); item.id = "5137158701"; SolrServer server = getSolrServer(); //DEBUG UpdateResponse resp= server.addBean(item); System.out.println("SolrResponse:"+ r.getStatus() + r.getElapsedTime()); for( Entry<String, Object> o: r.getResponse()){ System.out.println("SolrResponse - response :"+ o.getKey() + o.getValue().toString()); } server.commit();
// connect to your solr server SolrServer server = new HttpSolrServer("http://HOST:8983/solr/"); // adding a single document SampleDocument document = new SampleDocument(1, "title 1"); server.addBean(document); // adding multiple documents List<SampleDocument> documents = Arrays.asList( new SampleDocument(2, "title 2"), new SampleDocument(3, "title 3")); server.addBeans(documents); // commit changes server.commit(); // query solr for something QueryResponse response = server.query(new SolrQuery("*:*")); // get the response as List of POJO type List<SampleDocument> foundDocuments = response.getBeans(SampleDocument.class);
@Override public void persist(OrcidSolrDocument orcidSolrDocument) { try { solrServer.addBean(orcidSolrDocument); solrServer.commit(); } catch (SolrServerException se) { throw new NonTransientDataAccessResourceException("Error persisting to SOLR Server", se); } catch (IOException ioe) { throw new NonTransientDataAccessResourceException("IOException when persisting to SOLR", ioe); } }
@Override public void persist(OrgDisambiguatedSolrDocument orgDisambiguatedSolrDocument) { try { solrServer.addBean(orgDisambiguatedSolrDocument); solrServer.commit(); } catch (SolrServerException se) { throw new NonTransientDataAccessResourceException("Error persisting org to SOLR Server", se); } catch (IOException ioe) { throw new NonTransientDataAccessResourceException("IOException when persisting org to SOLR", ioe); } }
@Override public void persist(OrgDefinedFundingTypeSolrDocument fundingType) { try { solrServer.addBean(fundingType); solrServer.commit(); } catch (SolrServerException se) { throw new NonTransientDataAccessResourceException("Error persisting funding type to SOLR Server", se); } catch (IOException ioe) { throw new NonTransientDataAccessResourceException("IOException when persisting funding type to SOLR", ioe); } }