your problem is about new one Document for all sourcefiles i think you have 2 solution 1.new document in first step of loop(like below code) [code] for (int i = 0; i < sourcefiles.size(); i++) { for (int j = 0; j < sourcefiles.elementAt(i).getNumberOfRevisions(); j++) { Document doc = new Document(); [/code] 2.after iwriter.addDocument, remove all fields in doc
On Wed, Oct 29, 2008 at 12:20 AM, Sebastian Müller <[EMAIL PROTECTED]> wrote: > hi folks, > > i have great trouble while using lucene to implement search functionality > to my application: > > this way i index: > [code] > public void indexData() throws CorruptIndexException, > LockObtainFailedException, IOException { > Analyzer analyzer = new StandardAnalyzer(); > IndexWriter iwriter = new IndexWriter(indexFolder, analyzer, > true); > iwriter.setMaxFieldLength(25000); > Document doc = new Document(); > for (int i = 0; i < sourcefiles.size(); i++) { > for (int j = 0; j < > sourcefiles.elementAt(i).getNumberOfRevisions(); j++) { > doc.add(new Field("id", > sourcefiles.elementAt(i).getID(j), Field.Store.YES, > Field.Index.UN_TOKENIZED)); > doc.add(new Field("message", > sourcefiles.elementAt(i).getCommitMessage(j), Field.Store.NO, > Field.Index.TOKENIZED)); > iwriter.addDocument(doc); > System.out.println("Indexed: Source: " + > (i+1) + " Revision: " + (j+1)); > > System.out.println(sourcefiles.elementAt(i).getCommitMessage(j)); > > System.out.println(sourcefiles.elementAt(i).getID(j)); > } > } > iwriter.optimize(); > iwriter.close(); > } > [/code] > > and this way i make the query > > [code] > public void luceneSearch(String queryString) throws CorruptIndexException, > IOException, ParseException { > System.out.println("Searching started"); > IndexSearcher isearcher = new IndexSearcher(indexFolder); > Analyzer analyzer = new StandardAnalyzer(); > QueryParser parser = new QueryParser("message", analyzer); > org.apache.lucene.search.Query query = > parser.parse(queryString); > Hits hits = isearcher.search(query); > > if(hits.length() > 0) { > System.out.println("found: " + hits.length() + " > documents."); > for (int i = 0; i < hits.length(); i++) { > System.out.println((i + 1) + ". " + > hits.doc(i).get("id") + hits.doc(i).getField("message")); > } > } else { > System.out.println("No matching documents found."); > } > } > [/code] > > my problem is, that the query always returns a lot of too much results. > and the other problem is, the id is always for every result in the list the > same id, namly the first i added to the writer. and the message is always > null. > > while adding i check with sysout that all the ids are different and the > messages arent null > > whats going wrong?? thx for your hints > > -- > Sebastian > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >