lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Sokolov <msoko...@safaribooksonline.com>
Subject Re: Subclassing QueryScorer
Date Wed, 08 May 2013 00:00:38 GMT
On 5/7/2013 6:26 PM, Colin Pollock wrote:
> Hi, I want to modify how the QueryScorer selects fragments for snippeting. I
> want to add a small boost for fragments that contain certain terms (e.g.
> "great", "amazing") to the unique term occurrence score. But I don't want
> these words to actually be highlighted, so I can't just add them to the
> query (or make a WeightedSpamTerm[] myself containing both the query terms
> and word list terms and pass it to the QueryScorer).
>
> I tried to subclass lucene.search.highlight.QueryScorer and override the
> getTokenScore method. But the scorer's PositionIncrementAttribute field is
> private. I could change the Lucene source or copy QueryScorer's code into a
> new subclass.
Attributes have a slightly unusual API: you can get  handle on them by 
overriding init() (still calling super.init()), and calling:

posIncAtt = tokenStream.addAttribute(PositionIncrementAttribute.class);

setting your *own* posIncAtt (just like in QueryScorer.init()) -- you 
will get the *same* instance of the attribute

-Mike

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