MarcusSorealheis commented on code in PR #12208: URL: https://github.com/apache/lucene/pull/12208#discussion_r1158228357
########## lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestTermAutomatonQuery.java: ########## @@ -842,6 +844,95 @@ public void testRewriteSimplePhrase() throws Exception { IOUtils.close(w, r, dir); } + public void testExplainNonMatchingDocument() throws Exception { + TermAutomatonQuery q = new TermAutomatonQuery("field"); + int initState = q.createState(); + int s1 = q.createState(); + int s2 = q.createState(); + q.addTransition(initState, s1, "xml"); + q.addTransition(s1, s2, "json"); + q.setAccept(s2, true); + q.finish(); + + Directory dir = newDirectory(); + RandomIndexWriter w = new RandomIndexWriter(random(), dir); + Document doc = new Document(); + doc.add(newTextField("field", "protobuf", Field.Store.NO)); + w.addDocument(doc); + + IndexReader r = w.getReader(); + IndexSearcher searcher = newSearcher(r); + Query rewrite = q.rewrite(searcher); + assertTrue(rewrite instanceof PhraseQuery); Review Comment: We should. I made that change in this test, only. However, I want to point out that the TermAutomatonQuery's explain will rewrite to a variety of other queries depending on the what the client supplies. I think `PhraseQuery` is merely one of the primitive options when explain is called. The explain is not an exact representation of the true query today. That's something that I think we should look to add because users still benefit from where the work is as of now. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org