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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 using Document = Mono.Lucene.Net.Documents.Document;
21 using FieldSelector = Mono.Lucene.Net.Documents.FieldSelector;
22 using CorruptIndexException = Mono.Lucene.Net.Index.CorruptIndexException;
23 using Term = Mono.Lucene.Net.Index.Term;
25 namespace Mono.Lucene.Net.Search
28 /// <summary> The interface for search implementations.
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.
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.
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
44 public interface Searchable
47 /// <summary>Lower-level search API.
49 /// <p/>{@link HitCollector#Collect(int,float)} is called for every non-zero
51 /// <br/>HitCollector-based access to remote indexes is discouraged.
53 /// <p/>Applications should only use this if they need <i>all</i> of the
54 /// matching documents. The high-level search API ({@link
55 /// Searcher#Search(Query)}) is usually more efficient, as it skips
56 /// non-high-scoring hits.
59 /// <param name="weight">to match documents
61 /// <param name="filter">if non-null, used to permit documents to be collected.
63 /// <param name="results">to receive hits
65 /// <throws> BooleanQuery.TooManyClauses </throws>
66 /// <deprecated> use {@link #Search(Weight, Filter, Collector)} instead.
68 [Obsolete("use Search(Weight, Filter, Collector) instead.")]
69 void Search(Weight weight, Filter filter, HitCollector results);
71 /// <summary> Lower-level search API.
74 /// {@link Collector#Collect(int)} is called for every document. <br/>
75 /// Collector-based access to remote indexes is discouraged.
78 /// Applications should only use this if they need <i>all</i> of the matching
79 /// documents. The high-level search API ({@link Searcher#Search(Query)}) is
80 /// usually more efficient, as it skips non-high-scoring hits.
83 /// <param name="weight">to match documents
85 /// <param name="filter">if non-null, used to permit documents to be collected.
87 /// <param name="collector">to receive hits
89 /// <throws> BooleanQuery.TooManyClauses </throws>
90 void Search(Weight weight, Filter filter, Collector collector);
92 /// <summary>Frees resources associated with this Searcher.
93 /// Be careful not to call this method while you are still using objects
94 /// like {@link Hits}.
98 /// <summary>Expert: Returns the number of documents containing <code>term</code>.
99 /// Called by search code to compute term weights.
101 /// <seealso cref="Mono.Lucene.Net.Index.IndexReader.DocFreq(Term)">
103 int DocFreq(Term term);
105 /// <summary>Expert: For each term in the terms array, calculates the number of
106 /// documents containing <code>term</code>. Returns an array with these
107 /// document frequencies. Used to minimize number of remote calls.
109 int[] DocFreqs(Term[] terms);
111 /// <summary>Expert: Returns one greater than the largest possible document number.
112 /// Called by search code to compute term weights.
114 /// <seealso cref="Mono.Lucene.Net.Index.IndexReader.MaxDoc()">
118 /// <summary>Expert: Low-level search implementation. Finds the top <code>n</code>
119 /// hits for <code>query</code>, applying <code>filter</code> if non-null.
121 /// <p/>Called by {@link Hits}.
123 /// <p/>Applications should usually call {@link Searcher#Search(Query)} or
124 /// {@link Searcher#Search(Query,Filter)} instead.
126 /// <throws> BooleanQuery.TooManyClauses </throws>
127 TopDocs Search(Weight weight, Filter filter, int n);
129 /// <summary>Expert: Returns the stored fields of document <code>i</code>.
130 /// Called by {@link HitCollector} implementations.
132 /// <seealso cref="Mono.Lucene.Net.Index.IndexReader.Document(int)">
134 /// <throws> CorruptIndexException if the index is corrupt </throws>
135 /// <throws> IOException if there is a low-level IO error </throws>
138 /// <summary> Get the {@link Mono.Lucene.Net.Documents.Document} at the <code>n</code><sup>th</sup> position. The {@link Mono.Lucene.Net.Documents.FieldSelector}
139 /// may be used to determine what {@link Mono.Lucene.Net.Documents.Field}s to load and how they should be loaded.
141 /// <b>NOTE:</b> If the underlying Reader (more specifically, the underlying <code>FieldsReader</code>) is closed before the lazy {@link Mono.Lucene.Net.Documents.Field} is
142 /// loaded an exception may be thrown. If you want the value of a lazy {@link Mono.Lucene.Net.Documents.Field} to be available after closing you must
143 /// explicitly load it or fetch the Document again with a new loader.
147 /// <param name="n">Get the document at the <code>n</code><sup>th</sup> position
149 /// <param name="fieldSelector">The {@link Mono.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.
151 /// <returns> The stored fields of the {@link Mono.Lucene.Net.Documents.Document} at the nth position
153 /// <throws> CorruptIndexException if the index is corrupt </throws>
154 /// <throws> IOException if there is a low-level IO error </throws>
157 /// <seealso cref="Mono.Lucene.Net.Index.IndexReader.Document(int, FieldSelector)">
159 /// <seealso cref="Mono.Lucene.Net.Documents.Fieldable">
161 /// <seealso cref="Mono.Lucene.Net.Documents.FieldSelector">
163 /// <seealso cref="Mono.Lucene.Net.Documents.SetBasedFieldSelector">
165 /// <seealso cref="Mono.Lucene.Net.Documents.LoadFirstFieldSelector">
167 Document Doc(int n, FieldSelector fieldSelector);
169 /// <summary>Expert: called to re-write queries into primitive queries.</summary>
170 /// <throws> BooleanQuery.TooManyClauses </throws>
171 Query Rewrite(Query query);
173 /// <summary>Expert: low-level implementation method
174 /// Returns an Explanation that describes how <code>doc</code> scored against
175 /// <code>weight</code>.
177 /// <p/>This is intended to be used in developing Similarity implementations,
178 /// and, for good performance, should not be displayed with every hit.
179 /// Computing an explanation is as expensive as executing the query over the
181 /// <p/>Applications should call {@link Searcher#Explain(Query, int)}.
183 /// <throws> BooleanQuery.TooManyClauses </throws>
184 Explanation Explain(Weight weight, int doc);
186 /// <summary>Expert: Low-level search implementation with arbitrary sorting. Finds
187 /// the top <code>n</code> hits for <code>query</code>, applying
188 /// <code>filter</code> if non-null, and sorting the hits by the criteria in
189 /// <code>sort</code>.
191 /// <p/>Applications should usually call
192 /// {@link Searcher#Search(Query,Filter,int,Sort)} instead.
195 /// <throws> BooleanQuery.TooManyClauses </throws>
196 TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort);