Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
Searchable.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 FieldSelector = Lucene.Net.Documents.FieldSelector;
22 using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
23 using Term = Lucene.Net.Index.Term;
24 
25 namespace Lucene.Net.Search
26 {
27 
28  /// <summary> The interface for search implementations.
29  ///
30  /// <p/>
31  /// Searchable is the abstract network protocol for searching. Implementations
32  /// provide search over a single index, over multiple indices, and over indices
33  /// on remote servers.
34  ///
35  /// <p/>
36  /// Queries, filters and sort criteria are designed to be compact so that they
37  /// may be efficiently passed to a remote index, with only the top-scoring hits
38  /// being returned, rather than every matching hit.
39  ///
40  /// <b>NOTE:</b> this interface is kept public for convenience. Since it is not
41  /// expected to be implemented directly, it may be changed unexpectedly between
42  /// releases.
43  /// </summary>
44  public interface Searchable : IDisposable
45  {
46  /// <summary> Lower-level search API.
47  ///
48  /// <p/>
49  /// <see cref="Collector.Collect(int)" /> is called for every document. <br/>
50  /// Collector-based access to remote indexes is discouraged.
51  ///
52  /// <p/>
53  /// Applications should only use this if they need <i>all</i> of the matching
54  /// documents. The high-level search API (<see cref="Searcher.Search(Query,int)" />) is
55  /// usually more efficient, as it skips non-high-scoring hits.
56  ///
57  /// </summary>
58  /// <param name="weight">to match documents
59  /// </param>
60  /// <param name="filter">if non-null, used to permit documents to be collected.
61  /// </param>
62  /// <param name="collector">to receive hits
63  /// </param>
64  /// <throws> BooleanQuery.TooManyClauses </throws>
65  void Search(Weight weight, Filter filter, Collector collector);
66 
67  /// <summary>Frees resources associated with this Searcher.
68  /// Be careful not to call this method while you are still using objects
69  /// that reference this searchable
70  /// </summary>
71  void Close();
72 
73  /// <summary>Expert: Returns the number of documents containing <c>term</c>.
74  /// Called by search code to compute term weights.
75  /// </summary>
76  /// <seealso cref="Lucene.Net.Index.IndexReader.DocFreq(Term)">
77  /// </seealso>
78  int DocFreq(Term term);
79 
80  /// <summary>Expert: For each term in the terms array, calculates the number of
81  /// documents containing <c>term</c>. Returns an array with these
82  /// document frequencies. Used to minimize number of remote calls.
83  /// </summary>
84  int[] DocFreqs(Term[] terms);
85 
86  /// <summary>Expert: Returns one greater than the largest possible document number.
87  /// Called by search code to compute term weights.
88  /// </summary>
89  /// <seealso cref="Lucene.Net.Index.IndexReader.MaxDoc">
90  /// </seealso>
91  int MaxDoc { get; }
92 
93  /// <summary>
94  /// Expert: Low-level search implementation. Finds the top <c>n</c>
95  /// hits for <c>query</c>, applying <c>filter</c> if non-null.
96  ///
97  /// <p/>Applications should usually call <see cref="Searcher.Search(Query, int)" /> or
98  /// <see cref="Searcher.Search(Query,Filter,int)" /> instead.
99  /// </summary>
100  /// <throws> BooleanQuery.TooManyClauses </throws>
101  TopDocs Search(Weight weight, Filter filter, int n);
102 
103  /// <summary>Expert: Returns the stored fields of document <c>i</c>.</summary>
104  /// <seealso cref="Lucene.Net.Index.IndexReader.Document(int)" />
105  /// <throws> CorruptIndexException if the index is corrupt </throws>
106  /// <throws> IOException if there is a low-level IO error </throws>
107  Document Doc(int i);
108 
109  /// <summary> Get the <see cref="Lucene.Net.Documents.Document" />at the <c>n</c><sup>th</sup> position. The <see cref="Lucene.Net.Documents.FieldSelector"/>
110  /// may be used to determine what <see cref="Lucene.Net.Documents.Field" />s to load and how they should be loaded.
111  ///
112  /// <b>NOTE:</b> If the underlying Reader (more specifically, the underlying <c>FieldsReader</c>) is closed before the lazy <see cref="Lucene.Net.Documents.Field" /> is
113  /// loaded an exception may be thrown. If you want the value of a lazy <see cref="Lucene.Net.Documents.Field" /> to be available after closing you must
114  /// explicitly load it or fetch the Document again with a new loader.
115  ///
116  ///
117  /// </summary>
118  /// <param name="n">Get the document at the <c>n</c><sup>th</sup> position
119  /// </param>
120  /// <param name="fieldSelector">The <see cref="Lucene.Net.Documents.FieldSelector" /> to use to determine what Fields should be loaded on the Document. May be null, in which case all Fields will be loaded.
121  /// </param>
122  /// <returns> The stored fields of the <see cref="Lucene.Net.Documents.Document" /> at the nth position
123  /// </returns>
124  /// <throws> CorruptIndexException if the index is corrupt </throws>
125  /// <throws> IOException if there is a low-level IO error </throws>
126  /// <summary>
127  /// </summary>
128  /// <seealso cref="Lucene.Net.Index.IndexReader.Document(int, FieldSelector)">
129  /// </seealso>
130  /// <seealso cref="IFieldable">
131  /// </seealso>
132  /// <seealso cref="Lucene.Net.Documents.FieldSelector">
133  /// </seealso>
134  /// <seealso cref="Lucene.Net.Documents.SetBasedFieldSelector">
135  /// </seealso>
136  /// <seealso cref="Lucene.Net.Documents.LoadFirstFieldSelector">
137  /// </seealso>
138  Document Doc(int n, FieldSelector fieldSelector);
139 
140  /// <summary>Expert: called to re-write queries into primitive queries.</summary>
141  /// <throws> BooleanQuery.TooManyClauses </throws>
142  Query Rewrite(Query query);
143 
144  /// <summary>Expert: low-level implementation method
145  /// Returns an Explanation that describes how <c>doc</c> scored against
146  /// <c>weight</c>.
147  ///
148  /// <p/>This is intended to be used in developing Similarity implementations,
149  /// and, for good performance, should not be displayed with every hit.
150  /// Computing an explanation is as expensive as executing the query over the
151  /// entire index.
152  /// <p/>Applications should call <see cref="Searcher.Explain(Query, int)" />.
153  /// </summary>
154  /// <throws> BooleanQuery.TooManyClauses </throws>
155  Explanation Explain(Weight weight, int doc);
156 
157  /// <summary>Expert: Low-level search implementation with arbitrary sorting. Finds
158  /// the top <c>n</c> hits for <c>query</c>, applying
159  /// <c>filter</c> if non-null, and sorting the hits by the criteria in
160  /// <c>sort</c>.
161  ///
162  /// <p/>Applications should usually call
163  /// <see cref="Searcher.Search(Query,Filter,int,Sort)" /> instead.
164  ///
165  /// </summary>
166  /// <throws> BooleanQuery.TooManyClauses </throws>
167  TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort);
168  }
169 }