You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Jinsong Hu (JIRA)" <ji...@apache.org> on 2013/01/29 11:25:14 UTC

[jira] [Updated] (LUCENE-4730) SmartChineseAnalyzer got wrong matched offset

     [ https://issues.apache.org/jira/browse/LUCENE-4730?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jinsong Hu updated LUCENE-4730:
-------------------------------

    Description: 
We found that SmartChineseAnalyzer got wrong matched offset with the following test code:

    public void testHighlight() throws Exception {
        String text = "My China  ";        
        String queryText = "China";
        StringBuilder builder = new StringBuilder("<html>");
        Analyzer analyzer = new SmartChineseAnalyzer(Version.LUCENE_40);
        //Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
        QueryParser parser = new QueryParser(Version.LUCENE_40, "text", analyzer);
        Query query = parser.parse(queryText);
        SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span style=\"background: yellow\">", "</span>");
        TokenStream tokens = analyzer.tokenStream("text", new StringReader(text));
        QueryScorer scorer = new QueryScorer(query, "text");
        Highlighter highlighter = new Highlighter(formatter, scorer);
        highlighter.setTextFragmenter(new SimpleSpanFragmenter(scorer));
        String result = highlighter.getBestFragments(tokens, text, 10, "...");
        if (result.length() < text.length()) {
            result = text;
        }
        builder.append("<body>");
        builder.append(result);
        builder.append("</body>");
        builder.append("</html>");
        System.out.println(builder.toString());
    }

This method will generate a hilighted text, however, the highlight position is obviously wrong, and if we remove one space from the text, that is, changed text from "My China  " to "My China ", it will generate a text with correct highlight. If we change the analyzer from SmartChineseAnalyzer to StandardAnalyzer, the highlight issue will disappear.




  was:
We found that SmartChineseAnalyzer got wrong matched offset with the following test code:

    public void testHighlight() throws Exception {
        String text = "My China  ";        
        String queryText = "China";
        StringBuilder builder = new StringBuilder("<html>");
        Analyzer analyzer = new SmartChineseAnalyzer(Version.LUCENE_40);
        //Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
        QueryParser parser = new QueryParser(Version.LUCENE_40, "text", analyzer);
        Query query = parser.parse(queryText);
        SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span style=\"background: yellow\">", "</span>");
        TokenStream tokens = analyzer.tokenStream("text", new StringReader(text));
        QueryScorer scorer = new QueryScorer(query, "text");
        Highlighter highlighter = new Highlighter(formatter, scorer);
        highlighter.setTextFragmenter(new SimpleSpanFragmenter(scorer));
        String result = highlighter.getBestFragments(tokens, text, 10, "...");
        if (result.length() < text.length()) {
            result = text;
        }
        builder.append("<body>");
        builder.append(result);
        builder.append("</body>");
        builder.append("</html>");
        System.out.println(builder.toString());
    }

This method will generated a hilighted text, however, the highlight position is obviously wrong, and if we remove one space from the text, that is, changed text from "My China  " to "My China ", it will generate a text with correct highlight. If we change the analyzer from SmartChineseAnalyzer to StandardAnalyzer, the highlight issue will disappear.




    
> SmartChineseAnalyzer got wrong matched offset
> ---------------------------------------------
>
>                 Key: LUCENE-4730
>                 URL: https://issues.apache.org/jira/browse/LUCENE-4730
>             Project: Lucene - Core
>          Issue Type: Bug
>          Components: modules/analysis
>    Affects Versions: 4.0, 4.1
>         Environment: JDK1.7 Linux/Windows
>            Reporter: Jinsong Hu
>            Priority: Critical
>
> We found that SmartChineseAnalyzer got wrong matched offset with the following test code:
>     public void testHighlight() throws Exception {
>         String text = "My China  ";        
>         String queryText = "China";
>         StringBuilder builder = new StringBuilder("<html>");
>         Analyzer analyzer = new SmartChineseAnalyzer(Version.LUCENE_40);
>         //Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
>         QueryParser parser = new QueryParser(Version.LUCENE_40, "text", analyzer);
>         Query query = parser.parse(queryText);
>         SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span style=\"background: yellow\">", "</span>");
>         TokenStream tokens = analyzer.tokenStream("text", new StringReader(text));
>         QueryScorer scorer = new QueryScorer(query, "text");
>         Highlighter highlighter = new Highlighter(formatter, scorer);
>         highlighter.setTextFragmenter(new SimpleSpanFragmenter(scorer));
>         String result = highlighter.getBestFragments(tokens, text, 10, "...");
>         if (result.length() < text.length()) {
>             result = text;
>         }
>         builder.append("<body>");
>         builder.append(result);
>         builder.append("</body>");
>         builder.append("</html>");
>         System.out.println(builder.toString());
>     }
> This method will generate a hilighted text, however, the highlight position is obviously wrong, and if we remove one space from the text, that is, changed text from "My China  " to "My China ", it will generate a text with correct highlight. If we change the analyzer from SmartChineseAnalyzer to StandardAnalyzer, the highlight issue will disappear.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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