lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nachi <nachit...@gmail.com>
Subject indexing going wrong
Date Sat, 11 Aug 2007 06:55:03 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message