title: Need to run Lucene Analyzer offline from servlet
body: <p>This might be quite a meaty question but my problem is that I have a Spring servlet that is used for real-time searching.  I need to strip out the Lucene analyzer so that it runs offline and is called by the servlet everytime a query comes in to it, rather than having the analyzer within the servlet.  However, I don't quite know how to do this, and call the analyzer service from the servlet.  Can anyone point me in the right direction?</p>
  
  <p>At the moment, I have this:</p>
  
  <pre><code>RAMDirectory ramDirectory = new RAMDirectory();
  StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_31);
  
  IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_31, analyzer);
  IndexWriter indexWriter = new IndexWriter(ramDirectory, config);
  Document document = new Document();
  
  // TEST DATA
  document.add(new Field("firstName", "John", Field.Store.YES, Field.Index.ANALYZED));
  document.add(new Field("occupation", "Engineer", Field.Store.YES, Field.Index.ANALYZED));
  
  document.add(new Field("firstName", "Mary", Field.Store.YES, Field.Index.ANALYZED));
  document.add(new Field("occupation", "Field Engineer", Field.Store.YES, Field.Index.ANALYZED));
  
  document.add(new Field("firstName", "Jamie", Field.Store.YES, Field.Index.ANALYZED));
  document.add(new Field("occupation", "Primary teacher", Field.Store.YES, Field.Index.ANALYZED));
  // END TEST DATA
  
  indexWriter.addDocument(document);
  indexWriter.optimize();
  indexWriter.close();
  
  IndexSearcher indexSearcher = new IndexSearcher(ramDirectory);
  String[] fields = {"firstName", "occupation"};
  MultiFieldQueryParser parser = new MultiFieldQueryParser(null, fields, analyzer);
  Query query = parser.parse(searchQuery);
  
  // Parsing of results here
  </code></pre>
  
  <p>Thanks.</p>