lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephan Spat <stephan.s...@joanneum.at>
Subject Q: Highlighter + Search symbols "*, ?, ~"
Date Mon, 20 Nov 2006 08:21:22 GMT
Hello!

I would like to highlight the searching words from the user query in my 
result presentation. Therfore I use the highlighter package. I used to 
example published in "Lucene in Action" to do so! When I use bollean 
operators there is no problem, but with operators like "?", "*", ... the 
words cannot be found anymore.

Is it possible to highlight text (word) fregments (without extension of 
th package) when I use ?, *, ... operators? And when it is possible, how?

Thank's a lot!

Stephan Spat

PS: The used code:

public String cutAndHighlightText(String text, SearchParameterVO 
searchParameter) {
       
        QueryParser queryParser = new QueryParser(
            ConstantsRetrieval.FIELD_DOC_CONTENT, new SimpleAnalyzer());
       
        String formattedText = null;
       
        try {
           
            QueryScorer queryScorer = new QueryScorer(
                    queryParser.parse(searchParameter.getUserQuery()));
           
            
//logger.debug(queryParser.parse(searchParameter.getUserQuery()).toString());
           
            SimpleHTMLFormatter formatter = new SimpleHTMLFormatter(
                    "<span class=\"highlight\">", "</span>");
           
            Highlighter highlighter = new Highlighter(formatter, 
queryScorer);
            Fragmenter fragmenter = new SimpleFragmenter(200);
            highlighter.setTextFragmenter(fragmenter);
           
            TokenStream tokenStream = new StandardAnalyzer().
                tokenStream(ConstantsRetrieval.FIELD_DOC_CONTENT, new 
StringReader(text));
           
            formattedText = highlighter.getBestFragments(tokenStream, 
text, 5, "...");
           
            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;
        }
       
        return formattedText;
    }


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message