lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ritu choudhary <ritu.it...@gmail.com>
Subject Re: highlighting searched results in document
Date Thu, 28 May 2009 06:12:25 GMT
I  have added the lines you suggested and now its giving the following
output , still can't get what's wrong...

THE CHANGES I HAVE DONE:

SimpleHTMLFormatter formatter =
       new SimpleHTMLFormatter("<span class=\"highlight\">",
           "</span>");
   Highlighter highlighter = new Highlighter(formatter, new QueryScorer(query));
	
	    int maxNumFragmentsRequired=200;
		 String FragmentSeparator="...";
		 Fragmenter fragmenter = new SimpleFragmenter(50);

		   highlighter.setTextFragmenter(fragmenter);
		  	
		 TokenStream tokenStream=analyzer.tokenStream(FIELD_NAME,new
StringReader(text));
	     String result=highlighter.getBestFragments(tokenStream,text,maxNumFragmentsRequired,FragmentSeparator);
	
	    	System.out.println( "This is the result "+result);


OUTPUT:

Content field found--->>accept
This is the result <span class="highlight">accept</span>


On 28/05/2009, KK <dioxide.software@gmail.com> wrote:
> Yes, your code is wrong!
> Where is the highlighter span/formatter, because from your code what I can
> see is that you are just passsing the score to Queryscorer, instead you
> should pass both queryscore as well as formatter
> From my previous mail you can see the following code and mimic the same and
> it will work without any hitch,
>
> QueryScorer scorer = new QueryScorer(phrase);
>
>     SimpleHTMLFormatter formatter =
>         new SimpleHTMLFormatter("<span class=\"highlight\">",
>             "</span>");
>     Highlighter highlighter = new Highlighter(formatter, scorer);
>
> and this is your code,
>
> Highlighter highlighter = new Highlighter(new QueryScorer(query));
>
> You missed the formatter altogether but you added thestyler at the end,
> though. Add it and it will work like a charm.
>
> --KK
>
>
>
>
>
> On Wed, May 27, 2009 at 10:40 PM, Ritu choudhary
> <ritu.itzme@gmail.com>wrote:
>
>> Am i coding it wrongly ...please reply.
>>
>

---------------------------------------------------------------------
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