lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sebastian Müller <s...@icu.uzh.ch>
Subject Lucene Query returns always the first ID
Date Tue, 28 Oct 2008 20:50:00 GMT
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: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message