When I index some documents, i can add several fields such as contents
. But now, what i want to display is part of the contents that contain the query word, not the whole contents, just like the normal search engine. How can i archieve that?
Asked
Active
Viewed 95 times
0

cameron
- 2,976
- 3
- 23
- 35
-
See this question: http://stackoverflow.com/questions/2851473/lucene-get-matched-terms-in-query – mindas Dec 11 '12 at 09:36
-
Thanks for your advice. I tried, but it returns "`FieldWeights , tf , idf , fieldNorm`" something like that , that is not exactly what i need. – cameron Dec 11 '12 at 10:51
1 Answers
0
org.apache.lucene.search.highlight.Highlighter can be used to find and markup the best matching portions of text within fields in your query results (much like how google displays bold text for matching fragments).
You'll need to include the lucene-highligher-x.x.x jar from the contrib area to use it.
This blog post might help you get started with using it: http://hrycan.com/2009/10/25/lucene-highlighter-howto/

femtoRgon
- 32,893
- 7
- 60
- 87
-
Good suggestion, that is a wonderful tool, but if what i index is a very big size file, then i will not store the file's content into memory as a string, so in query process , i cann't get a string and highlight it, do you have any suggestion? – cameron Dec 12 '12 at 02:32
-
Your documents are too large to be retrieved from the index? So should I assume that you are not storing them in the index directly (perhaps storing a reference to them, from which you can use to open a stream)? – femtoRgon Dec 12 '12 at 17:34