Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
ReqExclScorer.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 
20 namespace Lucene.Net.Search
21 {
22 
23 
31  {
32  private Scorer reqScorer;
33  private DocIdSetIterator exclDisi;
34  private int doc = - 1;
35 
41  public ReqExclScorer(Scorer reqScorer, DocIdSetIterator exclDisi):base(null)
42  { // No similarity used.
43  this.reqScorer = reqScorer;
44  this.exclDisi = exclDisi;
45  }
46 
47  public override int NextDoc()
48  {
49  if (reqScorer == null)
50  {
51  return doc;
52  }
53  doc = reqScorer.NextDoc();
54  if (doc == NO_MORE_DOCS)
55  {
56  reqScorer = null; // exhausted, nothing left
57  return doc;
58  }
59  if (exclDisi == null)
60  {
61  return doc;
62  }
63  return doc = ToNonExcluded();
64  }
65 
78  private int ToNonExcluded()
79  {
80  int exclDoc = exclDisi.DocID();
81  int reqDoc = reqScorer.DocID(); // may be excluded
82  do
83  {
84  if (reqDoc < exclDoc)
85  {
86  return reqDoc; // reqScorer advanced to before exclScorer, ie. not excluded
87  }
88  else if (reqDoc > exclDoc)
89  {
90  exclDoc = exclDisi.Advance(reqDoc);
91  if (exclDoc == NO_MORE_DOCS)
92  {
93  exclDisi = null; // exhausted, no more exclusions
94  return reqDoc;
95  }
96  if (exclDoc > reqDoc)
97  {
98  return reqDoc; // not excluded
99  }
100  }
101  }
102  while ((reqDoc = reqScorer.NextDoc()) != NO_MORE_DOCS);
103  reqScorer = null; // exhausted, nothing left
104  return NO_MORE_DOCS;
105  }
106 
107  public override int DocID()
108  {
109  return doc;
110  }
111 
117  public override float Score()
118  {
119  return reqScorer.Score(); // reqScorer may be null when next() or skipTo() already return false
120  }
121 
122  public override int Advance(int target)
123  {
124  if (reqScorer == null)
125  {
126  return doc = NO_MORE_DOCS;
127  }
128  if (exclDisi == null)
129  {
130  return doc = reqScorer.Advance(target);
131  }
132  if (reqScorer.Advance(target) == NO_MORE_DOCS)
133  {
134  reqScorer = null;
135  return doc = NO_MORE_DOCS;
136  }
137  return doc = ToNonExcluded();
138  }
139  }
140 }