Java Mailing List Archive

http://www.java2.5341.com/

Home » java-user.lucene »

Query Search returns always the same id

Sebastian23

2008-10-28

Replies: Find Java Web Hosting

Author LoginPost Reply

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
--
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@(protected)
For additional commands, e-mail: java-user-help@(protected)

©2008 java2.5341.com - Jax Systems, LLC, U.S.A.