Hey Jeff!

Storey, Jeff schrieb:
Could you explain what you did for your solution?  This is a problem I'm currently facing as well. But, for example, if 
the user searches for "head~" would you also be able to highlight "read" and "dead" if 
they are returned or just "head" without the ~.
It is necessary to give a "native" query to the QueryScorer (only Boolean operators). Therefore I just took the an IndexWriter object and used its public method rewrite(query).

Here the code:

QueryParser queryParser = new QueryParser(
           ConstantsRetrieval.FIELD_DOC_CONTENT, new EMRAnalyzer());
String formattedText = null; try { // for the usage of highlighting with wildcards Query query = indexSearcher.rewrite(queryParser.parse(searchParameter.getUserQuery()));
           QueryScorer queryScorer = new QueryScorer(query);
//logger.debug("User Query: " + query.toString()); SimpleHTMLFormatter formatter = new SimpleHTMLFormatter(
                   "<span class=\"highlight\">", "</span>");
Highlighter highlighter = new Highlighter(formatter, queryScorer);
           Fragmenter fragmenter = new SimpleFragmenter(100);
           highlighter.setTextFragmenter(fragmenter);
TokenStream tokenStream = new EMRAnalyzer(). tokenStream(ConstantsRetrieval.FIELD_DOC_CONTENT, new StringReader(text)); formattedText = highlighter.getBestFragments(tokenStream, text, 5, "..."); //logger.debug("Formatted Text: \n" + formattedText); FileWriter writer = new FileWriter(
                   "D:/development/iremr/text/highlightedDoc.html");
writer.write("<html>");
           writer.write("<style>\n" +
                   ".highlight {\n" +
                   " background: yellow;\n" +
                   "}\n" +
                   "</style>");
           writer.write("<body>");
           writer.write(formattedText);
           writer.write("</body></html>");
           writer.close();
} catch (ParseException e) {
           logger.error("Not able to parse query\n" + e.getMessage());
           return null;
       } catch (IOException e) {
           logger.error("IO-Exception in highlighting" + e.getMessage());
           return null;
       }

Stephan


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to