With Lucene, what would be the recommended approach for finding matches in search results?
More specifically, suppose there is a “fullText” field in index documents that stores the text content of some document. Also, suppose that for one of these documents, the content is “Fast brown fox jumping over a lazy dog.” Then a search is made for "fox dog." Obviously, the document will be a hit.
In this case, is it possible to use Lucene to provide something like the appropriate regions for the found document? So for this scenario, I would like to create something like:
[{match: "fox", startIndex: 10, length: 3}, {match: "dog", startIndex: 34, length: 3}]
I suspect that this may be implemented by what is provided in the package org.apache.lucene.search.highlight. I'm not sure about the general approach, though ...
source share