[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdesupport/strigi/src/luceneindexer
From: Jos van den Oever <jos () vandenoever ! info>
Date: 2008-05-19 18:45:02
Message-ID: 1211222702.891133.20110.nullmailer () svn ! kde ! org
[Download RAW message or body]
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<std::string>& fullFields,
+ const std::vector<Strigi::Variant::Type>& types,
+ std::vector<std::vector<Strigi::Variant> >& result, int off, int max) {
+ int pos = 0;
+ int maxDoc = reader->maxDoc();
+ for (int i=0; i<off; i++) {
+ while (pos < maxDoc && reader->isDeleted(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<Variant>& 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<std::string>& fields,
const std::vector<Strigi::Variant::Type>& types,
std::vector<std::vector<Strigi::Variant> >& 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<std::string, time_t>& );
+
+ // implementation function
+ void getDocuments(const std::vector<std::string>& fields,
+ const std::vector<Strigi::Variant::Type>& types,
+ std::vector<std::vector<Strigi::Variant> >& result, int off, int max);
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic