lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liat oren <oren.l...@gmail.com>
Subject IndexSearcher
Date Thu, 05 Mar 2009 13:40:13 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message