Hi all. In this test, I wrap a query in a FilteredQuery. Then I do a query which returns one doc and pass that doc ID to get an explanation.
The resulting Explanation.isMatch() returns false, which seems odd, considering it was obviously a match. Is this a bug? Code follows. TX public class TestFilteredSearcherWtf { private Directory directory; private IndexReader reader; private IndexSearcher searcher; private Query query = new TermQuery(new Term("value", "1")); private Filter filter = not( new QueryWrapperFilter(new TermsFilter(new Term("hidden", "1")))); @Test public void testSearch() throws Exception { TopDocs topDocs = searcher.search(query, filter, 10); int doc = topDocs.scoreDocs[0].doc; // <- got the doc here Explanation explanation = searcher.explain(new FilteredQuery(query, filter), doc); assertThat(explanation.isMatch(), is(true)); // <- so it should return true, right? } public static Filter not(Filter filter) { BooleanQuery booleanQuery = new BooleanQuery(); booleanQuery.add(new MatchAllDocsQuery(), BooleanClause.Occur.SHOULD); booleanQuery.add(filter, BooleanClause.Occur.MUST_NOT); return new QueryWrapperFilter(booleanQuery); } @Before public void setUp() throws Exception { directory = new RAMDirectory(); try (IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(new WhitespaceAnalyzer()))) { Document doc1 = new Document(); doc1.add(new StringField("hidden", "1", Field.Store.YES)); doc1.add(new StringField("value", "1", Field.Store.YES)); writer.addDocument(doc1); Document doc2 = new Document(); doc2.add(new StringField("value", "1", Field.Store.YES)); writer.addDocument(doc2); Document doc3 = new Document(); doc3.add(new StringField("hidden", "1", Field.Store.YES)); doc3.add(new StringField("value", "2", Field.Store.YES)); writer.addDocument(doc3); Document doc4 = new Document(); doc4.add(new StringField("value", "2", Field.Store.YES)); writer.addDocument(doc4); } reader = DirectoryReader.open(directory); searcher = new IndexSearcher(reader); } @After public void tearDown() throws Exception { if (reader != null) { reader.close(); } if (directory != null) { directory.close(); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org