2 * Copyright 2004 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 Document
= Lucene
.Net
.Documents
.Document
;
19 using IndexReader
= Lucene
.Net
.Index
.IndexReader
;
20 using Term
= Lucene
.Net
.Index
.Term
;
22 namespace Lucene
.Net
.Search
25 /// <summary>The interface for search implementations.
27 /// <p>Searchable is the abstract network protocol for searching.
28 /// Implementations provide search over a single index, over multiple
29 /// indices, and over indices on remote servers.
31 /// <p>Queries, filters and sort criteria are designed to be compact so that
32 /// they may be efficiently passed to a remote index, with only the top-scoring
33 /// hits being returned, rather than every non-zero scoring hit.
36 public interface Searchable
38 /// <summary>Lower-level search API.
40 /// <p>{@link HitCollector#Collect(int,float)} is called for every non-zero
42 /// <br>HitCollector-based access to remote indexes is discouraged.
44 /// <p>Applications should only use this if they need <i>all</i> of the
45 /// matching documents. The high-level search API ({@link
46 /// Searcher#Search(Query)}) is usually more efficient, as it skips
47 /// non-high-scoring hits.
50 /// <param name="query">to match documents
52 /// <param name="filter">if non-null, a bitset used to eliminate some documents
54 /// <param name="results">to receive hits
56 /// <throws> BooleanQuery.TooManyClauses </throws>
61 void Search(Query query
, Filter filter
, HitCollector results
);
63 /// <summary>Expert: Low-level search implementation.
64 /// Identical to {@link #Search(Query, Filter, HitCollector)}, but takes
65 /// a Weight instead of a query.
67 void Search(Weight weight
, Filter filter
, HitCollector results
);
69 /// <summary>Frees resources associated with this Searcher.
70 /// Be careful not to call this method while you are still using objects
71 /// like {@link Hits}.
75 /// <summary>Expert: Returns the number of documents containing <code>term</code>.
76 /// Called by search code to compute term weights.
78 /// <seealso cref="IndexReader#docFreq(Term)">
80 int DocFreq(Term term
);
82 /// <summary>Expert: For each term in the terms array, calculates the number of
83 /// documents containing <code>term</code>. Returns an array with these
84 /// document frequencies. Used to minimize number of remote calls.
86 int[] DocFreqs(Term
[] terms
);
88 /// <summary>Expert: Returns one greater than the largest possible document number.
89 /// Called by search code to compute term weights.
91 /// <seealso cref="IndexReader#maxDoc()">
95 /// <summary>Expert: Low-level search implementation. Finds the top <code>n</code>
96 /// hits for <code>query</code>, applying <code>filter</code> if non-null.
98 /// <p>Called by {@link Hits}.
100 /// <p>Applications should usually call {@link Searcher#Search(Query)} or
101 /// {@link Searcher#Search(Query,Filter)} instead.
103 /// <throws> BooleanQuery.TooManyClauses </throws>
108 TopDocs
Search(Query query
, Filter filter
, int n
);
110 /// <summary>Expert: Low-level search implementation.
111 /// Identical to {@link #Search(Query, Filter, int)}, but takes
112 /// a Weight instead of a query.
114 TopDocs
Search(Weight weight
, Filter filter
, int n
);
116 /// <summary>Expert: Returns the stored fields of document <code>i</code>.
117 /// Called by {@link HitCollector} implementations.
119 /// <seealso cref="IndexReader#document(int)">
123 /// <summary>Expert: called to re-write queries into primitive queries.</summary>
124 /// <throws> BooleanQuery.TooManyClauses </throws>
125 Query
Rewrite(Query query
);
127 /// <summary>Returns an Explanation that describes how <code>doc</code> scored against
128 /// <code>query</code>.
130 /// <p>This is intended to be used in developing Similarity implementations,
131 /// and, for good performance, should not be displayed with every hit.
132 /// Computing an explanation is as expensive as executing the query over the
135 /// <throws> BooleanQuery.TooManyClauses </throws>
136 Explanation
Explain(Query query
, int doc
);
138 /// <summary> Identical to {@link #Search(Query, Filter, HitCollector)}, but takes
139 /// a Weight instead of a query.
141 Explanation
Explain(Weight weight
, int doc
);
143 /// <summary>Expert: Low-level search implementation with arbitrary sorting. Finds
144 /// the top <code>n</code> hits for <code>query</code>, applying
145 /// <code>filter</code> if non-null, and sorting the hits by the criteria in
146 /// <code>sort</code>.
148 /// <p>Applications should usually call {@link
149 /// Searcher#Search(Query,Filter,Sort)} instead.
151 /// <throws> BooleanQuery.TooManyClauses </throws>
156 TopFieldDocs
Search(Query query
, Filter filter
, int n
, Sort sort
);
158 /// <summary>Expert: Low-level search implementation.
159 /// Identical to {@link #Search(Query, Filter, int, Sort)}, but takes
160 /// a Weight instead of a query.
162 TopFieldDocs
Search(Weight weight
, Filter filter
, int n
, Sort sort
);