Hi,

I am new to Lucene.
I have directory which contains multiple file.I want to index those file.
I have written follwoing code.

String testDataDir = "/root/Desktop/testdata";
File testData = new File(testDataDir);
String idx = "/tmp/indexFileRead";
IndexWriter writer = new IndexWriter(idx, new StandardAnalyzer(),true);
Document doc = null;
if (testData.isDirectory()) {
String testDataFiles[] = testData.list();
for (String file : testDataFiles) {
System.out.println("Files ==>> " + file);
fileReader = new BufferedReader(new FileReader(new File(testDataDir + "/" + file)));
doc = new Document();
doc.add((Fieldable) new Field("content", reader));
writer.addDocument(doc);
fileReader.close();
}
}
writer.optimize();
writer.close();

Then for searching I have written following method.
public static void search(Searcher searcher, String content) throws ParseException, IOException {
QueryParser parser = new QueryParser("content", new StandardAnalyzer());
Query query = parser.parse(content);
Hits hits = searcher.search(query);
System.out.println("Search results for \"" + content + "\":");
int hitLnth = 0;
if (hits != null && (hitLnth = hits.length()) > 0) {
System.out.println("hitLnth ==>> " + hitLnth);
for (int i = 0; i < hitLnth; i++) {
Document hitDoc = hits.doc(i);
System.out.println("hits ==>> " + hitDoc.get("content") + " == " + hitDoc.toString() + " ids==>> " + hits.id(i));
}
} else {
System.out.println("Content Not Found....");
}
}

And called the above method as
/* Seaching */
Searcher searcher = new IndexSearcher(idx);
search(searcher, "freedom");
search(searcher, "free");

My Program Output :-
Search results for "freedom":
hitLnth ==>> 1
hits ==>> null == Document<> ids==>> 1
Search results for "free":
hitLnth ==>> 1
hits ==>> null == Document<> ids==>> 1

The file are indexes properly but the as the data is not stored while indexing the output shows null value.
How do I get the data in the above scenaria.
What changes are requried in above code to get the data .
I am using Lucene 2.2.0 .

Thanks in advance.