Last active
          December 11, 2015 16:28 
        
      - 
      
- 
        Save mumrah/4627882 to your computer and use it in GitHub Desktop. 
    Example of multi-threading Solr updates
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | public class SolrUpdater implements Runnable { | |
| private final SolrInputDocument doc = new SolrInputDocument(); | |
| private final UpdateRequest req = new UpdateRequest(); | |
| private final SolrServer solr; | |
| private final BlockingQueue<String> strings; | |
| private final AtomicLong id; | |
| public SolrUpdater(SolrServer solr, BlockingQueue<String> strings, | |
| AtomicLong id) { | |
| this.solr = solr; | |
| this.strings = strings; | |
| this.id = id; | |
| } | |
| @Override | |
| public void run() { | |
| while(true) { | |
| String text = strings.take(); | |
| doc.setField("id", "doc-" + id.getAndIncrement()); | |
| doc.setField("text", text); | |
| req.add(doc); | |
| req.process(solr); | |
| req.clear(); | |
| doc.clear(); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment