FAQ
Hello

i am having the following code to highlight a text

public String highlight(String text, String query ) throws IOException {
TermQuery query = new TermQuery(new Term("f", query));
QueryScorer scorer = new QueryScorer(query);
SimpleHTMLFormatter formatter =
new SimpleHTMLFormatter("<span class=\"highlight\">",
"</span>");
Highlighter highlighter = new Highlighter(formatter, scorer);
Fragmenter fragmenter = new SimpleFragmenter(50);
highlighter.setTextFragmenter(fragmenter);

TokenStream tokenStream = new GreekAnalyzer()
.tokenStream("f", new StringReader(text));

String result = highlighter.getBestFragments(tokenStream, text, 5, "...");

return result;
}

if i use a text with english characters works fine if i try a text
with Greek Character i am getting en empty string as result.
Why?

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

Search Discussions

  • Grant Ingersoll at Jun 26, 2008 at 12:39 pm
    Because there are no matches? Have you checked your index, etc? Do
    you get matches for that query normally in Greek against your index
    (nevermind highlighting)? Are your analyzers the same? Are your
    English Fields stored and the Greek ones not? Does field "f" contain
    Greek? It could be a whole host of reasons and that snippet of code
    is not enough to go from. Check your index with Luke, etc. See the
    FAQ for more help, too.

    Also, please don't repost the same exact question 45 minutes later b/c
    you didn't get an immediate response at 3:48 AM East Coast US time.
    It just clutters email and makes it less likely that you will get a
    response.

    -Grant
    On Jun 26, 2008, at 3:48 AM, jim@tera.gr wrote:

    Hello

    i am having the following code to highlight a text

    public String highlight(String text, String query ) throws
    IOException {
    TermQuery query = new TermQuery(new Term("f", query));
    QueryScorer scorer = new QueryScorer(query);
    SimpleHTMLFormatter formatter =
    new SimpleHTMLFormatter("<span class=\"highlight\">",
    "</span>");
    Highlighter highlighter = new Highlighter(formatter, scorer);
    Fragmenter fragmenter = new SimpleFragmenter(50);
    highlighter.setTextFragmenter(fragmenter);

    TokenStream tokenStream = new GreekAnalyzer()
    .tokenStream("f", new StringReader(text));

    String result = highlighter.getBestFragments(tokenStream, text,
    5, "...");

    return result;
    }

    if i use a text with english characters works fine if i try a text
    with Greek Character i am getting en empty string as result.
    Why?

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
    --------------------------
    Grant Ingersoll
    http://www.lucidimagination.com

    Lucene Helpful Hints:
    http://wiki.apache.org/lucene-java/BasicsOfPerformance
    http://wiki.apache.org/lucene-java/LuceneFAQ








    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Eleanor Joslin at Jun 30, 2008 at 9:12 am
    You should be using the same analyzer when you query as when you built
    the index. I suspect that in this case you need to make an analyzer
    that recognises both English and Greek.

    I hope this helps,

    Eleanor Joslin

    jim@tera.gr wrote:
    Hello

    i am having the following code to highlight a text

    public String highlight(String text, String query ) throws IOException {
    TermQuery query = new TermQuery(new Term("f", query));
    QueryScorer scorer = new QueryScorer(query);
    SimpleHTMLFormatter formatter =
    new SimpleHTMLFormatter("<span class=\"highlight\">",
    "</span>");
    Highlighter highlighter = new Highlighter(formatter, scorer);
    Fragmenter fragmenter = new SimpleFragmenter(50);
    highlighter.setTextFragmenter(fragmenter);

    TokenStream tokenStream = new GreekAnalyzer()
    .tokenStream("f", new StringReader(text));

    String result = highlighter.getBestFragments(tokenStream, text, 5,
    "...");

    return result;
    }

    if i use a text with english characters works fine if i try a text with
    Greek Character i am getting en empty string as result.
    Why?

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

    --
    Eleanor Joslin, Software Development DecisionSoft Ltd.
    Telephone: +44-1865-203192 http://www.decisionsoft.com

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Jim at Jun 30, 2008 at 10:01 am
    Hi

    Sorry about doubble messaging, it was from mistake

    I am working on an application that searches documents with lucene.
    The documents are taken from a database and the basic field is in HTML.
    The index and searching works fine with Greek characters. I am using
    the lucene to take the ID and then the to get the
    corresponding record from database. My problem is that: i want to
    highlight the field with HTML query string that using on searching.

    Is it possible to do with Hightlighter or i must write my own class?


    Grant Ingersoll wrote:
    Because there are no matches? Have you checked your index, etc?
    Do you get matches for that query normally in Greek against your
    index (nevermind highlighting)? Are your analyzers the same? Are
    your English Fields stored and the Greek ones not? Does field "f"
    contain Greek? It could be a whole host of reasons and that
    snippet of code is not enough to go from. Check your index with
    Luke, etc. See the FAQ for more help, too.

    Also, please don't repost the same exact question 45 minutes later
    b/c you didn't get an immediate response at 3:48 AM East Coast US
    time. It just clutters email and makes it less likely that you
    will get a response.

    -Grant
    On Jun 26, 2008, at 3:48 AM, jim@tera.gr wrote:

    Hello

    i am having the following code to highlight a text

    public String highlight(String text, String query ) throws IOException {
    TermQuery query = new TermQuery(new Term("f", query));
    QueryScorer scorer = new QueryScorer(query);
    SimpleHTMLFormatter formatter =
    new SimpleHTMLFormatter("<span class=\"highlight\">",
    "</span>");
    Highlighter highlighter = new Highlighter(formatter, scorer);
    Fragmenter fragmenter = new SimpleFragmenter(50);
    highlighter.setTextFragmenter(fragmenter);

    TokenStream tokenStream = new GreekAnalyzer()
    .tokenStream("f", new StringReader(text));

    String result = highlighter.getBestFragments(tokenStream, text,
    5, "...");

    return result;
    }

    if i use a text with english characters works fine if i try a text
    with Greek Character i am getting en empty string as result.
    Why?

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
    --------------------------
    Grant Ingersoll
    http://www.lucidimagination.com

    Lucene Helpful Hints:
    http://wiki.apache.org/lucene-java/BasicsOfPerformance
    http://wiki.apache.org/lucene-java/LuceneFAQ








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


    No virus found in this incoming message.
    Checked by AVG. Version: 8.0.101 / Virus Database: 270.4.3/1525 -
    Release Date: 29/6/2008 3:09 ìì


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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedJun 26, '08 at 7:50a
activeJun 30, '08 at 10:01a
posts4
users3
websitelucene.apache.org

People

Translate

site design / logo © 2022 Grokbase