Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/querytest.cpp
Show First 20 Lines • Show All 112 Lines • ▼ Show 20 Line(s) | 112 | { | |||
---|---|---|---|---|---|
113 | Document doc; | 113 | Document doc; | ||
114 | doc.setUrl(QFile::encodeName(url)); | 114 | doc.setUrl(QFile::encodeName(url)); | ||
115 | 115 | | |||
116 | QString fileName = url.mid(url.lastIndexOf('/') + 1); | 116 | QString fileName = url.mid(url.lastIndexOf('/') + 1); | ||
117 | 117 | | |||
118 | TermGenerator tg(doc); | 118 | TermGenerator tg(doc); | ||
119 | tg.indexText(text); | 119 | tg.indexText(text); | ||
120 | tg.indexFileNameText(fileName); | 120 | tg.indexFileNameText(fileName); | ||
121 | tg.indexFileNameText(fileName, QByteArrayLiteral("F")); | | |||
122 | doc.setId(id); | 121 | doc.setId(id); | ||
123 | doc.setMTime(1); | 122 | doc.setMTime(1); | ||
124 | doc.setCTime(2); | 123 | doc.setCTime(2); | ||
125 | 124 | | |||
126 | tr->addDocument(doc); | 125 | tr->addDocument(doc); | ||
127 | } | 126 | } | ||
128 | 127 | | |||
129 | void renameDocument(Transaction* tr, quint64 id, const QString& newName) | 128 | void renameDocument(Transaction* tr, quint64 id, const QString& newName) | ||
130 | { | 129 | { | ||
131 | Document doc; | 130 | Document doc; | ||
132 | 131 | | |||
133 | TermGenerator tg(doc); | 132 | TermGenerator tg(doc); | ||
134 | tg.indexFileNameText(newName); | 133 | tg.indexFileNameText(newName); | ||
135 | tg.indexFileNameText(newName, QByteArrayLiteral("F")); | | |||
136 | doc.setId(id); | 134 | doc.setId(id); | ||
137 | 135 | | |||
138 | tr->replaceDocument(doc, FileNameTerms); | 136 | tr->replaceDocument(doc, FileNameTerms); | ||
139 | } | 137 | } | ||
140 | 138 | | |||
141 | void insertTagDocuments(); | 139 | void insertTagDocuments(); | ||
142 | void addTagDocument(Transaction* tr,const QStringList& tags, quint64 id, const QString& url) | 140 | void addTagDocument(Transaction* tr,const QStringList& tags, quint64 id, const QString& url) | ||
143 | { | 141 | { | ||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | 238 | { | |||
244 | QTest::addColumn<QString>("failReason"); | 242 | QTest::addColumn<QString>("failReason"); | ||
245 | 243 | | |||
246 | auto addRow = [](const char* name, const QByteArrayList& phrase, | 244 | auto addRow = [](const char* name, const QByteArrayList& phrase, | ||
247 | const QVector<quint64> contentMatches, | 245 | const QVector<quint64> contentMatches, | ||
248 | const QVector<quint64> filenameMatches, | 246 | const QVector<quint64> filenameMatches, | ||
249 | const QString& failureReason) | 247 | const QString& failureReason) | ||
250 | { QTest::addRow("%s", name) << phrase << contentMatches << filenameMatches << failureReason; }; | 248 | { QTest::addRow("%s", name) << phrase << contentMatches << filenameMatches << failureReason; }; | ||
251 | 249 | | |||
250 | // Content matches | ||||
252 | addRow("Crazy dog", {"crazy", "dog"}, SortedIdVector{ m_id1 }, {}, ""); | 251 | addRow("Crazy dog", {"crazy", "dog"}, SortedIdVector{ m_id1 }, {}, ""); | ||
253 | addRow("Lazy dog", {"lazy", "dog"}, SortedIdVector{ m_id7 }, {}, ""); | 252 | addRow("Lazy dog", {"lazy", "dog"}, SortedIdVector{ m_id7 }, {}, ""); | ||
254 | addRow("Brown fox", {"brown", "fox"}, SortedIdVector{ m_id1, m_id7, m_id8 }, {}, ""); | 253 | addRow("Brown fox", {"brown", "fox"}, SortedIdVector{ m_id1, m_id7, m_id8 }, {}, ""); | ||
255 | addRow("Crazy dog file 1", {"file1"}, SortedIdVector{ m_id1 }, SortedIdVector{ m_id1 }, ""); | 254 | addRow("Dog", {"dog"}, SortedIdVector{ m_id1, m_id7, m_id8 }, {}, ""); | ||
256 | addRow("Crazy dog file 2", {"file1", "txt"}, SortedIdVector{ m_id1 }, SortedIdVector{ m_id1 }, ""); | 255 | // Filename matches | ||
257 | addRow("Lazy dog file 1", {"file7"}, SortedIdVector{ m_id7 }, SortedIdVector{ m_id7 }, ""); | 256 | addRow("Crazy dog file 1", {"file1"}, {}, SortedIdVector{ m_id1 }, ""); | ||
258 | addRow("Lazy dog file 2", {"file7", "lazy"}, SortedIdVector{ m_id7 }, SortedIdVector{ m_id7 }, "Content shadows filename"); | 257 | addRow("Crazy dog file 2", {"file1", "txt"}, {}, SortedIdVector{ m_id1 }, ""); | ||
259 | addRow("Lazy dog file 3", {"dog"}, SortedIdVector{ m_id1, m_id7, m_id8 }, SortedIdVector{ m_id8 }, "Filename shadows content"); | 258 | addRow("Lazy dog file 1", {"file7"}, {}, SortedIdVector{ m_id7 }, ""); | ||
259 | addRow("Lazy dog file 2", {"file7", "lazy"}, {}, SortedIdVector{ m_id7 }, ""); | ||||
260 | // Matches content and filename | ||||
261 | addRow("Lazy both", {"lazy"}, { m_id7 }, { m_id7 }, ""); | ||||
262 | addRow("Easy both", {"easy"}, { m_id8 }, { m_id8 }, ""); | ||||
260 | } | 263 | } | ||
261 | 264 | | |||
262 | void QueryTest::testTermPhrase() | 265 | void QueryTest::testTermPhrase() | ||
263 | { | 266 | { | ||
264 | QFETCH(QByteArrayList, phrase); | 267 | QFETCH(QByteArrayList, phrase); | ||
265 | QFETCH(QVector<quint64>, contentMatches); | 268 | QFETCH(QVector<quint64>, contentMatches); | ||
266 | QFETCH(QVector<quint64>, filenameMatches); | 269 | QFETCH(QVector<quint64>, filenameMatches); | ||
267 | QFETCH(QString, failReason); | 270 | QFETCH(QString, failReason); | ||
268 | 271 | | |||
269 | QVector<EngineQuery> queries; | 272 | QVector<EngineQuery> queries; | ||
270 | for (const QByteArray& term : phrase) { | 273 | for (const QByteArray& term : phrase) { | ||
271 | queries << EngineQuery(term); | 274 | queries << EngineQuery(term); | ||
272 | } | 275 | } | ||
273 | EngineQuery q(queries, EngineQuery::Phrase); | 276 | EngineQuery q(queries, EngineQuery::Phrase); | ||
274 | 277 | | |||
275 | Transaction tr(db, Transaction::ReadOnly); | 278 | Transaction tr(db, Transaction::ReadOnly); | ||
276 | if (!failReason.isEmpty()) { | 279 | if (!failReason.isEmpty()) { | ||
277 | QEXPECT_FAIL("", qPrintable(failReason), Continue); | 280 | QEXPECT_FAIL("", qPrintable(failReason), Continue); | ||
278 | } | 281 | } | ||
279 | QCOMPARE(tr.exec(q), contentMatches); | 282 | QCOMPARE(tr.exec(q), contentMatches); | ||
283 | | ||||
284 | queries.clear(); | ||||
285 | const QByteArray fPrefix = QByteArrayLiteral("F"); | ||||
286 | for (QByteArray term : phrase) { | ||||
287 | term = fPrefix + term; | ||||
288 | queries << EngineQuery(term); | ||||
289 | } | ||||
290 | EngineQuery qf(queries, EngineQuery::Phrase); | ||||
291 | QCOMPARE(tr.exec(qf), filenameMatches); | ||||
280 | } | 292 | } | ||
281 | 293 | | |||
282 | void QueryTest::testTagTermAnd_data() | 294 | void QueryTest::testTagTermAnd_data() | ||
283 | { | 295 | { | ||
284 | QTest::addColumn<QByteArrayList>("terms"); | 296 | QTest::addColumn<QByteArrayList>("terms"); | ||
285 | QTest::addColumn<QVector<quint64>>("matchIds"); | 297 | QTest::addColumn<QVector<quint64>>("matchIds"); | ||
286 | 298 | | |||
287 | QTest::addRow("Simple match") << QByteArrayList({"one", "four"}) | 299 | QTest::addRow("Simple match") << QByteArrayList({"one", "four"}) | ||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |