[ https://issues.apache.org/jira/browse/LUCENE-9524?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17210032#comment-17210032 ]
Zach Chen edited comment on LUCENE-9524 at 10/8/20, 6:50 AM: ------------------------------------------------------------- This seems to be a potential bug related to MemoryIndex. I ran two similar tests to compare (one using very much the code sample Michal provided), and saw the while the MemoryIndex one failed with the exact same exception, the other one passed: {code:java} // Failing test public void testExplainMemoryIndex() throws ParseException, IOException { String queryString = "(lorem AND NOT \"dolor lorem\") OR ipsum"; String text = "dolor lorem ipsum"; Analyzer analyzer = new MockAnalyzer(random()); Query query = new ComplexPhraseQueryParser("content", analyzer).parse(queryString); MemoryIndex memoryIndex = new MemoryIndex(true); memoryIndex.addField("content", text, analyzer); IndexSearcher searcher = memoryIndex.createSearcher(); TopDocs topDocs = searcher.search(query, 1); ScoreDoc match = topDocs.scoreDocs[0]; searcher.explain(query, match.doc); } {code} {code:java} // Passing test public void testExplainIndex() throws ParseException, IOException { String queryString = "(lorem AND NOT \"dolor lorem\") OR ipsum"; String text = "dolor lorem ipsum"; Analyzer analyzer = new MockAnalyzer(random()); Query query = new ComplexPhraseQueryParser("content", analyzer).parse(queryString); try(Directory rd = newDirectory()) { try(IndexWriter writer = new IndexWriter(rd, newIndexWriterConfig(analyzer))) { Document doc = new Document(); doc.add(newTextField("content", text, Field.Store.YES)); writer.addDocument(doc); } try(DirectoryReader reader = DirectoryReader.open(rd)) { IndexSearcher searcher = newSearcher(reader); TopDocs topDocs = searcher.search(query, 1); ScoreDoc match = topDocs.scoreDocs[0]; searcher.explain(query, match.doc); } } } {code} I'll dig a bit deeper to see why there's a difference. was (Author: zacharymorn): This seems to be a potential bug related to MemoryIndex. I ran two similar tests to compare (one using very much the code sample Michal provided), and saw the while the MemoryIndex one failed with the exact same exception, the other one passed: {code:java} // Failing test public void testExplainMemoryIndex() throws ParseException, IOException { String queryString = "(lorem AND NOT \"dolor lorem\") OR ipsum"; String text = "dolor lorem ipsum"; Analyzer analyzer = new MockAnalyzer(random()); Query query = new ComplexPhraseQueryParser("content", analyzer).parse(queryString); MemoryIndex memoryIndex = new MemoryIndex(true); memoryIndex.addField("content", text, analyzer); IndexSearcher searcher = memoryIndex.createSearcher(); TopDocs topDocs = searcher.search(query, 1); ScoreDoc match = topDocs.scoreDocs[0]; searcher.explain(query, match.doc); } {code} {code:java} // Passing test public void testExplainIndex() throws ParseException, IOException { String queryString = "(lorem AND NOT \"dolor lorem\") OR ipsum"; String text = "dolor lorem ipsum"; Analyzer analyzer = new MockAnalyzer(random()); Query query = new ComplexPhraseQueryParser("content", analyzer).parse(queryString); try(Directory rd = newDirectory()) { try(IndexWriter writer = new IndexWriter(rd, newIndexWriterConfig(analyzer))) { Document doc = new Document(); doc.add(newTextField("content", text, Field.Store.YES)); writer.addDocument(doc); } try(DirectoryReader reader = DirectoryReader.open(rd)) { IndexSearcher searcher = newSearcher(reader); TopDocs topDocs = searcher.search(query, 1); ScoreDoc match = topDocs.scoreDocs[0]; searcher.explain(query, match.doc); } } } {code} I'll dig a bit deeper to see why there's a difference. > NullPointerException in IndexSearcher.explain() when using > ComplexPhraseQueryParser > ----------------------------------------------------------------------------------- > > Key: LUCENE-9524 > URL: https://issues.apache.org/jira/browse/LUCENE-9524 > Project: Lucene - Core > Issue Type: Bug > Components: core/queryparser, core/search > Affects Versions: 8.6, 8.6.2 > Reporter: Michał Słomkowski > Priority: Major > > I get NPE when I use {{IndexSearcher.explain()}}. Checked with Lucene 8.6.0 > and 8.6.2. > The query: {{(lorem AND NOT "dolor lorem") OR ipsum}} > The text: {{dolor lorem ipsum}} > Stack trace: > {code} > java.lang.NullPointerException at > java.util.Objects.requireNonNull(Objects.java:203) > at org.apache.lucene.search.LeafSimScorer.<init>(LeafSimScorer.java:38) > at > org.apache.lucene.search.spans.SpanWeight.explain(SpanWeight.java:160) > at org.apache.lucene.search.BooleanWeight.explain(BooleanWeight.java:87) > at org.apache.lucene.search.BooleanWeight.explain(BooleanWeight.java:87) > at > org.apache.lucene.search.IndexSearcher.explain(IndexSearcher.java:716) > at > org.apache.lucene.search.IndexSearcher.explain(IndexSearcher.java:693) > {code} > Minimal example code: > {code:java} > val analyzer = new StandardAnalyzer(); > val query = new ComplexPhraseQueryParser("", analyzer).parse(queryString); > final MemoryIndex memoryIndex = new MemoryIndex(true); > memoryIndex.addField("", text, analyzer); > final IndexSearcher searcher = memoryIndex.createSearcher(); > final TopDocs topDocs = searcher.search(query, 1); > final ScoreDoc match = topDocs.scoreDocs[0]; > searcher.explain(query, match.doc); > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org