Perhaps someone can explain something that seems to be a little weird to me. I seem to be unable to search on fields of type Keyword. The following snippet returns no hits….
IndexWriter index = new IndexWriter(indexPath, new StandardAnalyzer(), true);
Document doc = null;
doc = new Document(); doc.add(Field.Text("artist", "Butthole Surfers")); doc.add(Field.Keyword("genre", "Punk")); doc.add(Field.Text("album", "Rembrandt Pussyhorse")); index.addDocument(doc);
doc = new Document(); doc.add(Field.Text("artist", "Ornette Coleman")); doc.add(Field.Keyword("genre", "Jazz")); doc.add(Field.Text("album", "Tomorrow is the Question")); index.addDocument(doc);
index.optimize(); index.close();
Searcher searcher = new IndexSearcher(indexPath);
String _expression_ = "genre:punk"; Query query = QueryParser.parse(_expression_, "artist", new StandardAnalyzer());
Hits hits = searcher.search(query); for (int i = 0; i < hits.length(); i++) { System.out.println(hits.doc(i)); }
searcher.close();
However, if I change the “genre” field to be defined as Field.Text or Field.UnStored, I get the result I expect. Can anyone offer any insight?
Mike
|
smime.p7s
Description: S/MIME cryptographic signature