Running version 5.2.1 of Lucene.
Here is the code I am running:
Path indexPath = Paths.get("index");
Directory dir = NIOFSDirectory.open(indexPath);
IndexWriterConfig iwc = new IndexWriterConfig(new StandardAnalyzer());
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
IndexWriter indexWriter = new IndexWriter(dir, iwc);
IndexReader indexReader = DirectoryReader.open(indexWriter, false);
IndexSearcher indexSearcher = new IndexSearcher(directoryReader);
QueryParser queryParser = new QueryParser("defaultField", new StandardAnalyzer());
String query = "field:value";
indexSearcher.search(queryParser.parse(query), new SimpleCollector() {
@Override
public void collect(int doc) throws IOException {
System.out.println("result " + doc);
}
@Override
public boolean needsScores() {
return false;
}
});
I am expecting to print the doc ids to console, but I am not getting any results.
If use Luke to look at the index, I can see the results in the index that it should be returning via the "Documents" tab, but if I use the "Search" tab, again it returns nothing which leads me to think its something to do with my query?
What could be going wrong?