From kde-commits Mon May 19 18:45:02 2008 From: Jos van den Oever Date: Mon, 19 May 2008 18:45:02 +0000 To: kde-commits Subject: kdesupport/strigi/src/luceneindexer Message-Id: <1211222702.891133.20110.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=121122272108991 SVN commit 809919 by vandenoever: When an empty query is sent, return all documents, since none are filtered out. M +51 -0 cluceneindexreader.cpp M +5 -0 cluceneindexreader.h --- trunk/kdesupport/strigi/src/luceneindexer/cluceneindexreader.cpp #809918:809919 @@ -384,6 +384,11 @@ int32_t CLuceneIndexReader::countHits(const Strigi::Query& q) { if (!checkReader()) return -1; + // if the query is empty, we return the number of files in the index + if (q.term().string().size() == 0 && q.subQueries().size() == 0) { + return countDocuments(); + } + Query* bq = p->createQuery(q); if (reader == 0) { return 0; @@ -475,10 +480,50 @@ return results; } void +CLuceneIndexReader::getDocuments(const std::vector& fullFields, + const std::vector& types, + std::vector >& result, int off, int max) { + int pos = 0; + int maxDoc = reader->maxDoc(); + for (int i=0; iisDeleted(pos)) pos++; + if (pos == maxDoc) return; + pos++; + } + if (max < 0) max = 0; + result.resize(max); + Document* d = new Document(); + for (int i = 0; i < max && pos < maxDoc; ++i) { + while (pos < maxDoc && reader->isDeleted(pos)) pos++; + d->clear(); + if (pos == maxDoc || !reader->document(pos++, d)) { + continue; + } + + vector& doc = result[i]; + doc.clear(); + doc.resize(fullFields.size()); + + DocumentFieldEnumeration* e = d->fields(); + while (e->hasMoreElements()) { + Field* field = e->nextElement(); + string name(wchartoutf8(field->name())); + for (uint j = 0; j < fullFields.size(); ++j) { + if (fullFields[j] == name) { + doc[j] = p->getFieldValue(field, types[j]); + } + } + } + _CLDELETE(e); + } + delete d; +} +void CLuceneIndexReader::getHits(const Strigi::Query& q, const std::vector& fields, const std::vector& types, std::vector >& result, int off, int max) { +cerr << "getHits " << off << " " << max << endl; result.clear(); if (!checkReader() || types.size() < fields.size()) { return; @@ -496,6 +541,12 @@ } } + // if the query is empty, we return the number of files in the index + if (q.term().string().size() == 0 && q.subQueries().size() == 0) { + getDocuments(fullFields, types, result, off, max); + return; + } + Query* bq = p->createQuery(q); IndexSearcher searcher(reader); Hits* hits = 0; --- trunk/kdesupport/strigi/src/luceneindexer/cluceneindexreader.h #809918:809919 @@ -75,6 +75,11 @@ uint32_t max, uint32_t offset); void getChildren(const std::string& parent, std::map& ); + + // implementation function + void getDocuments(const std::vector& fields, + const std::vector& types, + std::vector >& result, int off, int max); }; #endif