private void submitBuffer ( boolean forceCommit ) { int size = docBuffer . size ( ) ; if ( size > 0 ) { // Debugging // String age = String.valueOf( // ((new Date().getTime()) - bufferOldest) / 1000); // String length = String.valueOf(bufferSize); // log.debug("Submitting buffer: " + size + " documents, " + length // + // " bytes, " + age + "s"); log . debug ( "=== Submitting buffer: " + size + " documents" ) ; // Concatenate all documents in the buffer StringBuffer submissionBuffer = new StringBuffer ( ) ; for ( String doc : docBuffer . keySet ( ) ) { submissionBuffer . append ( docBuffer . get ( doc ) ) ; // log.debug("DOC: {}", doc); } // Submit if the result is valid if ( submissionBuffer . length ( ) > 0 ) { // Wrap in the basic Solr 'add' node String submission = submissionBuffer . insert ( 0 , "<add>" ) . append ( "</add>" ) . toString ( ) ; // And submit try { solr . request ( new DirectXmlRequest ( "/update" , submission ) ) ; } catch ( Exception ex ) { log . error ( "Error submitting documents to Solr!" , ex ) ; } // Commit if required if ( autoCommit || forceCommit ) { log . info ( "Running forced commit!" ) ; try { // HTTP commits for embedded if ( commit != null ) { solr . commit ( ) ; commit . commit ( ) ; // or just HTTP on it's own } else { solr . commit ( ) ; } } catch ( Exception e ) { log . warn ( "Solr forced commit failed. Document will" + " not be visible until Solr autocommit fires." + " Error message: {}" , e ) ; } } } } purgeBuffer ( ) ; }
Submit all documents currently in the buffer to Solr then purge