DelegatingScoringQueryExecutor.java

  1. /*
  2.  *  DelegatingScoringQueryExecutor.java
  3.  *
  4.  *  Copyright (c) 2007-2011, The University of Sheffield.
  5.  *
  6.  *  This file is part of GATE Mímir (see http://gate.ac.uk/family/mimir.html),
  7.  *  and is free software, licenced under the GNU Lesser General Public License,
  8.  *  Version 3, June 2007 (also included with this distribution as file
  9.  *  LICENCE-LGPL3.html).
  10.  *
  11.  *  Valentin Tablan, 14 September 2011
  12.  *
  13.  *  $Id: DelegatingScoringQueryExecutor.java 16667 2013-04-29 16:35:35Z valyt $
  14.  */
  15. package gate.mimir.search.score;

  16. import gate.mimir.search.query.Binding;
  17. import gate.mimir.search.query.QueryExecutor;
  18. import it.unimi.dsi.fastutil.objects.Reference2DoubleMap;
  19. import it.unimi.di.big.mg4j.index.Index;
  20. import it.unimi.di.big.mg4j.search.DocumentIterator;
  21. import it.unimi.di.big.mg4j.search.score.DelegatingScorer;

  22. import java.io.IOException;

  23. /**
  24.  * Implementation of {@link MimirScorer} that delegates the scoring work to an
  25.  * MG4J {@link DelegatingScorer}.
  26.  */
  27. public class DelegatingScoringQueryExecutor implements MimirScorer {
  28.  
  29.   public DelegatingScoringQueryExecutor(DelegatingScorer scorer)
  30.     throws IOException {
  31.     this.underlyingScorer = scorer;
  32.   }
  33.  
  34.   public long nextDocument(long greaterThan) throws IOException {
  35.     return underlyingExecutor.nextDocument(greaterThan);
  36.   }
  37.  
  38.  
  39.   /* (non-Javadoc)
  40.    * @see gate.mimir.search.query.MimirScorer#nextHit()
  41.    */
  42.   @Override
  43.   public Binding nextHit() throws IOException {
  44.     return underlyingExecutor.nextHit();
  45.   }
  46.  
  47.   public double score() throws IOException {
  48.     return underlyingScorer.score();
  49.   }

  50.   private DelegatingScorer underlyingScorer;
  51.  
  52.   private QueryExecutor underlyingExecutor;



  53.   public double score(Index index) throws IOException {
  54.     return underlyingScorer.score(index);
  55.   }

  56.   public boolean setWeights(Reference2DoubleMap<Index> index2Weight) {
  57.     return underlyingScorer.setWeights(index2Weight);
  58.   }



  59.   public Reference2DoubleMap<Index> getWeights() {
  60.     return underlyingScorer.getWeights();
  61.   }


  62.   public long nextDocument() throws IOException {
  63.     return underlyingScorer.nextDocument();
  64.   }



  65.   public DelegatingScorer copy() {
  66.     try {
  67.       return new DelegatingScoringQueryExecutor(
  68.           (DelegatingScorer)underlyingScorer.copy());
  69.     } catch(IOException e) {
  70.       throw new RuntimeException(e);
  71.     }
  72.   }


  73.   public void wrap(DocumentIterator queryExecutor) throws IOException {
  74.     underlyingExecutor = (QueryExecutor)queryExecutor;
  75.     underlyingScorer.wrap(queryExecutor);
  76.   }

  77.   public boolean usesIntervals() {
  78.     return underlyingScorer.usesIntervals();
  79.   }
  80. }