title: Sample code for searching text in PDF using LUCENE 4.6 and PDF Box
body: <p>Iam using LUCENE 4.6 for searching phrase in PDF. I have written the following code. But it is throwing error in "Analyser" and "QueryPhrase" lines. Please help me in doing this.</p>
  
  <pre><code>            Analyzer analyzer = new Analyzer(Version.LUCENE_44);
  
              // Store the index in memory:               
              Directory directory = new RAMDirectory();
              // To store an index on disk, use this instead:
              //Directory directory = FSDirectory.open("/tmp/testindex");
              IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_44, analyzer);
              IndexWriter iwriter = new IndexWriter(directory, config);
              Document doc = new Document();
              String text = "This is the text to be indexed.";
              doc.add(new Field("fieldname", text, TextField.TYPE_STORED));
              iwriter.addDocument(doc);
              iwriter.close();
  
              // Now search the index
              DirectoryReader ireader = DirectoryReader.open(directory);
              IndexSearcher isearcher = new IndexSearcher(ireader);
              // Parse a simple query that searches for "text":
              QueryParser parser = new QueryParser(Version.LUCENE_44, "fieldname", analyzer);
              Query query = parser.parse("text");
              ScoreDoc[] hits = isearcher.search(query, null, 1000).scoreDocs;
              // Iterate through the results:
              if(hits.length&gt;0){
                  System.out.println("Searched text existed in the PDF.");
              }
              ireader.close();
              directory.close();
           }
           catch(Exception e){
               System.out.println("Exception: "+e.getMessage());
           }
   }
  </code></pre>