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
Searcher.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 using Lucene.Net.Documents;
20 using Document = Lucene.Net.Documents.Document;
21 using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
22 using Term = Lucene.Net.Index.Term;
23 
24 namespace Lucene.Net.Search
25 {
26 
34  public abstract class Searcher : System.MarshalByRefObject, Searchable, System.IDisposable
35  {
36  protected Searcher()
37  {
38  InitBlock();
39  }
40  private void InitBlock()
41  {
42  similarity = Net.Search.Similarity.Default;
43  }
44 
55  public virtual TopFieldDocs Search(Query query, Filter filter, int n, Sort sort)
56  {
57  return Search(CreateWeight(query), filter, n, sort);
58  }
59 
72  public virtual void Search(Query query, Collector results)
73  {
74  Search(CreateWeight(query), null, results);
75  }
76 
96  public virtual void Search(Query query, Filter filter, Collector results)
97  {
98  Search(CreateWeight(query), filter, results);
99  }
100 
106  public virtual TopDocs Search(Query query, Filter filter, int n)
107  {
108  return Search(CreateWeight(query), filter, n);
109  }
110 
116  public virtual TopDocs Search(Query query, int n)
117  {
118  return Search(query, null, n);
119  }
120 
129  public virtual Explanation Explain(Query query, int doc)
130  {
131  return Explain(CreateWeight(query), doc);
132  }
133 
135  private Similarity similarity;
136 
142  public virtual Similarity Similarity
143  {
144  get { return this.similarity; }
145  set { this.similarity = value; }
146  }
147 
151  public /*protected internal*/ virtual Weight CreateWeight(Query query)
152  {
153  return query.Weight(this);
154  }
155 
156  // inherit javadoc
157  public virtual int[] DocFreqs(Term[] terms)
158  {
159  int[] result = new int[terms.Length];
160  for (int i = 0; i < terms.Length; i++)
161  {
162  result[i] = DocFreq(terms[i]);
163  }
164  return result;
165  }
166 
167  public abstract void Search(Weight weight, Filter filter, Collector results);
168 
169  [Obsolete("Use Dispose() instead")]
170  public void Close()
171  {
172  Dispose();
173  }
174 
175  public void Dispose()
176  {
177  Dispose(true);
178  }
179 
180  protected abstract void Dispose(bool disposing);
181 
182  public abstract int DocFreq(Term term);
183  public abstract int MaxDoc { get; }
184  public abstract TopDocs Search(Weight weight, Filter filter, int n);
185  public abstract Document Doc(int i);
186  public abstract Document Doc(int docid, FieldSelector fieldSelector);
187  public abstract Query Rewrite(Query query);
188  public abstract Explanation Explain(Weight weight, int doc);
189  public abstract TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort);
190  /* End patch for GCJ bug #15411. */
191  }
192 }