all, No sure if earlier mail went thru..so resending...
Im new lucene and Im trying to develope a textual search module. I have written the following code ( this is research code) - File dir = new File("c:/test"); IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(), true); Document doc = new Document(); File[] file = dir.listFiles(); for (File f: file) { if (f.isFile() && f.canRead()) { System.out.println(f.getName()); doc.add(new Field("filename",f.getName(),Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.add(new Field("contents", new FileReader(f))); writer.addDocument(doc); } } System.out.println("count=" + writer.docCount()); writer.optimize(); writer.close(); I'm trying to index the contents of test diretory which has only txt files. When I search the index for an particular word, I get the same filename everytime. Here is the code for searching - File dir = new File("D:\\test"); FSDirectory fsdir = FSDirectory.getDirectory(dir); IndexSearcher d = new IndexSearcher(fsdir); QueryParser p = new QueryParser("contents",new StandardAnalyzer()); Query q = p.parse("ERROR"); Hits hits = d.search(q); for (int i = 0; i < hits.length(); i++) { Document doc = hits.doc(i); System.out.println(doc.get("filename")); } d.close(); } Can somebody tell me what I'm doing wrong ? I suspect that there is something wrong in the way I index. -- -nachi