lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Willnauer <simon.willna...@gmail.com>
Subject Re: TopDocCollector vs TopScoreDocCollector (semantics changed in 4.0, not backward comptabile)
Date Fri, 25 Jan 2013 09:13:32 GMT
hey,

you don't need to set the indexreader in the constructor. An
AtomicReader is passed in for each segment to
Collector#setNextReader(AtomicReaderContext)
If you want to use a given collector and extend it with some custom
code in collect I would likely write a delegate Collector like this:

public class DelegatingCollector extends Collector {

  private final Collector delegate;

  public DelegatingCollector(Collector delegate) {
    this.delegate = delegate;
  }

 public Collector getDelegate() {
    return delegate;
  }

  @Override
  public void setScorer(Scorer scorer) throws IOException {
    delegate.setScorer(scorer);
  }

  @Override
  public void collect(int doc) throws IOException {
    // ADD YOUR CUSTOM LOGIC HERE
    delegate.collect(doc);
  }

  @Override
  public void setNextReader(AtomicReaderContext context) throws IOException {
    // THIS IS WHERE YOU GET THE READER --> context.reader()
    delegate.setNextReader(context);
  }

  @Override
  public boolean acceptsDocsOutOfOrder() {
    return delegate.acceptsDocsOutOfOrder();
  }
}

maybe this is easier for you? then you can simply call
TopScoreDocCollector.create(int numHits, boolean docsScoredInOrder);
and use the specialized collector for your settings in the delegate?

simon

On Thu, Jan 24, 2013 at 11:37 PM, saisantoshi <saisantoshi76@gmail.com> wrote:
> Can someone please help us here to validate the above?
>
> Thanks,
> Sai.
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/TopDocCollector-vs-TopScoreDocCollector-semantics-changed-in-4-0-not-backward-comptabile-tp4035806p4036093.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>

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