equal
deleted
inserted
replaced
14 #include "clucene/document/document.h" |
14 #include "clucene/document/document.h" |
15 #include "clucene/index/indexreader.h" |
15 #include "clucene/index/indexreader.h" |
16 #include "clucene/index/term.h" |
16 #include "clucene/index/term.h" |
17 #include "clucene/util/bitset.h" |
17 #include "clucene/util/bitset.h" |
18 #include "fieldsortedhitqueue.h" |
18 #include "fieldsortedhitqueue.h" |
19 |
|
20 CL_NS_USE(index) |
19 CL_NS_USE(index) |
21 CL_NS_USE(util) |
20 CL_NS_USE(util) |
22 CL_NS_USE(document) |
21 CL_NS_USE(document) |
23 |
22 |
24 CL_NS_DEF(search) |
23 CL_NS_DEF(search) |
110 |
109 |
111 CND_PRECONDITION(path != NULL, "path is NULL"); |
110 CND_PRECONDITION(path != NULL, "path is NULL"); |
112 |
111 |
113 reader = IndexReader::open(path); |
112 reader = IndexReader::open(path); |
114 readerOwner = true; |
113 readerOwner = true; |
|
114 |
|
115 |
115 } |
116 } |
116 |
117 |
117 IndexSearcher::IndexSearcher(CL_NS(store)::Directory* directory){ |
118 IndexSearcher::IndexSearcher(CL_NS(store)::Directory* directory){ |
118 //Func - Constructor |
119 //Func - Constructor |
119 // Creates a searcher searching the index in the specified directory. */ |
120 // Creates a searcher searching the index in the specified directory. */ |
122 |
123 |
123 CND_PRECONDITION(directory != NULL, "directory is NULL"); |
124 CND_PRECONDITION(directory != NULL, "directory is NULL"); |
124 |
125 |
125 reader = IndexReader::open(directory); |
126 reader = IndexReader::open(directory); |
126 readerOwner = true; |
127 readerOwner = true; |
|
128 |
|
129 |
127 } |
130 } |
128 |
131 |
129 IndexSearcher::IndexSearcher(IndexReader* r){ |
132 IndexSearcher::IndexSearcher(IndexReader* r){ |
130 //Func - Constructor |
133 //Func - Constructor |
131 // Creates a searcher searching the index with the provide IndexReader |
134 // Creates a searcher searching the index with the provide IndexReader |
132 //Pre - path != NULL |
135 //Pre - path != NULL |
133 //Post - The instance has been created |
136 //Post - The instance has been created |
134 |
137 |
135 reader = r; |
138 reader = r; |
136 readerOwner = false; |
139 readerOwner = false; |
|
140 |
137 } |
141 } |
138 |
142 |
139 IndexSearcher::~IndexSearcher(){ |
143 IndexSearcher::~IndexSearcher(){ |
140 //Func - Destructor |
144 //Func - Destructor |
141 //Pre - true |
145 //Pre - true |
198 |
202 |
199 TopDocs* IndexSearcher::_search(Query* query, Filter* filter, const int32_t nDocs){ |
203 TopDocs* IndexSearcher::_search(Query* query, Filter* filter, const int32_t nDocs){ |
200 //Func - |
204 //Func - |
201 //Pre - reader != NULL |
205 //Pre - reader != NULL |
202 //Post - |
206 //Post - |
203 |
|
204 CND_PRECONDITION(reader != NULL, "reader is NULL"); |
207 CND_PRECONDITION(reader != NULL, "reader is NULL"); |
205 CND_PRECONDITION(query != NULL, "query is NULL"); |
208 CND_PRECONDITION(query != NULL, "query is NULL"); |
|
209 |
|
210 |
206 |
211 |
207 Weight* weight = query->weight(this); |
212 Weight* weight = query->weight(this); |
208 Scorer* scorer = weight->scorer(reader); |
213 Scorer* scorer = weight->scorer(reader); |
209 if (scorer == NULL){ |
214 if (scorer == NULL){ |
210 return _CLNEW TopDocs(0, NULL, 0); |
215 return _CLNEW TopDocs(0, NULL, 0); |
245 } |
250 } |
246 |
251 |
247 // inherit javadoc |
252 // inherit javadoc |
248 TopFieldDocs* IndexSearcher::_search(Query* query, Filter* filter, const int32_t nDocs, |
253 TopFieldDocs* IndexSearcher::_search(Query* query, Filter* filter, const int32_t nDocs, |
249 const Sort* sort) { |
254 const Sort* sort) { |
250 |
255 |
|
256 |
251 CND_PRECONDITION(reader != NULL, "reader is NULL"); |
257 CND_PRECONDITION(reader != NULL, "reader is NULL"); |
252 CND_PRECONDITION(query != NULL, "query is NULL"); |
258 CND_PRECONDITION(query != NULL, "query is NULL"); |
|
259 |
|
260 |
253 |
261 |
254 Weight* weight = query->weight(this); |
262 Weight* weight = query->weight(this); |
255 Scorer* scorer = weight->scorer(reader); |
263 Scorer* scorer = weight->scorer(reader); |
256 if (scorer == NULL){ |
264 if (scorer == NULL){ |
257 return _CLNEW TopFieldDocs(0, NULL, 0, NULL ); |
265 return _CLNEW TopFieldDocs(0, NULL, 0, NULL ); |
293 // as it skips non-high-scoring hits. |
301 // as it skips non-high-scoring hits. |
294 //Pre - query is a valid reference to a query |
302 //Pre - query is a valid reference to a query |
295 // filter may or may not be NULL |
303 // filter may or may not be NULL |
296 // results is a valid reference to a HitCollector and used to store the results |
304 // results is a valid reference to a HitCollector and used to store the results |
297 //Post - filter if non-NULL, a bitset used to eliminate some documents |
305 //Post - filter if non-NULL, a bitset used to eliminate some documents |
298 |
306 |
299 CND_PRECONDITION(reader != NULL, "reader is NULL"); |
307 CND_PRECONDITION(reader != NULL, "reader is NULL"); |
300 CND_PRECONDITION(query != NULL, "query is NULL"); |
308 CND_PRECONDITION(query != NULL, "query is NULL"); |
|
309 |
|
310 |
|
311 |
301 |
312 |
302 BitSet* bits = NULL; |
313 BitSet* bits = NULL; |
303 SimpleFilteredCollector* fc = NULL; |
314 SimpleFilteredCollector* fc = NULL; |
304 |
315 |
305 if (filter != NULL){ |
316 if (filter != NULL){ |