diff --git a/index/index-generator.cpp b/index/index-generator.cpp index c2a88dc..6b96669 100644 --- a/index/index-generator.cpp +++ b/index/index-generator.cpp @@ -16,6 +16,11 @@ IndexGenerator *IndexGenerator::getInstance() return global_instance; } +bool IndexGenerator::setIndexdataPath() +{ + return true; +} + bool IndexGenerator::creatAllIndex(QStringList *pathlist) { HandlePathList(pathlist); @@ -23,7 +28,7 @@ bool IndexGenerator::creatAllIndex(QStringList *pathlist) { m_indexer = new Xapian::TermGenerator(); m_indexer->set_database(*m_datebase); - m_indexer->set_flags(Xapian::TermGenerator::FLAG_SPELLING); +// m_indexer->set_flags(Xapian::TermGenerator::FLAG_SPELLING); m_indexer->set_stemming_strategy(Xapian::TermGenerator::STEM_SOME); QMap::const_iterator i; @@ -33,7 +38,7 @@ bool IndexGenerator::creatAllIndex(QStringList *pathlist) { docStr = new QString(i.key()); indexStr = new QString(i.value()); - CreatIndex(indexStr,docStr); + insertIntoDatabase(indexStr,docStr); } m_datebase->commit(); } @@ -58,7 +63,7 @@ IndexGenerator::~IndexGenerator() { } -void IndexGenerator::CreatIndex(QString *indexText,QString *doc) +void IndexGenerator::insertIntoDatabase(QString *indexText,QString *doc) { qDebug()<< "--index start--"; m_docstr = doc->toStdString(); @@ -92,7 +97,8 @@ void IndexGenerator::HandlePathList(QStringList *pathlist) //提取文件名并用空格分割,同时去除'.' QString filename = info->fileName(); QString index_test = filename.replace(".","").replace(""," "); - index_test.simplified(); + +// index_text.simplified(); // qDebug()<<"index_test"<insert(info->absoluteFilePath(),index_test); // qDebug()<value(index_test); @@ -110,30 +116,46 @@ bool IndexGenerator::isIndexdataExist() } -void IndexGenerator::IndexSearch(QString *indexText) +QStringList IndexGenerator::IndexSearch(QString indexText) { + QStringList searchResult; try { qDebug()<<"--search start--"; - Xapian::Enquire enquire(*m_datebase); + Xapian::Database db(INDEX_PATH); + Xapian::Enquire enquire(db); Xapian::QueryParser qp; - qp.set_default_op(Xapian::Query::OP_NEAR); - qp.set_database(*m_datebase); + qp.set_default_op(Xapian::Query::OP_PHRASE); + qp.set_database(db); + auto userInput = indexText; - std::string queryStr = indexText->replace(""," ").toStdString(); + std::string queryStr = indexText.replace(""," ").toStdString(); // std::string s =db.get_spelling_suggestion(queryStr,10); // qDebug()<<"spelling_suggestion!"< v; + for(int i=0;isearchFinish(); - return; + return searchResult; } bool IndexGenerator::deleteAllIndex(QStringList *pathlist) diff --git a/index/index-generator.h b/index/index-generator.h index d15eb27..2dd4f54 100644 --- a/index/index-generator.h +++ b/index/index-generator.h @@ -5,7 +5,7 @@ #include #include -#include +#include #include class IndexGenerator : public QObject @@ -13,19 +13,21 @@ class IndexGenerator : public QObject Q_OBJECT public: static IndexGenerator *getInstance(); + bool setIndexdataPath(); bool isIndexdataExist(); + static QStringList IndexSearch(QString indexText); Q_SIGNALS: void transactionFinished(); void searchFinish(); public Q_SLOTS: bool creatAllIndex(QStringList *pathlist); bool deleteAllIndex(QStringList *pathlist); - void IndexSearch(QString *indexText); + private: explicit IndexGenerator(QObject *parent = nullptr); void HandlePathList(QStringList *pathlist); //add one data in database - void CreatIndex(QString *indexText,QString *doc); + void insertIntoDatabase(QString *indexText,QString *doc); ~IndexGenerator(); QMap *m_index_map; diff --git a/index/test-Inotify-Manager.cpp b/index/test-Inotify-Manager.cpp index ab5896b..c410576 100644 --- a/index/test-Inotify-Manager.cpp +++ b/index/test-Inotify-Manager.cpp @@ -1,30 +1,9 @@ -#include "mainwindow.h" +#include "src/mainwindow.h" #include "inotify-manager.h" #include #include void testTraverse(void){ - - -// QStringList qsl; -// for (int i = 0; i < 4000; i++){ -// qsl.append(QString("%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1%1").arg(i)); -// } - -// for (int i = 0; i < 4000; i++){ -// qDebug() << i << " " << qsl.at(i); -// if (qsl.at(i) != QString("%1").arg(i)){ -// qDebug() << "fuck stringlist"; -// } -// } - -// qDebug() << qsl.length(); -// qDebug() << "stringlist"; -// exit(0); - - - - QTime t1 = QTime::currentTime(); InotifyManager* im = new InotifyManager(); im->AddWatch("/home/zpf"); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 151f291..2730153 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -29,6 +29,9 @@ #include #include "kwindowsystem.h" +#include "file-utils.h" +#include "index-generator.h" +#include "inotify-manager.h" extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed); /** diff --git a/ukui-search.pro b/ukui-search.pro index 259a0e2..0830599 100644 --- a/ukui-search.pro +++ b/ukui-search.pro @@ -15,7 +15,7 @@ DEFINES += QT_DEPRECATED_WARNINGS # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -include(src/src.pri)) +include(src/src.pri) include(index/index.pri) include(model/model.pri) include(control/control.pri))