Hi Frederik, Using explain should be fine for that use-case since you will only apply it to the top hits. Otherwise you could use the low-level search APIs in order to do this. It would look something like that if you want to find which query among `queries` matches document `docID` (I did not check it compiles but it should give the idea):
List<Query> queries; int docID; IndexSearcher searcher; int leafIndex = ReaderUtil.subIndex(docID, searcher.getIndexReader().leaves()); LeafReaderContext leaf = searcher.getIndexReader().leaves().get(leafIndex); int leafDocID = docID - leaf.docBase; for (Query query : queries) { Weight weight = searcher.createNormalizedWeight(query); Scorer scorer = weight.scorer(leaf); boolean matches = scorer.advance(leafDocID) == leafDocID; } Le lun. 19 juin 2017 à 11:24, Frederik Van Hoyweghen < frederik.vanhoyweg...@chapoo.com> a écrit : > Hey everyone, > > To start, we are using Lucene 4.3. > > To search, we prepare several queries and combine these into a > BooleanQuery. > What we are looking for is a way to determine on which specific fields a > certain document matched. > For example, I create 2 queries: one to search in the "Name" field, and > another to search in the "Description" field. > > Combining these into a BooleanQuery and running it will return the matching > documents, > but we'd like to know for each document returned whether there was a match > in the Name field or in the Description field. > > It seems to me that something like the highlighter would need to know this > too but highlighting isn't a goal currently. I've also looked at > indexsearcher.explain() but the doc says that this is as expensive as > running the query against the entire index, so I'd obviously like to avoid > running the same queries mutliple times :). > > Kind regards, > Frederik >