34 { |
34 { |
35 ; |
35 ; |
36 } |
36 } |
37 |
37 |
38 |
38 |
39 void HitsBase::destroyWrappers() |
39 void HitsBase::destroyWrappers(int32_t index) |
40 { |
40 { |
41 WrapperMap::iterator |
41 WrapperMap::iterator |
42 i = wrappers_.begin(), |
42 i = wrappers_.begin(); |
43 end = wrappers_.end(); |
43 |
44 |
44 if (index == -1) { |
45 for (; i != end; ++i) |
45 for (; i != wrappers_.end(); ++i) |
46 { |
46 { |
47 delete i->second; |
47 delete i->second; |
48 } |
48 wrappers_.clear(); |
49 |
49 } |
50 wrappers_.clear(); |
50 } else { |
|
51 for (; i != wrappers_.find(index); ++i) |
|
52 { |
|
53 delete i->second; |
|
54 |
|
55 } |
|
56 wrappers_.erase(wrappers_.begin(),wrappers_.find(index)); |
|
57 } |
|
58 |
|
59 |
51 } |
60 } |
52 |
61 |
53 |
62 |
54 HitsBase::HitsBase(bool docsOwnedByClucene) |
63 HitsBase::HitsBase(bool docsOwnedByClucene) |
55 : docsOwnedByClucene_(docsOwnedByClucene) |
64 : docsOwnedByClucene_(docsOwnedByClucene) |
59 |
68 |
60 |
69 |
61 void HitsBase::wrapDocument(int32_t index, |
70 void HitsBase::wrapDocument(int32_t index, |
62 lucene::document::Document * doc) |
71 lucene::document::Document * doc) |
63 { |
72 { |
64 if (wrappers_.find(index) != wrappers_.end()) |
73 // if (wrappers_.find(index) != wrappers_.end()) |
65 { |
74 // { |
66 delete wrappers_[index]; |
75 // delete wrappers_[index]; |
67 wrappers_[index] = NULL; |
76 // wrappers_[index] = NULL; |
68 } |
77 // } |
69 |
78 // |
70 Cpix::Document |
79 // Cpix::Document |
71 * cpixDoc = new Cpix::Document(doc, |
80 // * cpixDoc = new Cpix::Document(doc, |
72 docsOwnedByClucene_); |
81 // docsOwnedByClucene_); |
73 wrappers_[index] = cpixDoc; |
82 // wrappers_[index] = cpixDoc; |
|
83 |
|
84 if (wrappers_.find(index) == wrappers_.end()) |
|
85 { |
|
86 Cpix::Document |
|
87 * cpixDoc = new Cpix::Document(doc, |
|
88 docsOwnedByClucene_); |
|
89 wrappers_[index] = cpixDoc; |
|
90 } |
|
91 |
|
92 |
74 } |
93 } |
75 |
94 |
76 |
95 |
77 Cpix::Document * HitsBase::getDocument(int32_t index) |
96 Cpix::Document * HitsBase::getDocument(int32_t index) |
78 { |
97 { |
87 rv = wrappers_[index]; |
106 rv = wrappers_[index]; |
88 |
107 |
89 return rv; |
108 return rv; |
90 } |
109 } |
91 |
110 |
92 |
111 int HitsBase::resetDocumentCache(int32_t index, int32_t count) |
|
112 { |
|
113 int32_t reqCount = index + count; |
|
114 int rv = 0; |
|
115 int i = (wrappers_.begin()->first)+ (int32_t) wrappers_.size(); |
|
116 if ((i < reqCount) || (index < wrappers_.begin()->first)) |
|
117 { |
|
118 getDocument_(index); |
|
119 |
|
120 } |
|
121 rv = (int32_t) wrappers_.size(); |
|
122 return rv; |
|
123 } |
93 |
124 |
94 /** |
125 /** |
95 * Class ClhDocumentConsumer |
126 * Class ClhDocumentConsumer |
96 */ |
127 */ |
97 int32_t ClhDocumentConsumer::beginIndex() const |
128 int32_t ClhDocumentConsumer::beginIndex() const |
142 THROW_CPIXEXC("Not a valid hit doc: %d (hits length is %d)", |
173 THROW_CPIXEXC("Not a valid hit doc: %d (hits length is %d)", |
143 index, |
174 index, |
144 clHits_.length()); |
175 clHits_.length()); |
145 } |
176 } |
146 |
177 |
147 beginIndex_ = index - (index % pageSize_); |
178 //beginIndex_ = index - (index % pageSize_); |
|
179 beginIndex_ = index; |
148 endIndex_ = beginIndex_ + pageSize_; |
180 endIndex_ = beginIndex_ + pageSize_; |
149 |
181 |
150 endIndex_ = std::min(clHits_.length(), |
182 endIndex_ = std::min(clHits_.length(), |
151 endIndex_); |
183 endIndex_); |
152 |
184 |
232 LuceneHits::~LuceneHits() |
264 LuceneHits::~LuceneHits() |
233 { |
265 { |
234 delete hits_; |
266 delete hits_; |
235 hits_ = 0; |
267 hits_ = 0; |
236 |
268 |
237 destroyWrappers(); |
269 destroyWrappers(0); |
238 |
270 |
239 delete docConsumer_; |
271 delete docConsumer_; |
240 |
272 |
241 IdxDbMgr::instance()->releaseHndl(idxDb_); |
273 IdxDbMgr::instance()->releaseHndl(idxDb_); |
242 } |
274 } |
243 |
275 |
244 |
276 |
245 void LuceneHits::getDocument_(int32_t index) |
277 void LuceneHits::getDocument_(int32_t index) |
246 { |
278 { |
247 // check if we have tried to fetch it before and failed |
279 // check if we have tried to fetch it before and failed |
248 docConsumer_->throwIfFailedDocIndex(index); |
280 //docConsumer_->throwIfFailedDocIndex(index); |
249 |
281 |
250 // common usage pattern is to enumerate hits, never to access |
282 // common usage pattern is to enumerate hits, never to access |
251 // them at true random manner. That means that we never need |
283 // them at true random manner. That means that we never need |
252 // wrappers for more than the current page - ie when about to |
284 // wrappers for more than the current page - ie when about to |
253 // fetch the next page we can discard all other wrapped |
285 // fetch the next page we can discard all other wrapped |
254 // documents. Merely an memory consumption optimization |
286 // documents. Merely an memory consumption optimization |
255 // measure, can be commented out. |
287 // measure, can be commented out. |
256 destroyWrappers(); |
288 destroyWrappers(index); |
257 |
289 |
258 // if we get here, then it means we don't have the page of hit |
290 // if we get here, then it means we don't have the page of hit |
259 // docs we need, but it may still throw if the hits is an |
291 // docs we need, but it may still throw if the hits is an |
260 // empty object or the hits itself was NULL |
292 // empty object or the hits itself was NULL |
261 docConsumer_->setPageBoundaryForIndex(index); |
293 docConsumer_->setPageBoundaryForIndex(index); |