I have two questions regarding hit highlighter provided with apache lucene:
see this function could you explain the use of token stream parameter.
I have several large lucene document containing many fields and each field has some strings in it. Now I have found the most relevant document for a particular query. Now this document was found because several words in the query might have matched with the words in the document. I want to find out what words in the query caused this. So for this I plan to use Lucene Hit Highlighter. Example: if the query is "skin doctor delhi" and the document titled "dermatologist" contains the words "skin" and "doctor" then after hit highlighting i should be able to separate out "skin" and "doctor" from the query. I have been trying to write the code for this for several weeks now. Not able to get what i want. Could you help me please?
Thanks in advance.
Update:
Current Approach: I create a query containing all the words in the document.
Field[] field = doc.getFields("description");
String desc = "";
for (int j = 0; j < field.length; ++j) {
desc += field[j].stringValue() + " ";
}
Query q = qp.parse(desc);
QueryScorer scorer = new QueryScorer(q, reader, "description");
Highlighter highlighter = new Highlighter(scorer);
String fragment = highlighter.getBestFragment(analyzer, "description", text);
It works for small documents but does not work for large documents. The following stacktrace is obtained.
org.apache.lucene.search.BooleanQuery$TooManyClauses: maxClauseCount is set to 1024
at org.apache.lucene.search.BooleanQuery.add(BooleanQuery.java:152)
at org.apache.lucene.queryParser.QueryParser.getBooleanQuery(QueryParser.java:891)
at org.apache.lucene.queryParser.QueryParser.getBooleanQuery(QueryParser.java:866)
at org.apache.lucene.queryParser.QueryParser.Query(QueryParser.java:1213)
at org.apache.lucene.queryParser.QueryParser.TopLevelQuery(QueryParser.java:1167)
at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:182)
It is obvious that the approach is unreasonable for large documents. What should be done to correct this?
BTW I am using FuzzyQuery matching.