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 |
19 //#ifdef USE_HIGHLIGHTER |
|
20 //#include "CLucene/highlighter/QueryTermExtractor.h" |
|
21 //#include "CLucene/highlighter/QueryScorer.h" |
|
22 //#include "CLucene/highlighter/Highlighter.h" |
|
23 //#include "CLucene/highlighter/SimpleHTMLFormatter.h" |
|
24 //#include "CLucene/analysis/standard/StandardAnalyzer.h" |
|
25 //#include "CLucene/queryParser/QueryParser.h" |
|
26 //#endif |
20 CL_NS_USE(index) |
27 CL_NS_USE(index) |
21 CL_NS_USE(util) |
28 CL_NS_USE(util) |
22 CL_NS_USE(document) |
29 CL_NS_USE(document) |
23 |
30 |
24 CL_NS_DEF(search) |
31 CL_NS_DEF(search) |
110 |
117 |
111 CND_PRECONDITION(path != NULL, "path is NULL"); |
118 CND_PRECONDITION(path != NULL, "path is NULL"); |
112 |
119 |
113 reader = IndexReader::open(path); |
120 reader = IndexReader::open(path); |
114 readerOwner = true; |
121 readerOwner = true; |
|
122 //#ifdef USE_HIGHLIGHTER |
|
123 // rewrittenQuery = NULL; |
|
124 //#endif |
|
125 |
115 } |
126 } |
116 |
127 |
117 IndexSearcher::IndexSearcher(CL_NS(store)::Directory* directory){ |
128 IndexSearcher::IndexSearcher(CL_NS(store)::Directory* directory){ |
118 //Func - Constructor |
129 //Func - Constructor |
119 // Creates a searcher searching the index in the specified directory. */ |
130 // Creates a searcher searching the index in the specified directory. */ |
122 |
133 |
123 CND_PRECONDITION(directory != NULL, "directory is NULL"); |
134 CND_PRECONDITION(directory != NULL, "directory is NULL"); |
124 |
135 |
125 reader = IndexReader::open(directory); |
136 reader = IndexReader::open(directory); |
126 readerOwner = true; |
137 readerOwner = true; |
|
138 //#ifdef USE_HIGHLIGHTER |
|
139 // rewrittenQuery = NULL; |
|
140 //#endif |
|
141 |
127 } |
142 } |
128 |
143 |
129 IndexSearcher::IndexSearcher(IndexReader* r){ |
144 IndexSearcher::IndexSearcher(IndexReader* r){ |
130 //Func - Constructor |
145 //Func - Constructor |
131 // Creates a searcher searching the index with the provide IndexReader |
146 // Creates a searcher searching the index with the provide IndexReader |
132 //Pre - path != NULL |
147 //Pre - path != NULL |
133 //Post - The instance has been created |
148 //Post - The instance has been created |
134 |
149 |
135 reader = r; |
150 reader = r; |
136 readerOwner = false; |
151 readerOwner = false; |
|
152 //#ifdef USE_HIGHLIGHTER |
|
153 // rewrittenQuery = NULL; |
|
154 //#endif |
137 } |
155 } |
138 |
156 |
139 IndexSearcher::~IndexSearcher(){ |
157 IndexSearcher::~IndexSearcher(){ |
140 //Func - Destructor |
158 //Func - Destructor |
141 //Pre - true |
159 //Pre - true |
198 |
216 |
199 TopDocs* IndexSearcher::_search(Query* query, Filter* filter, const int32_t nDocs){ |
217 TopDocs* IndexSearcher::_search(Query* query, Filter* filter, const int32_t nDocs){ |
200 //Func - |
218 //Func - |
201 //Pre - reader != NULL |
219 //Pre - reader != NULL |
202 //Post - |
220 //Post - |
203 |
221 //#ifdef USE_HIGHLIGHTER |
|
222 // if(!rewrittenQuery) |
|
223 // { |
|
224 // rewrittenQuery = query->rewrite(reader); |
|
225 // } |
|
226 //#endif |
|
227 |
204 CND_PRECONDITION(reader != NULL, "reader is NULL"); |
228 CND_PRECONDITION(reader != NULL, "reader is NULL"); |
205 CND_PRECONDITION(query != NULL, "query is NULL"); |
229 CND_PRECONDITION(query != NULL, "query is NULL"); |
206 |
230 |
207 Weight* weight = query->weight(this); |
231 Weight* weight = query->weight(this); |
208 Scorer* scorer = weight->scorer(reader); |
232 Scorer* scorer = weight->scorer(reader); |
245 } |
269 } |
246 |
270 |
247 // inherit javadoc |
271 // inherit javadoc |
248 TopFieldDocs* IndexSearcher::_search(Query* query, Filter* filter, const int32_t nDocs, |
272 TopFieldDocs* IndexSearcher::_search(Query* query, Filter* filter, const int32_t nDocs, |
249 const Sort* sort) { |
273 const Sort* sort) { |
250 |
274 //#ifdef USE_HIGHLIGHTER |
|
275 // if(!rewrittenQuery) |
|
276 // { |
|
277 // rewrittenQuery = query->rewrite(reader); |
|
278 // } |
|
279 //#endif |
251 CND_PRECONDITION(reader != NULL, "reader is NULL"); |
280 CND_PRECONDITION(reader != NULL, "reader is NULL"); |
252 CND_PRECONDITION(query != NULL, "query is NULL"); |
281 CND_PRECONDITION(query != NULL, "query is NULL"); |
253 |
282 |
254 Weight* weight = query->weight(this); |
283 Weight* weight = query->weight(this); |
255 Scorer* scorer = weight->scorer(reader); |
284 Scorer* scorer = weight->scorer(reader); |
293 // as it skips non-high-scoring hits. |
322 // as it skips non-high-scoring hits. |
294 //Pre - query is a valid reference to a query |
323 //Pre - query is a valid reference to a query |
295 // filter may or may not be NULL |
324 // filter may or may not be NULL |
296 // results is a valid reference to a HitCollector and used to store the results |
325 // 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 |
326 //Post - filter if non-NULL, a bitset used to eliminate some documents |
298 |
327 //#ifdef USE_HIGHLIGHTER |
|
328 // if(!rewrittenQuery) |
|
329 // { |
|
330 // rewrittenQuery = query->rewrite(reader); |
|
331 // } |
|
332 //#endif |
299 CND_PRECONDITION(reader != NULL, "reader is NULL"); |
333 CND_PRECONDITION(reader != NULL, "reader is NULL"); |
300 CND_PRECONDITION(query != NULL, "query is NULL"); |
334 CND_PRECONDITION(query != NULL, "query is NULL"); |
301 |
335 |
302 BitSet* bits = NULL; |
336 BitSet* bits = NULL; |
303 SimpleFilteredCollector* fc = NULL; |
337 SimpleFilteredCollector* fc = NULL; |
336 } |
370 } |
337 last = query; |
371 last = query; |
338 } |
372 } |
339 return query; |
373 return query; |
340 } |
374 } |
341 |
375 //#ifdef USE_HIGHLIGHTER |
|
376 //Query* IndexSearcher::getrewritten(int32_t n, Query* original) |
|
377 // { |
|
378 // if(!rewrittenQuery) |
|
379 // { |
|
380 // rewrittenQuery = original->rewrite(reader); |
|
381 // } |
|
382 // return rewrittenQuery; |
|
383 // } |
|
384 //#endif |
342 void IndexSearcher::explain(Query* query, int32_t doc, Explanation* ret){ |
385 void IndexSearcher::explain(Query* query, int32_t doc, Explanation* ret){ |
343 Weight* weight = query->weight(this); |
386 Weight* weight = query->weight(this); |
344 weight->explain(reader, doc, ret); |
387 weight->explain(reader, doc, ret); |
345 |
388 |
346 Query* wq = weight->getQuery(); |
389 Query* wq = weight->getQuery(); |