1 package org.apache.lucene.search; 2 3 18 19 import java.io.IOException ; 20 21 22 27 public class ReqExclScorer extends Scorer { 28 private Scorer reqScorer, exclScorer; 29 30 34 public ReqExclScorer( 35 Scorer reqScorer, 36 Scorer exclScorer) { 37 super(null); this.reqScorer = reqScorer; 39 this.exclScorer = exclScorer; 40 } 41 42 private boolean firstTime = true; 43 44 public boolean next() throws IOException { 45 if (firstTime) { 46 if (! exclScorer.next()) { 47 exclScorer = null; } 49 firstTime = false; 50 } 51 if (reqScorer == null) { 52 return false; 53 } 54 if (! reqScorer.next()) { 55 reqScorer = null; return false; 57 } 58 if (exclScorer == null) { 59 return true; } 61 return toNonExcluded(); 62 } 63 64 75 private boolean toNonExcluded() throws IOException { 76 int exclDoc = exclScorer.doc(); 77 do { 78 int reqDoc = reqScorer.doc(); if (reqDoc < exclDoc) { 80 return true; } else if (reqDoc > exclDoc) { 82 if (! exclScorer.skipTo(reqDoc)) { 83 exclScorer = null; return true; 85 } 86 exclDoc = exclScorer.doc(); 87 if (exclDoc > reqDoc) { 88 return true; } 90 } 91 } while (reqScorer.next()); 92 reqScorer = null; return false; 94 } 95 96 public int doc() { 97 return reqScorer.doc(); } 99 100 104 public float score() throws IOException { 105 return reqScorer.score(); } 107 108 114 public boolean skipTo(int target) throws IOException { 115 if (firstTime) { 116 firstTime = false; 117 if (! exclScorer.skipTo(target)) { 118 exclScorer = null; } 120 } 121 if (reqScorer == null) { 122 return false; 123 } 124 if (exclScorer == null) { 125 return reqScorer.skipTo(target); 126 } 127 if (! reqScorer.skipTo(target)) { 128 reqScorer = null; 129 return false; 130 } 131 return toNonExcluded(); 132 } 133 134 public Explanation explain(int doc) throws IOException { 135 Explanation res = new Explanation(); 136 if (exclScorer.skipTo(doc) && (exclScorer.doc() == doc)) { 137 res.setDescription("excluded"); 138 } else { 139 res.setDescription("not excluded"); 140 res.addDetail(reqScorer.explain(doc)); 141 } 142 return res; 143 } 144 } 145 | Popular Tags |