QueryResponses.cs, DumpIndex.cs, IQueryResult.cs, QueryExecutor.cs, QueryResult.cs...
[beagle.git] / beagled / Lucene.Net / Search / MatchAllDocsQuery.cs
blob27742891e710adfc7c342a1cedd3082f46864cd2
1 /*
2 * Copyright 2005 The Apache Software Foundation
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
17 using System;
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.
25 ///
26 /// </summary>
27 /// <author> John Wang
28 /// </author>
29 [Serializable]
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
46 get
48 return enclosingInstance;
53 internal IndexReader reader;
54 internal int count;
55 internal int maxDoc;
57 internal MatchAllScorer(MatchAllDocsQuery enclosingInstance, IndexReader reader, Similarity similarity) : base(similarity)
59 InitBlock(enclosingInstance);
60 this.reader = reader;
61 count = - 1;
62 maxDoc = reader.MaxDoc();
65 public override int Doc()
67 return count;
70 public override Explanation Explain(int doc)
72 Explanation explanation = new Explanation();
73 explanation.SetValue(1.0f);
74 explanation.SetDescription("MatchAllDocsQuery");
75 return explanation;
78 public override bool Next()
80 while (count < (maxDoc - 1))
82 count++;
83 if (!reader.IsDeleted(count))
85 return true;
88 return false;
91 public override float Score()
93 return 1.0f;
96 public override bool SkipTo(int target)
98 count = target - 1;
99 return Next();
103 [Serializable]
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()
139 return 1.0f;
142 public virtual float SumOfSquaredWeights()
144 return 1.0f;
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());
167 return queryExpl;
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))
187 return false;
188 MatchAllDocsQuery other = (MatchAllDocsQuery) o;
189 return this.GetBoost() == other.GetBoost();
192 public override int GetHashCode()
194 return BitConverter.ToInt32(BitConverter.GetBytes(GetBoost()), 0);