2 * Copyright 2005 The Apache Software Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using IndexReader
= Lucene
.Net
.Index
.IndexReader
;
19 using ToStringUtils
= Lucene
.Net
.Util
.ToStringUtils
;
21 namespace Lucene
.Net
.Search
24 /// <summary> A query that matches all documents.
27 /// <author> John Wang
30 public class MatchAllDocsQuery
: Query
33 public MatchAllDocsQuery()
37 private class MatchAllScorer
:Scorer
39 private void InitBlock(MatchAllDocsQuery enclosingInstance
)
41 this.enclosingInstance
= enclosingInstance
;
43 private MatchAllDocsQuery enclosingInstance
;
44 public MatchAllDocsQuery Enclosing_Instance
48 return enclosingInstance
;
53 internal IndexReader reader
;
57 internal MatchAllScorer(MatchAllDocsQuery enclosingInstance
, IndexReader reader
, Similarity similarity
) : base(similarity
)
59 InitBlock(enclosingInstance
);
62 maxDoc
= reader
.MaxDoc();
65 public override int Doc()
70 public override Explanation
Explain(int doc
)
72 Explanation explanation
= new Explanation();
73 explanation
.SetValue(1.0f
);
74 explanation
.SetDescription("MatchAllDocsQuery");
78 public override bool Next()
80 while (count
< (maxDoc
- 1))
83 if (!reader
.IsDeleted(count
))
91 public override float Score()
96 public override bool SkipTo(int target
)
104 private class MatchAllDocsWeight
: Weight
106 private void InitBlock(MatchAllDocsQuery enclosingInstance
)
108 this.enclosingInstance
= enclosingInstance
;
110 private MatchAllDocsQuery enclosingInstance
;
111 public MatchAllDocsQuery Enclosing_Instance
115 return enclosingInstance
;
119 private Searcher searcher
;
121 public MatchAllDocsWeight(MatchAllDocsQuery enclosingInstance
, Searcher searcher
)
123 InitBlock(enclosingInstance
);
124 this.searcher
= searcher
;
127 public override System
.String
ToString()
129 return "weight(" + Enclosing_Instance
+ ")";
132 public virtual Query
GetQuery()
134 return Enclosing_Instance
;
137 public virtual float GetValue()
142 public virtual float SumOfSquaredWeights()
147 public virtual void Normalize(float queryNorm
)
151 public virtual Scorer
Scorer(IndexReader reader
)
153 return new MatchAllScorer(enclosingInstance
, reader
, Enclosing_Instance
.GetSimilarity(searcher
));
156 public virtual Explanation
Explain(IndexReader reader
, int doc
)
158 // explain query weight
159 Explanation queryExpl
= new Explanation();
160 queryExpl
.SetDescription("MatchAllDocsQuery:");
162 Explanation boostExpl
= new Explanation(Enclosing_Instance
.GetBoost(), "boost");
163 if (Enclosing_Instance
.GetBoost() != 1.0f
)
164 queryExpl
.AddDetail(boostExpl
);
165 queryExpl
.SetValue(boostExpl
.GetValue());
171 protected internal override Weight
CreateWeight(Searcher searcher
)
173 return new MatchAllDocsWeight(this, searcher
);
176 public override System
.String
ToString(System
.String field
)
178 System
.Text
.StringBuilder buffer
= new System
.Text
.StringBuilder();
179 buffer
.Append("MatchAllDocsQuery");
180 buffer
.Append(ToStringUtils
.Boost(GetBoost()));
181 return buffer
.ToString();
184 public override bool Equals(System
.Object o
)
186 if (!(o
is MatchAllDocsQuery
))
188 MatchAllDocsQuery other
= (MatchAllDocsQuery
) o
;
189 return this.GetBoost() == other
.GetBoost();
192 public override int GetHashCode()
194 return BitConverter
.ToInt32(BitConverter
.GetBytes(GetBoost()), 0);