@Override public void optimizeIndex(SolrClient server) throws ServiceException, IOException { try { if (LOG.isDebugEnabled()) { LOG.debug("Optimizing the index..."); } if (isSolrConfigured) { server.optimize(); } } catch (SolrServerException e) { throw new ServiceException("Could not optimize index", e); } }
@Override public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception { solrClient.optimize(MarkdownDocument.MARKDOWN_CORE); return RepeatStatus.FINISHED; } }
/** * Performs an explicit optimize, causing a merge of all segments to one. * * waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access * * Note: In most cases it is not required to do explicit optimize * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public UpdateResponse optimize() throws SolrServerException, IOException { return optimize(null, true, true, 1); }
/** * Performs an explicit optimize, causing a merge of all segments to one. * <p> * Note: In most cases it is not required to do explicit optimize * * @param waitFlush block until index changes are flushed to disk * @param waitSearcher block until a new searcher is opened and registered as * the main query searcher, making the changes visible * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public UpdateResponse optimize(boolean waitFlush, boolean waitSearcher) throws SolrServerException, IOException { return optimize(null, waitFlush, waitSearcher); }
/** * Performs an explicit optimize, causing a merge of all segments to one. * * waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access * * Note: In most cases it is not required to do explicit optimize * * @param collection the Solr collection to send the optimize to * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public UpdateResponse optimize(String collection) throws SolrServerException, IOException { return optimize(collection, true, true, 1); }
/** * Performs an explicit optimize, causing a merge of all segments to one. * <p> * Note: In most cases it is not required to do explicit optimize * * @param waitFlush block until index changes are flushed to disk * @param waitSearcher block until a new searcher is opened and registered as * the main query searcher, making the changes visible * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public UpdateResponse optimize(boolean waitFlush, boolean waitSearcher) throws SolrServerException, IOException { return optimize(null, waitFlush, waitSearcher); }
/** * Performs an explicit optimize, causing a merge of all segments to one. * * Note: In most cases it is not required to do explicit optimize * * @param waitFlush block until index changes are flushed to disk * @param waitSearcher block until a new searcher is opened and registered as * the main query searcher, making the changes visible * @param maxSegments optimizes down to at most this number of segments * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public UpdateResponse optimize(boolean waitFlush, boolean waitSearcher, int maxSegments) throws SolrServerException, IOException { return optimize(null, waitFlush, waitSearcher, maxSegments); }
/** * Performs an explicit optimize, causing a merge of all segments to one. * * waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access * * Note: In most cases it is not required to do explicit optimize * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public UpdateResponse optimize() throws SolrServerException, IOException { return optimize(null, true, true, 1); }
/** * Performs an explicit optimize, causing a merge of all segments to one. * <p> * Note: In most cases it is not required to do explicit optimize * * @param collection the Solr collection to send the optimize to * @param waitFlush block until index changes are flushed to disk * @param waitSearcher block until a new searcher is opened and registered as * the main query searcher, making the changes visible * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public UpdateResponse optimize(String collection, boolean waitFlush, boolean waitSearcher) throws SolrServerException, IOException { return optimize(collection, waitFlush, waitSearcher, 1); }
/** * Performs an explicit optimize, causing a merge of all segments to one. * <p> * Note: In most cases it is not required to do explicit optimize * * @param collection the Solr collection to send the optimize to * @param waitFlush block until index changes are flushed to disk * @param waitSearcher block until a new searcher is opened and registered as * the main query searcher, making the changes visible * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public UpdateResponse optimize(String collection, boolean waitFlush, boolean waitSearcher) throws SolrServerException, IOException { return optimize(collection, waitFlush, waitSearcher, 1); }
/** * Performs an explicit optimize, causing a merge of all segments to one. * * waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access * * Note: In most cases it is not required to do explicit optimize * * @param collection the Solr collection to send the optimize to * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public UpdateResponse optimize(String collection) throws SolrServerException, IOException { return optimize(collection, true, true, 1); }
/** * Performs an explicit optimize, causing a merge of all segments to one. * * Note: In most cases it is not required to do explicit optimize * * @param waitFlush block until index changes are flushed to disk * @param waitSearcher block until a new searcher is opened and registered as * the main query searcher, making the changes visible * @param maxSegments optimizes down to at most this number of segments * * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} containing the response * from the server * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public UpdateResponse optimize(boolean waitFlush, boolean waitSearcher, int maxSegments) throws SolrServerException, IOException { return optimize(null, waitFlush, waitSearcher, maxSegments); }
private void optimize(SolrClient solrClient) throws IOException { long startTime = System.currentTimeMillis(); try { solrClient.optimize(); LOG.info("Optimizing Solr Index finished in " + (System.currentTimeMillis() - startTime) + "ms"); } catch (SolrServerException e) { LOG.error("Error while optimizing", e); e.printStackTrace(); } }
private void optimize(SolrClient solrClient) throws IOException { long startTime = System.currentTimeMillis(); try { solrClient.optimize(); LOG.info("Optimizing Solr Index finished in " + (System.currentTimeMillis() - startTime) + "ms"); } catch (SolrServerException e) { LOG.error("Error while optimizing", e); e.printStackTrace(); } }
public void optimizeAIPs() throws GenericException, AuthorizationDeniedException { RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); try { getSolrClient().optimize(RodaConstants.INDEX_AIP); getSolrClient().optimize(RodaConstants.INDEX_FILE); getSolrClient().optimize(RodaConstants.INDEX_REPRESENTATION); getSolrClient().optimize(RodaConstants.INDEX_PRESERVATION_EVENTS); getSolrClient().optimize(RodaConstants.INDEX_PRESERVATION_AGENTS); } catch (SolrServerException | IOException e) { throw new GenericException("Error while optimizing indexes", e); } }
protected void run() throws SolrServerException, IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String line = reader.readLine(); while (line != null) { if (!line.startsWith("#")) { docs++; solr.add(makeDoc(line)); if (docs % 1000 == 0) { System.out.println("Docs: " + docs); } } line = reader.readLine(); } reader.close(); System.out.println("Optimizing..."); solr.optimize(); }
@Override public void commit(boolean optimize) { try { solrClientLogger.debug(">>> commit()"); this.solrClient.commit(); if(optimize) { solrClientLogger.debug(">>> optimize()"); this.solrClient.optimize(); } } catch (SolrServerException | IOException e) { log.error("Cannot commit", e); throw new SearchServerException("Cannot commit", e); } }
@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"); } }
public void optimizeIndex(String indexName) throws GenericException, AuthorizationDeniedException { RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); try { getSolrClient().optimize(indexName); } catch (SolrServerException | IOException e) { throw new GenericException("Error while optimizing indexes", e); } }
reader.close(); System.out.println("Optimizing..."); solr.optimize(); solr.close();