~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/search/DocSetDelegateCollector.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.solr.search;
2
 
 
3
 
/*
4
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
5
 
 * contributor license agreements.  See the NOTICE file distributed with
6
 
 * this work for additional information regarding copyright ownership.
7
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
8
 
 * (the "License"); you may not use this file except in compliance with
9
 
 * the License.  You may obtain a copy of the License at
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
13
 
 * Unless required by applicable law or agreed to in writing, software
14
 
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 
 * See the License for the specific language governing permissions and
17
 
 * limitations under the License.
18
 
 */
19
 
 
20
 
import org.apache.lucene.index.IndexReader;
21
 
import org.apache.lucene.search.Collector;
22
 
import org.apache.lucene.search.Scorer;
23
 
import org.apache.lucene.util.OpenBitSet;
24
 
 
25
 
import java.io.IOException;
26
 
 
27
 
/**
28
 
 *
29
 
 */
30
 
public class DocSetDelegateCollector extends DocSetCollector {
31
 
  final Collector collector;
32
 
 
33
 
  public DocSetDelegateCollector(int smallSetSize, int maxDoc, Collector collector) {
34
 
    super(smallSetSize, maxDoc);
35
 
    this.collector = collector;
36
 
  }
37
 
 
38
 
  @Override
39
 
  public void collect(int doc) throws IOException {
40
 
    collector.collect(doc);
41
 
 
42
 
    doc += base;
43
 
    // optimistically collect the first docs in an array
44
 
    // in case the total number will be small enough to represent
45
 
    // as a small set like SortedIntDocSet instead...
46
 
    // Storing in this array will be quicker to convert
47
 
    // than scanning through a potentially huge bit vector.
48
 
    // FUTURE: when search methods all start returning docs in order, maybe
49
 
    // we could have a ListDocSet() and use the collected array directly.
50
 
    if (pos < scratch.length) {
51
 
      scratch[pos]=doc;
52
 
    } else {
53
 
      // this conditional could be removed if BitSet was preallocated, but that
54
 
      // would take up more memory, and add more GC time...
55
 
      if (bits==null) bits = new OpenBitSet(maxDoc);
56
 
      bits.fastSet(doc);
57
 
    }
58
 
 
59
 
    pos++;
60
 
  }
61
 
 
62
 
  @Override
63
 
  public DocSet getDocSet() {
64
 
    if (pos<=scratch.length) {
65
 
      // assumes docs were collected in sorted order!
66
 
      return new SortedIntDocSet(scratch, pos);
67
 
    } else {
68
 
      // set the bits for ids that were collected in the array
69
 
      for (int i=0; i<scratch.length; i++) bits.fastSet(scratch[i]);
70
 
      return new BitDocSet(bits,pos);
71
 
    }
72
 
  }
73
 
 
74
 
  @Override
75
 
  public void setScorer(Scorer scorer) throws IOException {
76
 
    collector.setScorer(scorer);
77
 
  }
78
 
 
79
 
  @Override
80
 
  public void setNextReader(IndexReader indexReader, int docBase) throws IOException {
81
 
    collector.setNextReader(indexReader, docBase);
82
 
    this.base = docBase;
83
 
  }
84
 
}