diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-07-30 14:59:29 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-07-30 15:07:13 +0200 |
commit | 824a59466eeb08327cd811493fc6f0aa90ea1e1d (patch) | |
tree | 1f2c135ce00a0c9cc7e3863f0d9ecd5b9730cd93 | |
parent | c397667ac4f41b2b5564e4661d9f9e16088527c5 (diff) | |
download | sink-824a59466eeb08327cd811493fc6f0aa90ea1e1d.tar.gz sink-824a59466eeb08327cd811493fc6f0aa90ea1e1d.zip |
An adaptive query limit and a warning if we exceed it
-rw-r--r-- | common/fulltextindex.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/common/fulltextindex.cpp b/common/fulltextindex.cpp index abe29f5..e57a562 100644 --- a/common/fulltextindex.cpp +++ b/common/fulltextindex.cpp | |||
@@ -170,9 +170,24 @@ QVector<QByteArray> FulltextIndex::lookup(const QString &searchTerm) | |||
170 | Xapian::Enquire enquire(*mDb); | 170 | Xapian::Enquire enquire(*mDb); |
171 | enquire.set_query(query); | 171 | enquire.set_query(query); |
172 | 172 | ||
173 | const auto limit = searchTerm.size() <= 4 ? 1000 : 10000; | 173 | const auto limit = [&] { |
174 | switch (searchTerm.size()) { | ||
175 | case 1: | ||
176 | case 2: | ||
177 | case 3: | ||
178 | return 500; | ||
179 | case 4: | ||
180 | return 5000; | ||
181 | default: | ||
182 | return 20000; | ||
183 | } | ||
184 | }(); | ||
174 | Xapian::MSet mset = enquire.get_mset(0, limit); | 185 | Xapian::MSet mset = enquire.get_mset(0, limit); |
175 | SinkTrace() << "Found " << mset.size() << " results, limited to " << limit; | 186 | SinkTrace() << "Found " << mset.size() << " results, limited to " << limit; |
187 | //Print a hint why a query could lack some expected results. | ||
188 | if (searchTerm.size() > 4 && mset.size() >= limit) { | ||
189 | SinkLog() << "Result set exceeding limit of " << limit << QString::fromStdString(query.get_description()); | ||
190 | } | ||
176 | for (Xapian::MSetIterator it = mset.begin(); it != mset.end(); it++) { | 191 | for (Xapian::MSetIterator it = mset.begin(); it != mset.end(); it++) { |
177 | auto doc = it.get_document(); | 192 | auto doc = it.get_document(); |
178 | const auto data = doc.get_value(0); | 193 | const auto data = doc.get_value(0); |