Hi,
I would like to do a search that will return documents that contain a given
word.
For example, I created the following index:
IndexWriter writer = new IndexWriter("C:/TryIndex", new StandardAnalyzer());
Document doc = new Document();
doc.add(new Field(WordIndex.FIELD_WORLDS, "111 222 333", Field.Store.YES,
Field.Index.UN_TOKENIZED));
writer.addDocument(doc);
doc = new Document();
doc.add(new Field(WordIndex.FIELD_WORLDS, "111", Field.Store.YES,
Field.Index.UN_TOKENIZED));
writer.addDocument(doc);
doc = new Document();
doc.add(new Field(WordIndex.FIELD_WORLDS, "222 333", Field.Store.YES,
Field.Index.UN_TOKENIZED));
writer.addDocument(doc);
writer.optimize();
writer.close();
now I want to get all the documents that contain the word "222".
I tried to run the following code but it doesn;t return any doc
IndexSearcher searcher = new IndexSearcher(indexPath);
// // TermQuery mapQuery = new TermQuery(new Term(FIELD_WORLDS,
worldNum)); - this one also didn't word
Analyzer analyzer = new StandardAnalyzer();
QueryParser parser = new QueryParser(FIELD_WORLDS, analyzer);
Query query = parser.parse(worldNum);
Hits mapHits = searcher.search(query);
Thanks a lot,
Liat