/** * Adds a single bean * * The bean is converted to a {@link SolrInputDocument} by the client's * {@link org.apache.solr.client.solrj.beans.DocumentObjectBinder} * * @param obj the input bean * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server * * @throws IOException if there is a communication error with the server * @throws SolrServerException if there is an error on the server */ public UpdateResponse addBean(Object obj) throws IOException, SolrServerException { return addBean(null, obj, -1); }
@Override public void process(Exchange exchange) throws Exception { String operation = (String) exchange.getIn().getHeader(SolrConstants.OPERATION); if (operation == null) { throw new IllegalArgumentException(SolrConstants.OPERATION + " header is missing"); } SolrClient serverToUse = getBestSolrServer(operation); if (operation.equalsIgnoreCase(SolrConstants.OPERATION_INSERT)) { insert(exchange, serverToUse); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_INSERT_STREAMING)) { insert(exchange, serverToUse); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_DELETE_BY_ID)) { serverToUse.deleteById(exchange.getIn().getBody(String.class)); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_DELETE_BY_QUERY)) { serverToUse.deleteByQuery(exchange.getIn().getBody(String.class)); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_ADD_BEAN)) { serverToUse.addBean(exchange.getIn().getBody()); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_ADD_BEANS)) { serverToUse.addBeans(exchange.getIn().getBody(Collection.class)); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_COMMIT)) { serverToUse.commit(); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_ROLLBACK)) { serverToUse.rollback(); } else if (operation.equalsIgnoreCase(SolrConstants.OPERATION_OPTIMIZE)) { serverToUse.optimize(); } else { throw new IllegalArgumentException( SolrConstants.OPERATION + " header value '" + operation + "' is not supported"); } }
/** * Adds a single bean * * The bean is converted to a {@link SolrInputDocument} by the client's * {@link org.apache.solr.client.solrj.beans.DocumentObjectBinder} * * @param obj the input bean * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server * * @throws IOException if there is a communication error with the server * @throws SolrServerException if there is an error on the server */ public UpdateResponse addBean(Object obj) throws IOException, SolrServerException { return addBean(null, obj, -1); }
/** * Adds a single bean * * The bean is converted to a {@link SolrInputDocument} by the client's * {@link org.apache.solr.client.solrj.beans.DocumentObjectBinder} * <p> * Many {@link SolrClient} implementations have drastically slower indexing performance when documents are added * individually. Document batching generally leads to better indexing performance and should be used whenever * possible. * * @param collection to Solr collection to add documents to * @param obj the input bean * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server * * @throws IOException if there is a communication error with the server * @throws SolrServerException if there is an error on the server */ public UpdateResponse addBean(String collection, Object obj) throws IOException, SolrServerException { return addBean(collection, obj, -1); }
/** * Adds a single bean * * The bean is converted to a {@link SolrInputDocument} by the client's * {@link org.apache.solr.client.solrj.beans.DocumentObjectBinder} * * @param collection to Solr collection to add documents to * @param obj the input bean * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server * * @throws IOException if there is a communication error with the server * @throws SolrServerException if there is an error on the server */ public UpdateResponse addBean(String collection, Object obj) throws IOException, SolrServerException { return addBean(collection, obj, -1); }