MarcusSorealheis commented on code in PR #12208:
URL: https://github.com/apache/lucene/pull/12208#discussion_r1159444007


##########
lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestTermAutomatonQuery.java:
##########
@@ -842,6 +843,92 @@ public void testRewriteSimplePhrase() throws Exception {
     IOUtils.close(w, r, dir);
   }
 
+  /* Implement a custom term automaton query to ensure that rewritten queries
+   *  do not get rewritten to primitive queries. The custom extension will 
allow
+   *  the following explain tests to evaluate Explain.
+   * */
+
+  private static class CustomTermAutomatonQuery extends TermAutomatonQuery {
+    public CustomTermAutomatonQuery(String field) {
+      super(field);
+    }
+
+    @Override
+    public Query rewrite(IndexSearcher searcher) throws IOException {
+      return this;
+    }
+  }
+
+  public void testExplainNoMatchingDocument() throws Exception {
+    CustomTermAutomatonQuery q = new CustomTermAutomatonQuery("field");
+    int initState = q.createState();
+    int s1 = q.createState();
+    q.addTransition(initState, s1, "xml");
+    q.setAccept(s1, 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 TermAutomatonQuery);
+
+    TopDocs topDocs = searcher.search(rewrite, 10);
+    assertEquals(0, topDocs.totalHits.value);

Review Comment:
   I must've overlooked this:
   
   >if there's no document matched, then make sure the explain returns NO_MATCH 
for any documents
   
   Again, my bad on back and forth. Thinking about getting back into this PR 3 
weeks after I opened it makes it amazing to me that some people can come back 
to files they haven't touched in 15 years and know what's going on. I basically 
had to do most stuff over again, even the few things that weren't broken or 
wrong. 



-- 
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

Reply via email to