lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neetika <>
Subject getting problem while indexing pdf files with pdfbox
Date Tue, 17 Jul 2007 11:17:12 GMT DRra0026.pdf 

hi all,

 i am able to convert a pdf in to a text file using pdfbox. 
 and this is the code that I used, but I am not able to index it
// code for parsing and making index

		public Document getDocument(InputStream is)
		COSDocument cosDoc = null;
		try {
			PDFParser parser = new PDFParser(is);
		cosDoc = parser.getDocument();
		catch (IOException e) {
		String docText = null;
		try {
		PDFTextStripper stripper = new PDFTextStripper();
		docText = stripper.getText(new PDDocument(cosDoc));
		catch (IOException e) {
		Document doc = new Document();
		if (docText != null) {
		doc.add(new Field("body", docText, Field.Store.YES, 
		return doc;
		public static void main(String[] args) throws Exception {
			TestPDFParser handler = new TestPDFParser();
		Document doc = handler.getDocument(new FileInputStream(new

		//Following code is for making index
		IndexWriter f_writer = new IndexWriter("D:\\lucenePdf", new
StandardAnalyzer(), true);

 //code for searching a particular string..

 public static void main(String[] args) throws Exception {
        String indexDir = "D:\\lucenePdf";
        String q = "RA0083";

        Directory fsDir = FSDirectory.getDirectory(indexDir);
        IndexSearcher is = new IndexSearcher(fsDir);

        Query query = new QueryParser("body", new

        Hits hits =;
        System.out.println("Found " + hits.length() + " documents that
matched query '" + q + "':");
        for (int i = 0; i < hits.length(); i++) {
            Document doc = hits.doc(i);

When I run the above code...I get folowing output as a result of running
indexer class

: RA0083 
000099062000062000000021000000100220468148001102006PAYOUT : RA0083 
000099062000063000000021000000100330468153601102006PAYOUT : RA0083 
000099062000064700000021000000100440468155401102006PAYOUT : RA0083 
000099062000065700000021000000100550468156201102006PAYOUT : RA0083 

and following  files are generated in the specified path..


but when I run the search class it gives the result as:

Found 0 documents that matched query 'RA0083':

I am also attaching the corresponding pdf file for reference.
It seems as the index is not getting created..

Please help me with some of your inputs,it will be very helpfull for me.
View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message