Coverage Report - org.crosswire.jsword.index.lucene.VerseCollector
 
Classes in this File Line Coverage Branch Coverage Complexity
VerseCollector
0%
0/18
N/A
1.4
 
 1  
 /**
 2  
  * Distribution License:
 3  
  * JSword is free software; you can redistribute it and/or modify it under
 4  
  * the terms of the GNU Lesser General Public License, version 2.1 or later
 5  
  * as published by the Free Software Foundation. This program is distributed
 6  
  * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 7  
  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 8  
  * See the GNU Lesser General Public License for more details.
 9  
  *
 10  
  * The License is available on the internet at:
 11  
  *      http://www.gnu.org/copyleft/lgpl.html
 12  
  * or by writing to:
 13  
  *      Free Software Foundation, Inc.
 14  
  *      59 Temple Place - Suite 330
 15  
  *      Boston, MA 02111-1307, USA
 16  
  *
 17  
  * © CrossWire Bible Society, 2007 - 2016
 18  
  *
 19  
  */
 20  
 package org.crosswire.jsword.index.lucene;
 21  
 
 22  
 import java.io.IOException;
 23  
 
 24  
 import org.apache.lucene.document.Document;
 25  
 import org.apache.lucene.index.IndexReader;
 26  
 import org.apache.lucene.search.Collector;
 27  
 import org.apache.lucene.search.Scorer;
 28  
 import org.apache.lucene.search.Searcher;
 29  
 import org.crosswire.jsword.passage.Key;
 30  
 import org.crosswire.jsword.passage.NoSuchVerseException;
 31  
 import org.crosswire.jsword.passage.VerseFactory;
 32  
 import org.crosswire.jsword.versification.Versification;
 33  
 
 34  
 /**
 35  
  * A simple collector of verses that stores the verses in a Key.
 36  
  * 
 37  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 38  
  * @author DM Smith
 39  
  */
 40  
 public class VerseCollector extends Collector {
 41  
 
 42  
     /**
 43  
      * Create a collector for the searcher that populates results.
 44  
      * @param v11n
 45  
      *            the versification to which referenced pertains
 46  
      * @param searcher 
 47  
      * @param results 
 48  
      */
 49  0
     public VerseCollector(Versification v11n, Searcher searcher, Key results) {
 50  0
         this.v11n = v11n;
 51  0
         this.searcher = searcher;
 52  0
         this.results = results;
 53  0
     }
 54  
 
 55  
     /*
 56  
      * (non-Javadoc)
 57  
      * 
 58  
      * @see org.apache.lucene.search.Collector#acceptsDocsOutOfOrder()
 59  
      */
 60  
     @Override
 61  
     public boolean acceptsDocsOutOfOrder() {
 62  
         // Order is unimportant
 63  0
         return true;
 64  
     }
 65  
 
 66  
     /*
 67  
      * (non-Javadoc)
 68  
      * 
 69  
      * @see org.apache.lucene.search.Collector#collect(int)
 70  
      */
 71  
     @Override
 72  
     public void collect(int docId) throws IOException {
 73  0
         Document doc = searcher.doc(docBase + docId);
 74  
         try {
 75  0
             Key key = VerseFactory.fromString(v11n, doc.get(LuceneIndex.FIELD_KEY));
 76  0
             results.addAll(key);
 77  0
         } catch (NoSuchVerseException e) {
 78  
             // Wrap the NoSuchVerseException in an IOException so it can be
 79  
             // gotten.
 80  0
             IOException ioe = new IOException();
 81  0
             ioe.initCause(e);
 82  0
             throw ioe;
 83  
             // JDK6: Change to:
 84  
             // throw new IOException(e);
 85  0
         }
 86  0
     }
 87  
 
 88  
     /*
 89  
      * (non-Javadoc)
 90  
      * 
 91  
      * @see
 92  
      * org.apache.lucene.search.Collector#setNextReader(org.apache.lucene.index
 93  
      * .IndexReader, int)
 94  
      */
 95  
     @Override
 96  
     public void setNextReader(IndexReader reader, int docBase) throws IOException {
 97  0
         this.docBase = docBase;
 98  0
     }
 99  
 
 100  
     /*
 101  
      * (non-Javadoc)
 102  
      * 
 103  
      * @see
 104  
      * org.apache.lucene.search.Collector#setScorer(org.apache.lucene.search
 105  
      * .Scorer)
 106  
      */
 107  
     @Override
 108  
     public void setScorer(Scorer scorer) throws IOException {
 109  
         // This collector does no scoring. It collects all hits.
 110  0
     }
 111  
 
 112  
     private int docBase;
 113  
     private Versification v11n;
 114  
     private Searcher searcher;
 115  
     private Key results;
 116  
 }