Index any PDFs that are attached. Basically it turns the PDF into text and adds it the same way as a note's body
| 234 | // Index any PDFs that are attached. Basically it turns the PDF into text and adds it the same |
| 235 | // way as a note's body |
| 236 | void NoteIndexer::indexPdf(qint32 reslid) { |
| 237 | |
| 238 | QLOG_TRACE_IN(); |
| 239 | if (!global.indexPDFLocally) |
| 240 | return; |
| 241 | |
| 242 | NSqlQuery sql(db); |
| 243 | if (reslid <= 0) |
| 244 | return; |
| 245 | |
| 246 | QString file = global.fileManager.getDbaDirPath() + QString::number(reslid) +".pdf"; |
| 247 | |
| 248 | QString text = ""; |
| 249 | Poppler::Document *doc = Poppler::Document::load(file); |
| 250 | if (doc == NULL || doc->isEncrypted() || doc->isLocked()) |
| 251 | return; |
| 252 | |
| 253 | for (int i=0; i<doc->numPages(); i++) { |
| 254 | QRectF rect; |
| 255 | text = text + doc->page(i)->text(rect) + QString(" "); |
| 256 | } |
| 257 | |
| 258 | QLOG_TRACE() << "Adding PDF"; |
| 259 | // Add the new content. it is basically a text version of the note with a weight of 100. |
| 260 | sql.prepare("Insert into SearchIndex (lid, weight, source, content) values (:lid, :weight, :source, :content)"); |
| 261 | sql.bindValue(":lid", reslid); |
| 262 | sql.bindValue(":weight", 100); |
| 263 | sql.bindValue(":source", "recognition"); |
| 264 | if (!global.forceSearchLowerCase) |
| 265 | sql.bindValue(":content", text); |
| 266 | else |
| 267 | sql.bindValue(":content", text.toLower()); |
| 268 | sql.exec(); |
| 269 | QLOG_TRACE_OUT(); |
| 270 | } |
no test coverage detected