Text search in all file inside a directory with apache lucene 4.7

Text search in all file inside a directory with apache lucene 4.7

Below program will search inside all files in a directory – In this example program I have searched with “Gopal”. It will search on any type of file.

final File docDir = new File("D:/gcdback/official docs");// Change this path which directory you want to search.

String indexPath = "D:/gcdback/"; // this is the path where lucene will create index.

What ever phrase you want to search replace it in “Gopal” –

// 3. query
String querystr = args.length > 0 ? args[0] : “Gopal”;


Indexing to directory ‘D:/gcdback/’…
adding D:\gcdback\official docs\documents\edu docs\Picture 030.jpg
adding D:\gcdback\official docs\documents\edu docs\Picture 031.jpg
adding D:\gcdback\official docs\documents\edu docs\Picture 032.jpg
adding D:\gcdback\official docs\documents\edu docs\Picture 033.jpg
adding D:\gcdback\official docs\documents\edu docs\Picture 034.jpg
adding D:\gcdback\official docs\documents\edu docs\Thumbs.db
adding D:\gcdback\official docs\documents\edu_docs_ram.7z
adding D:\gcdback\official docs\Resume.doc
adding D:\gcdback\official docs\pic.jpg
adding D:\gcdback\official docs\PaySlipMar2011.rtf
adding D:\gcdback\official docs\Relieving_xx.pdf
Found 2 hits.
1. stored,indexed,tokenized,omitNorms,indexOptions=DOCS_ONLY<path:d:\gcdback\official docs\resume.doc=””>
2. stored,indexed,tokenized,omitNorms,indexOptions=DOCS_ONLY<path:d:\gcdback\official docs\payslipmar2011.rtf=””>

Gopal Das
Follow me

Gopal Das

Founder at GopalDas.Org
He is a technology evangelist, Salesforce trainer, blogger, and working as a Salesforce Technical Lead. After working in Java based project implementation, he jumped to the Salesforce system on a whim and never looked back. He fell in love with Salesforce’s flexibility, scalability, and power. He expanded his knowledge of the platform and became a Certified App Builder, Administrator, Platform Developer I, SalesCloud Consultant while leading the Salesforce implementation and technology needs. He has worked in a wide variety of applications/services like desktop, web and mobile applications.
Gopal Das
Follow me

Leave a Reply

Your email address will not be published. Required fields are marked *