diff --git a/index/document.cpp b/index/document.cpp index f6ea7aa..70d991b 100644 --- a/index/document.cpp +++ b/index/document.cpp @@ -11,9 +11,9 @@ Document::~Document() // if(m_document) // delete m_document; // if(m_index_text) -// delete m_index_text; +// delete m_index_text; // if(m_unique_term) -// delete m_unique_term; +// delete m_unique_term; } void Document::setData(QString data) diff --git a/index/file-searcher.cpp b/index/file-searcher.cpp new file mode 100644 index 0000000..0baaa47 --- /dev/null +++ b/index/file-searcher.cpp @@ -0,0 +1,81 @@ +#include "file-searcher.h" + +FileSearcher::FileSearcher(QObject *parent) : QObject(parent) +{ + +} + +void FileSearcher::onKeywordSearch(QString keyword) +{ + QStringList searchResult; + try + { + qDebug()<<"--search start--"; + + Xapian::Database db(INDEX_PATH); + Xapian::Enquire enquire(db); + Xapian::QueryParser qp; + qp.set_default_op(Xapian::Query::OP_PHRASE); + qp.set_database(db); + auto userInput = keyword; + + std::string queryStr = indexText.replace(""," ").toStdString(); +// std::string s =db.get_spelling_suggestion(queryStr,10); +// qDebug()<<"spelling_suggestion!"< v; + for(int i=0;iresult(searchResult); + return; + +} diff --git a/index/file-searcher.h b/index/file-searcher.h new file mode 100644 index 0000000..5a2c435 --- /dev/null +++ b/index/file-searcher.h @@ -0,0 +1,24 @@ +#ifndef FILESEARCHER_H +#define FILESEARCHER_H + +#include +#include +#define INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/index_data").toStdString() + + +class FileSearcher : public QObject +{ + Q_OBJECT +public: + explicit FileSearcher(QObject *parent = nullptr); + +public Q_SLOTS: + void onKeywordSearch(QString keyword); + +Q_SIGNALS: + void result(QStringList resultList); + + +}; + +#endif // FILESEARCHER_H diff --git a/index/index-generator.cpp b/index/index-generator.cpp index d886cf8..e3c2542 100644 --- a/index/index-generator.cpp +++ b/index/index-generator.cpp @@ -77,24 +77,25 @@ IndexGenerator::~IndexGenerator() void IndexGenerator::insertIntoDatabase(Document doc) { - qDebug()<< "--index start--"; +// qDebug()<< "--index start--"; Xapian::Document document = doc.getXapianDocument(); m_indexer->set_document(document); - qDebug()<index_text(i.toStdString()); } Xapian::docid innerId= m_datebase->replace_document(doc.getUniqueTerm(),document); - qDebug()<<"replace doc docid="<(innerId); - qDebug()<< "--index finish--"; +// qDebug()<<"replace doc docid="<(innerId); +// qDebug()<< "--index finish--"; return; } void IndexGenerator::HandlePathList(QList> *messageList) { qDebug()<<"Begin HandlePathList!"; + qDebug()<size(); // qDebug()< future = QtConcurrent::mapped(*messageList,&IndexGenerator::GenerateDocument); @@ -227,7 +228,7 @@ bool IndexGenerator::deleteAllIndex(QStringList *pathlist) for(int i = 0;isize();i++) { QString doc = list->at(i); - std::string uniqueterm = m_cryp->hash(doc.toUtf8(),QCryptographicHash::Md5).toStdString();; + std::string uniqueterm = FileUtils::makeDocUterm(doc); try { qDebug()<<"--delete start--"; diff --git a/index/index.pri b/index/index.pri index 11097a9..bab7f9c 100644 --- a/index/index.pri +++ b/index/index.pri @@ -9,7 +9,8 @@ HEADERS += \ $$PWD/messagelist-manager.h \ $$PWD/traverse_bfs.h \ $$PWD/messagelist-manager.h \ - $$PWD/text-content-indexer.h + $$PWD/text-content-indexer.h \ + $$PWD/file-searcher.h SOURCES += \ # $$PWD/chinesecharacterstopinyin.cpp \ @@ -20,5 +21,6 @@ SOURCES += \ $$PWD/messagelist-manager.cpp \ $$PWD/test-Inotify-Manager.cpp \ $$PWD/traverse_bfs.cpp \ - $$PWD/text-content-indexer.cpp + $$PWD/text-content-indexer.cpp \ + $$PWD/file-searcher.cpp