Hi, I am creating an index successfully and the field called "note" that I am searching against has the term "background". But when I run the query it returns some completely unrelated term for the first hit. Here is the code:
<code> List<EmployeeNote> employeeNotes = employeeDAO.getAllEmployeeNotes(clientId); //indexDir is the directory that hosts Lucene's index files File indexDir = new File("C:\\luceneIndex"); Analyzer luceneAnalyzer = new StandardAnalyzer(Version.LUCENE_CURRENT); IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,true,MaxFieldLength.UNLIMITED); Query query = null; Document doc = new Document(); IndexSearcher searcher = null; TopDocs hits = null; try { for(EmployeeNote employeeNote : employeeNotes){ doc.add(new Field("id", employeeNote.getId().toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.add(new Field("note", employeeNote.getNote(), Field.Store.YES, Field.Index.ANALYZED)); indexWriter.addDocument(doc); } indexWriter.optimize(); indexWriter.close(); IndexReader reader = IndexReader.open(FSDirectory.open(indexDir), true); // only searching, so read-only=true searcher = new IndexSearcher(reader); QueryParser qp = new QueryParser("note", luceneAnalyzer); query = qp.parse("note:(+background)"); hits = searcher.search(query, 50); Document docx = searcher.doc(hits.scoreDocs[0].doc); //test to see what first hit is String doctitle = docx.get("note"); System.out.println("Here is the note: " + doctitle); </code> -- View this message in context: http://old.nabble.com/Result-of-query-not-what-I-expect-tp26958815p26958815.html Sent from the Lucene - Java Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org