Index: trunk/lucene-search-3/src/main/java/org/apache/lucene/search/MultiSearcherBase.java |
— | — | @@ -17,17 +17,18 @@ |
18 | 18 | * limitations under the License. |
19 | 19 | */ |
20 | 20 | |
21 | | -import org.apache.lucene.document.Document; |
22 | | -import org.apache.lucene.document.FieldSelector; |
23 | | -import org.apache.lucene.index.CorruptIndexException; |
24 | | -import org.apache.lucene.index.Term; |
25 | | - |
26 | 21 | import java.io.IOException; |
27 | 22 | import java.util.HashMap; |
28 | 23 | import java.util.HashSet; |
29 | 24 | import java.util.Map; |
30 | 25 | import java.util.Set; |
31 | 26 | |
| 27 | +import org.apache.lucene.document.Document; |
| 28 | +import org.apache.lucene.document.FieldSelector; |
| 29 | +import org.apache.lucene.index.CorruptIndexException; |
| 30 | +import org.apache.lucene.index.IndexReader; |
| 31 | +import org.apache.lucene.index.Term; |
| 32 | + |
32 | 33 | /** Implements search over a set of <code>Searchables</code>. |
33 | 34 | * |
34 | 35 | * <p>Applications usually need only call the inherited {@link #search(Query)} |
— | — | @@ -103,10 +104,20 @@ |
104 | 105 | public TopDocs search(Weight weight,Filter filter,int n) { |
105 | 106 | throw new UnsupportedOperationException(); |
106 | 107 | } |
| 108 | + |
| 109 | + @Override |
| 110 | + public void search(Weight weight, Filter filter, Collector results) |
| 111 | + throws IOException { |
| 112 | + throw new UnsupportedOperationException(); |
| 113 | + |
| 114 | + } |
| 115 | + |
107 | 116 | |
108 | 117 | public TopFieldDocs search(Weight weight,Filter filter,int n,Sort sort) { |
109 | 118 | throw new UnsupportedOperationException(); |
110 | 119 | } |
| 120 | + |
| 121 | + |
111 | 122 | } |
112 | 123 | |
113 | 124 | |
— | — | @@ -207,11 +218,11 @@ |
208 | 219 | public int maxDoc() throws IOException { |
209 | 220 | return maxDoc; |
210 | 221 | } |
211 | | - |
| 222 | + |
212 | 223 | public TopDocs search(Weight weight, Filter filter, int nDocs) |
213 | 224 | throws IOException { |
214 | 225 | |
215 | | - HitQueue hq = new HitQueue(nDocs); |
| 226 | + HitQueue hq = new HitQueue(nDocs, false); |
216 | 227 | int totalHits = 0; |
217 | 228 | |
218 | 229 | for (int i = 0; i < searchables.length; i++) { // search each searcher |
— | — | @@ -256,6 +267,8 @@ |
257 | 268 | break; // no more scores > minScore |
258 | 269 | } |
259 | 270 | } |
| 271 | + |
| 272 | + |
260 | 273 | |
261 | 274 | ScoreDoc[] scoreDocs = new ScoreDoc[hq.size()]; |
262 | 275 | for (int i = hq.size() - 1; i >= 0; i--) // put docs in array |
— | — | @@ -264,7 +277,61 @@ |
265 | 278 | return new TopFieldDocs (totalHits, scoreDocs, hq.getFields(), maxScore); |
266 | 279 | } |
267 | 280 | |
| 281 | + @Override |
| 282 | + public void search(Weight weight, Filter filter, final Collector results) |
| 283 | + throws IOException { |
268 | 284 | |
| 285 | + for (int i = 0; i < searchables.length; i++) { // search each searcher |
| 286 | + |
| 287 | + final int start=starts[i]; |
| 288 | + |
| 289 | + searchables[i].search(weight, filter, new Collector(){ |
| 290 | + |
| 291 | + private Scorer scorer; |
| 292 | + @Override |
| 293 | + public void setScorer(Scorer scorer) throws IOException { |
| 294 | + this.scorer=scorer; |
| 295 | + |
| 296 | + } |
| 297 | + |
| 298 | + @Override |
| 299 | + public void collect(int doc) throws IOException { |
| 300 | + try{ |
| 301 | + results.collect(doc+start); |
| 302 | + }catch(IOException e){ |
| 303 | + e.printStackTrace(); |
| 304 | + } |
| 305 | + |
| 306 | + } |
| 307 | + |
| 308 | + @Override |
| 309 | + public void setNextReader(IndexReader reader, int docBase) |
| 310 | + throws IOException { |
| 311 | + // TODO Auto-generated method stub |
| 312 | + |
| 313 | + } |
| 314 | + |
| 315 | + @Override |
| 316 | + public boolean acceptsDocsOutOfOrder() { |
| 317 | + // TODO Auto-generated method stub |
| 318 | + return false; |
| 319 | + } |
| 320 | + |
| 321 | + }); |
| 322 | + /* |
| 323 | + TopDocs docs = searchables[i].search(weight, filter, nDocs); |
| 324 | + totalHits += docs.totalHits; // update totalHits |
| 325 | + ScoreDoc[] scoreDocs = docs.scoreDocs; |
| 326 | + for (int j = 0; j < scoreDocs.length; j++) { // merge scoreDocs into hq |
| 327 | + ScoreDoc scoreDoc = scoreDocs[j]; |
| 328 | + scoreDoc.doc += starts[i]; // convert doc |
| 329 | + if(!hq.insert(scoreDoc)) |
| 330 | + break; // no more scores > minScore |
| 331 | + */ |
| 332 | + } |
| 333 | + |
| 334 | + } |
| 335 | + |
269 | 336 | // inherit javadoc |
270 | 337 | public void search(Weight weight, Filter filter, final HitCollector results) |
271 | 338 | throws IOException { |
— | — | @@ -361,4 +428,5 @@ |
362 | 429 | return rewrittenQuery.weight(cacheSim); |
363 | 430 | } |
364 | 431 | |
| 432 | + |
365 | 433 | } |
Index: trunk/lucene-search-3/src/main/java/org/apache/lucene/search/PositionalQuery.java |
— | — | @@ -151,7 +151,7 @@ |
152 | 152 | * @author rainman |
153 | 153 | * |
154 | 154 | */ |
155 | | - protected class PositionalWeight implements Weight//PhraseWeight |
| 155 | + protected class PositionalWeight extends Weight//PhraseWeight |
156 | 156 | { |
157 | 157 | |
158 | 158 | private Similarity similarity; |
— | — | @@ -177,6 +177,13 @@ |
178 | 178 | queryWeight *= queryNorm; // normalize query weight |
179 | 179 | value = queryWeight * idf; // idf for document |
180 | 180 | } |
| 181 | + |
| 182 | + @Override |
| 183 | + public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder, |
| 184 | + boolean topScorer) throws IOException { |
| 185 | + |
| 186 | + return scorer(reader) ; |
| 187 | + } |
181 | 188 | |
182 | 189 | public Scorer scorer(IndexReader reader) throws IOException { |
183 | 190 | if (terms.size() == 0) // optimize zero-term case |
— | — | @@ -293,6 +300,8 @@ |
294 | 301 | queryWeight = idf * getBoost(); // compute query weight |
295 | 302 | return queryWeight * queryWeight; // square it |
296 | 303 | } |
| 304 | + |
| 305 | + |
297 | 306 | } |
298 | 307 | |
299 | 308 | @Override |
Index: trunk/lucene-search-3/src/main/java/org/apache/lucene/search/RemoteSearchableMul.java |
— | — | @@ -47,6 +47,14 @@ |
48 | 48 | return local.maxDoc(); |
49 | 49 | } |
50 | 50 | |
| 51 | + |
| 52 | + @Override |
| 53 | + public void search(Weight weight, Filter filter, Collector results) |
| 54 | + throws IOException { |
| 55 | + local.search(weight, filter, results); |
| 56 | + |
| 57 | + } |
| 58 | + |
51 | 59 | public TopDocs search(Weight weight, Filter filter, int n) throws IOException { |
52 | 60 | return local.search(weight, filter, n); |
53 | 61 | } |
— | — | @@ -88,4 +96,7 @@ |
89 | 97 | return local.doc(n,fieldSelector); |
90 | 98 | } |
91 | 99 | |
| 100 | + |
| 101 | + |
| 102 | + |
92 | 103 | } |