lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ito hayato <>
Subject Unexpected highlighted text
Date Mon, 06 Apr 2009 11:02:32 GMT
Hi All, 
My name is Hayato.

I have a question for Highlighter.

I indexed following text and use Tokenizer.

text     : abracadabra
Tokenizer: NGramAnalyzer

and requested following query 

query    : ab

expected result and actual result is following

expect   : <B>ab</B>racad<B>ab</B>ra
actual   : <B>abracadab</B>ra

To be more specific, i try this testcase, but failed.

is this behavior valid?
if valid, please teach me why this result...

    public static class NGramAnalyzer extends Analyzer {
        int minGram;

        int maxGram;

        public NGramAnalyzer(int minGram, int maxGram) {
            this.maxGram = maxGram;
            this.minGram = minGram;

        public TokenStream tokenStream(String fieldName, reader) {
            return new NGramTokenizer(reader, minGram,

    public void testGetBestTextFragments2() throws
IOException, ParseException {
        String CONTENT = "abracadabra";
        String QUERY_STRING = "ab";
        String F = "f";
        Analyzer analyzer = new NGramAnalyzer(2,2);
        TokenStream tokenStream =
analyzer.tokenStream("f", new StringReader(CONTENT));

        QueryParser qp = new QueryParser(F, analyzer);
        Query query = null;
        query = qp.parse(QUERY_STRING);

        Scorer scorer = new QueryScorer(query, F);
        Highlighter h = new Highlighter(scorer);

h.getBestTextFragments(tokenStream, CONTENT, true,


Power up the Internet with Yahoo! Toolbar.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message