Hi, I have an index with a single document with a field "field" and textual content "johnny peters" and I am using org.apache.lucene.queryparser.complexPhrase.ComplexPhraseQueryParser to parse the query: field: (john* peter) When searching with this query, I am getting the document as expected. However with this query: field: ("john*" "peter") I am getting the following exception: Exception in thread "main" java.lang.IllegalArgumentException: Unknown query type "org.apache.lucene.search.PrefixQuery" found in phrase query string "john*" at org.apache.lucene.queryparser.complexPhrase.ComplexPhraseQueryParser$ComplexPhraseQuery.rewrite(ComplexPhraseQueryParser.java:268) at org.apache.lucene.search.BooleanQuery.rewrite(BooleanQuery.java:278) at org.apache.lucene.search.IndexSearcher.rewrite(IndexSearcher.java:836) at org.apache.lucene.search.IndexSearcher.createNormalizedWeight(IndexSearcher.java:886) at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:535) at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:744) at org.apache.lucene.search.IndexSearcher.searchAfter(IndexSearcher.java:460) at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:489) at ComplexQueryTest.main(ComplexQueryTest.java:36)
Note: the exception is not thrown during the parse() method call, but during the search() method call. I don't see why the ComplexQueryParser can't handle this. Am I misusing it? Or should I file a bug on Jira? I'm on Lucene 5.5.1, but the situation looks the same on 6.3.0. Any help is appreciated! Otmar The code to reproduce my issue: import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field.Store; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.queryparser.complexPhrase.ComplexPhraseQueryParser; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.RAMDirectory; public class ComplexQueryTest { public static void main(String[] args) throws Throwable { RAMDirectory directory = new RAMDirectory(); IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(new StandardAnalyzer())); Document doc1 = new Document(); doc1.add(new TextField("field", "johnny peters", Store.NO)); writer.addDocument(doc1); writer.commit(); writer.close(); IndexReader reader = DirectoryReader.open(directory); IndexSearcher searcher = new IndexSearcher(reader); ComplexPhraseQueryParser parser = new ComplexPhraseQueryParser("field", new StandardAnalyzer()); TopDocs topDocs; Query queryOk = parser.parse("field: (john* peters)"); topDocs = searcher.search(queryOk, 2); System.out.println("found " + topDocs.totalHits + " docs"); Query queryFail = parser.parse("field: (\"john*\" \"peters\")"); topDocs = searcher.search(queryFail, 2); // -----> throws the above mentioned exception System.out.println("found " + topDocs.totalHits + " docs"); } }