diff --git a/libsearch/index/chinesecharacterstopinyin.cpp b/libsearch/index/chinesecharacterstopinyin.cpp deleted file mode 100644 index abb7416..0000000 --- a/libsearch/index/chinesecharacterstopinyin.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "chinesecharacterstopinyin.h" - -chineseCharactersToPinyin::chineseCharactersToPinyin(QObject *parent) : QObject(parent) -{ - map = loadHanziTable("://index/pinyinWithoutTone.txt"); -} - - diff --git a/libsearch/index/chinesecharacterstopinyin.h b/libsearch/index/chinesecharacterstopinyin.h deleted file mode 100644 index d3e2c89..0000000 --- a/libsearch/index/chinesecharacterstopinyin.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef CHINESECHARACTERSTOPINYIN_H -#define CHINESECHARACTERSTOPINYIN_H - -#include -#include -#include - -class chineseCharactersToPinyin : public QObject -{ - Q_OBJECT -public: - explicit chineseCharactersToPinyin(QObject *parent = nullptr); - static QString find(const QString &hanzi) - { - static QMap map = loadHanziTable("://index/pinyinWithoutTone.txt"); -// static QMap map; - QString output; - QStringList stringList = hanzi.split(""); - - /* 遍历查找汉字-拼音对照表的内容并将汉字替换为拼音 */ - for (const QString &str : stringList) { - if (map.contains(str)) - output += map[str].first(); - else - output += str; - } - - return output; - } - -Q_SIGNALS: -private: - static QMap map; - /* 加载汉字对照表 */ - static QMap loadHanziTable(const QString &fileName) - { - QMap map; - QFile file(fileName); - if (!file.open(QFile::ReadOnly | QFile::Text)) { - qDebug("File: '%s' open failed!", file.fileName().toStdString().c_str()); - return map; - } - - /* 读取汉字对照表文件并转换为QMap存储 */ - while(!file.atEnd()) { - QString content = QString::fromUtf8(file.readLine()); - map[content.split(" ").last().trimmed()] = content.split(" ").first().split(","); - } - - file.close(); - - return map; - } -}; - -#endif // CHINESECHARACTERSTOPINYIN_H diff --git a/libsearch/index/index-generator.cpp b/libsearch/index/index-generator.cpp index c6ffd59..de5ce64 100644 --- a/libsearch/index/index-generator.cpp +++ b/libsearch/index/index-generator.cpp @@ -5,7 +5,6 @@ #include "chinese-segmentation.h" #include "file-utils.h" #include "index-generator.h" -#include "chinesecharacterstopinyin.h" #include "global-settings.h" #include diff --git a/libsearch/index/index.pri b/libsearch/index/index.pri index 2f14d4e..a8345be 100644 --- a/libsearch/index/index.pri +++ b/libsearch/index/index.pri @@ -1,30 +1,24 @@ INCLUDEPATH += $$PWD HEADERS += \ -# $$PWD/chinesecharacterstopinyin.h \ $$PWD/document.h \ $$PWD/filetypefilter.h \ $$PWD/file-reader.h \ $$PWD/first-index.h \ $$PWD/index-generator.h \ -# $$PWD/inotify-manager.h \ $$PWD/inotify-index.h \ $$PWD/traverse_bfs.h \ -# $$PWD/text-content-indexer.h \ $$PWD/file-searcher.h \ $$PWD/ukui-search-qdbus.h SOURCES += \ -# $$PWD/chinesecharacterstopinyin.cpp \ $$PWD/document.cpp \ $$PWD/filetypefilter.cpp \ $$PWD/file-reader.cpp \ $$PWD/first-index.cpp \ $$PWD/index-generator.cpp \ -# $$PWD/inotify-manager.cpp \ $$PWD/inotify-index.cpp \ $$PWD/traverse_bfs.cpp \ -# $$PWD/text-content-indexer.cpp \ $$PWD/file-searcher.cpp \ $$PWD/ukui-search-qdbus.cpp diff --git a/libsearch/index/inotify-manager.cpp b/libsearch/index/inotify-manager.cpp deleted file mode 100644 index 909afa5..0000000 --- a/libsearch/index/inotify-manager.cpp +++ /dev/null @@ -1,226 +0,0 @@ -#include "inotify-manager.h" -#include "index-generator.h" -#include "messagelist-manager.h" - -bool InotifyManager::Traverse_BFS(const QString& path, int autoSendMessageLength){ - qDebug() << "BFS start-----------------------------"; - this->mlm->SetAutoSendMessageLength(autoSendMessageLength); - QQueue bfs; - bfs.enqueue(path); - QFileInfoList list; - QDir dir; - dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - dir.setSorting(QDir::DirsFirst); - while (!bfs.empty()) { - dir.setPath(bfs.dequeue()); - list = dir.entryInfoList(); - for (auto i : list){ -// qDebug() << i.absoluteFilePath(); - if (i.isDir()){ - AddWatch(i.absoluteFilePath()); - bfs.enqueue(i.absoluteFilePath()); - } - else{ - this->mlm->AddMessage(i.absoluteFilePath()); - //continue; - } - } - } - this->mlm->SendMessage(); - qDebug() << "BFS end-----------------------------"; - return true; -} - - -//the DFS method is aborted -bool InotifyManager::Traverse_DFS(const QString& path, const bool& CREATORDELETE){ - - QDir dir(path); - if (!dir.exists()) { - return false; - } - dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - dir.setSorting(QDir::DirsFirst); - QFileInfoList list = dir.entryInfoList(); - int i = 0; - do { - if(list.size()==0){ - break; - } - QFileInfo fileInfo = list.at(i); - bool bisDir = fileInfo.isDir(); - if (fileInfo.fileName().at(0) != '.'){ - if (bisDir) { - // qDebug() << QString("Path: %0/%1") - // .arg(fileInfo.path()) - // .arg(fileInfo.fileName()); - qDebug() << "inotify-manager traverse: " << fileInfo.filePath(); - if (CREATORDELETE){ - AddWatch(fileInfo.filePath()); - } - Traverse_DFS(fileInfo.filePath(), CREATORDELETE); - if (!CREATORDELETE){ - RemoveWatch(fileInfo.filePath()); - } - } else { - // qDebug() << QString("File: %0/%1") - // .arg(fileInfo.path()) - // .arg(fileInfo.fileName()); - //IndexGenerator::getInstance()->creatAllIndex(new QStringList(fileInfo.filePath())); - - } - } - i++; - } while (i < list.size()); - return true; -} - -bool InotifyManager::AddWatch(const QString &path){ - //m_fd = inotify_init(); -// qDebug() << "m_fd: " <" <::Iterator i = currentPath.begin(); i != currentPath.end();){ - if (i.value().length() > path.length()){ - if (i.value().mid(0, path.length()) == path){ - qDebug() << i.value(); - /*--------------------------------*/ - //在此调用删除索引 - IndexGenerator::getInstance()->deleteAllIndex(new QStringList(path)); - /*--------------------------------*/ - currentPath.erase(i++); - } - else{ - i++; - } - } - else{ - i++; - } - } - qDebug() << path; - //这个貌似不用删,先mark一下 - //currentPath.remove(currentPath.key(path)); - return true; -} - -void InotifyManager::run(){ - - char * p; - char buf[BUF_LEN] __attribute__((aligned(8))); - - ssize_t numRead; - - for (;;) { /* Read events forever */ - numRead = read(m_fd, buf, BUF_LEN); - if (numRead == 0) { - qDebug() << "read() from inotify fd returned 0!"; - } - if (numRead == -1) { - qDebug() << "read"; - } - qDebug() << "Read " << numRead << " bytes from inotify fd"; - - /* Process all of the events in buffer returned by read() */ - - for (p = buf; p < buf + numRead;) { - struct inotify_event * event = reinterpret_cast(p); - if(event->name[0] != '.'){ -// if(true){ - //这个位运算不要在意,只是懒得把文件夹、文件和事件排列组合了,只是看一下事件的类型 - qDebug() << "Read Event: " << num2string[(event->mask & 0x0000ffff)] << currentPath[event->wd] << QString(event->name) << event->cookie << event->wd; - //num2string[event->mask & 0x0000ffff] - IndexGenerator::getInstance()->creatAllIndex(new QStringList(currentPath[event->wd] + event->name)); - - /*--------------------------------*/ - - //传创建或移动过来的文件路径 - if((event->mask & IN_CREATE) | (event->mask & IN_MOVED_TO)){ - //添加监视要先序遍历,先添加top节点 - if (event->mask & IN_ISDIR){ - AddWatch(currentPath[event->wd] + '/' + event->name); - Traverse_BFS(currentPath[event->wd] + '/' + event->name); - } - else { - //IndexGenerator::getInstance()->creatAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name)); - this->mlm->AddMessage(currentPath[event->wd] + '/' + event->name); - this->mlm->SendMessage(); - } - } - else if((event->mask & IN_DELETE) | (event->mask & IN_MOVED_FROM)){ - if (event->mask & IN_ISDIR){ - RemoveWatch(currentPath[event->wd] + '/' + event->name); - } - else { - //这里调用删除索引 - this->mlm->AddMessage(currentPath[event->wd] + '/' + event->name); - this->mlm->SendDeleteMessage(); -// IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name)); - } - } - /*--------------------------------*/ - } - p += sizeof(struct inotify_event) + event->len; - } - } -} - - -InotifyManager::InotifyManager() -{ - - m_fd = inotify_init(); - qDebug() << "m_fd----------->" <mlm = new MessageListManager(); - return; - -} diff --git a/libsearch/index/inotify-manager.h b/libsearch/index/inotify-manager.h deleted file mode 100644 index b50d4e8..0000000 --- a/libsearch/index/inotify-manager.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef INOTIFYMANAGER_H -#define INOTIFYMANAGER_H - -#include -#include -#include -#include -#include -#include -#include -#include "messagelist-manager.h" -//#define EVENT_NUM 12 -#define BUF_LEN 1024 - - -class InotifyManager : public QThread -{ - Q_OBJECT -public: - explicit InotifyManager(); - //the DFS method is aborted - bool Traverse_DFS(const QString&, const bool&);//true->create, false->delete - bool Traverse_BFS(const QString&, int autoSendMessageLength = 80000); - //typedef bool (*AddWatch)(const QString&); - //AddWatch cmp; - - bool AddWatch(const QString&); - bool AddWatchList(const QStringList&); - bool RemoveWatch(const QString&); - -protected: - void run() override; -private: - QString *m_watch_path; - int m_fd; - QMap currentPath; - QMap num2string; - MessageListManager* mlm; - -}; - -void testTraverse(void); - -#endif // INOTIFYMANAGER_H diff --git a/libsearch/index/text-content-indexer.cpp b/libsearch/index/text-content-indexer.cpp deleted file mode 100644 index b99ad34..0000000 --- a/libsearch/index/text-content-indexer.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "text-content-indexer.h" -#include -#include -#include -#include - -TextContentIndexer::TextContentIndexer(QObject *parent) : QObject(parent) -{ - -} - -void TextContentIndexer::creatContentdata() -{ - -} - -void TextContentIndexer::setFileList(QStringList *filelist) -{ - m_file_list = filelist; -} - -void TextContentIndexer::begin() -{ - -} - -bool TextContentIndexer::getPlaintextFileContent(QString path) -{ - QFile file(path); - if(!file.open(QIODevice::ReadOnly)) - return false; - - QTextStream *stream = new QTextStream(&file); - QString content = stream->readAll(); - qDebug()< -#include -#include - -class TextContentIndexer : public QObject -{ - Q_OBJECT -public: - explicit TextContentIndexer(QObject *parent = nullptr); - void setFileList(QStringList *filelist); - void begin(); - bool getPlaintextFileContent(QString path); -Q_SIGNALS: - bool finish(); -private: - void creatContentdata(); - QStringList *m_file_list; - Document *m_current_document; - - -Q_SIGNALS: - -}; - -#endif // TEXTCONTENTINDEXER_H