Reputation: 21
When I'm searching for a query in Lucene, I receive a list of documents as result. But how can I get the hits within those documents? I want to access the payload of those word, which where found by the query.
If your query contains only one term you can simply use TermPositions
to access the payload of this term. But if you have a more complex query with Phrase Search, Proximity Search, ... you can't just search for the single terms in TermPositions
.
I would like to receive a List<Token>
, TokenStream
or something similiar, which contains all the Tokens that were found by the query. Then I can iterate over the list and access the payload of each Token.
Upvotes: 1
Views: 888
Reputation: 21
I solved my problem by using SpanQueries. Nearly every Query can be expressed as SpanQuery. A SpanQuery gives access to the spans where the hit within a document is. Because the normal QueryParser doesn`t produce SpanQueries, I had to write my own parser which only creates SpanQueries. Another option would be the SurroundParser from Lucene-Contrib, which also creates SpanQueries.
Upvotes: 1
Reputation: 5703
I think you'll want to start by looking at the Lucene Highlighter, as it highlights the matching terms in the document.
Upvotes: 0