diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp index 8830f44..5e03d2d 100644 --- a/libsearch/file-utils.cpp +++ b/libsearch/file-utils.cpp @@ -472,22 +472,21 @@ QStringList FileUtils::findMultiToneWords(const QString& hanzi) * @param path: abs path * @return docx to QString */ -QString *FileUtils::getDocxTextContent(QString &path) +void FileUtils::getDocxTextContent(QString &path,QString &textcontent) { QFileInfo info = QFileInfo(path); if(!info.exists()||info.isDir()) - return nullptr; + return; QuaZip file(path); if(!file.open(QuaZip::mdUnzip)) - return nullptr; + return; if(!file.setCurrentFile("word/document.xml",QuaZip::csSensitive)) - return nullptr; + return; QuaZipFile fileR(&file); fileR.open(QIODevice::ReadOnly); //读取方式打开 - QString *allText = new QString(); QDomDocument doc; doc.setContent(fileR.readAll()); QDomElement first = doc.firstChildElement("w:document"); @@ -498,19 +497,19 @@ QString *FileUtils::getDocxTextContent(QString &path) while(!wr.isNull()) { QDomElement wt = wr.firstChildElement("w:t"); - allText->append(wt.text()); + textcontent.append(wt.text().replace("\n","")); wr = wr.nextSiblingElement(); } first = first.nextSiblingElement(); } - return allText; + return; } -QString *FileUtils::getTxtContent(QString &path) +void FileUtils::getTxtContent(QString &path, QString &textcontent) { QFile file(path); if(!file.open(QIODevice::ReadOnly|QIODevice::Text)) - return nullptr; - QString *allText = new QString(file.readAll()); - return allText; + return; + textcontent = QString(file.readAll()).replace("\n",""); + return; } diff --git a/libsearch/file-utils.h b/libsearch/file-utils.h index d9f707e..3e8b19f 100644 --- a/libsearch/file-utils.h +++ b/libsearch/file-utils.h @@ -27,8 +27,8 @@ public: //parse text,docx..... static QString getMimetype(QString &path, bool getsuffix = false); - static QString *getDocxTextContent(QString &path); - static QString *getTxtContent(QString &path); + static void getDocxTextContent(QString &path, QString &textcontent); + static void getTxtContent(QString &path, QString &textcontent); static size_t _max_index_count; static size_t _current_index_count; diff --git a/libsearch/global-settings.cpp b/libsearch/global-settings.cpp index 4660381..2e40935 100644 --- a/libsearch/global-settings.cpp +++ b/libsearch/global-settings.cpp @@ -17,6 +17,7 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) { m_settings = new QSettings("org.ukui", "ukui-search", this); m_block_dirs_settings = new QSettings("org.ukui","ukui-search-block-dirs",this); + m_block_dirs_settings->setIniCodec(QTextCodec::codecForName("UTF-8")); this->forceSync(); //the default number of transparency in mainwindow is 0.7 //if someone changes the num in mainwindow, here should be modified too @@ -82,13 +83,15 @@ void GlobalSettings::resetAll() bool GlobalSettings::setBlockDirs(const QString &path, QString &returnMessage, bool remove) { - //why QSetting's key can't start with "/"?? - QString pathKey = path.right(path.length()-1); if(remove) { - m_block_dirs_settings->remove(pathKey); + m_block_dirs_settings->remove(path); return true; } + + //why QSetting's key can't start with "/"?? + QString pathKey = path.right(path.length()-1); + QStringList blockDirs = m_block_dirs_settings->allKeys(); for(QString i:blockDirs) { diff --git a/libsearch/index/file-reader.cpp b/libsearch/index/file-reader.cpp index a31c6cb..a9a29c7 100644 --- a/libsearch/index/file-reader.cpp +++ b/libsearch/index/file-reader.cpp @@ -6,15 +6,15 @@ FileReader::FileReader(QObject *parent) : QObject(parent) } -QString *FileReader::getTextContent(QString path) +void FileReader::getTextContent(QString path, QString &textContent) { //获取所有文件内容 //先分类 QString type =FileUtils::getMimetype(path,true); if(type == "application/zip") - return FileUtils::getDocxTextContent(path); + FileUtils::getDocxTextContent(path,textContent); else if(type == "text/plain") - return FileUtils::getTxtContent(path); + FileUtils::getTxtContent(path,textContent); - return new QString(); + return; } diff --git a/libsearch/index/file-reader.h b/libsearch/index/file-reader.h index 69256c9..c0c977c 100644 --- a/libsearch/index/file-reader.h +++ b/libsearch/index/file-reader.h @@ -8,7 +8,7 @@ class FileReader : public QObject Q_OBJECT public: explicit FileReader(QObject *parent = nullptr); - static QString* getTextContent(QString path); + static void getTextContent(QString path, QString &textContent); }; diff --git a/libsearch/index/file-searcher.cpp b/libsearch/index/file-searcher.cpp index 1831639..d797d3d 100644 --- a/libsearch/index/file-searcher.cpp +++ b/libsearch/index/file-searcher.cpp @@ -354,7 +354,7 @@ bool FileSearcher::isBlocked(QString &path) QStringList blockList = GlobalSettings::getInstance()->getBlockDirs(); for(QString i :blockList) { - if(path.startsWith(i)) + if(path.startsWith(i.prepend("/"))) return true; } return false; diff --git a/libsearch/index/first-index.cpp b/libsearch/index/first-index.cpp index 0eaab8f..f2468ac 100644 --- a/libsearch/index/first-index.cpp +++ b/libsearch/index/first-index.cpp @@ -79,7 +79,7 @@ void FirstIndex::run(){ //why??????????????????????????????????????????????????????????????? //why not quit? // this->quit(); - exit(0); + return; // return; // this->wait(); } diff --git a/libsearch/index/index-generator.cpp b/libsearch/index/index-generator.cpp index a99bd04..de0a937 100644 --- a/libsearch/index/index-generator.cpp +++ b/libsearch/index/index-generator.cpp @@ -131,7 +131,7 @@ IndexGenerator::~IndexGenerator() GlobalSettings::getInstance()->setValue(INDEX_GENERATOR_NORMAL_EXIT,"2"); qDebug() << "QThread::currentThreadId()" << QThread::currentThreadId(); - qDebug() << "~IndexGenerator 22222222222222222222"; + qDebug() << "~IndexGenerator end"; } void IndexGenerator::insertIntoDatabase(Document doc) @@ -240,11 +240,12 @@ Document IndexGenerator::GenerateDocument(const QVector &list) Document IndexGenerator::GenerateContentDocument(const QString &path) { // 构造文本索引的document - QString *content = FileReader::getTextContent(path); + QString content; + FileReader::getTextContent(path,content); QString uniqueterm = QString::fromStdString(FileUtils::makeDocUterm(path)); - QVector term = ChineseSegmentation::getInstance()->callSegement(content); + QVector term = ChineseSegmentation::getInstance()->callSegement(&content); Document doc; - doc.setData(*content); + doc.setData(content); doc.setUniqueTerm(uniqueterm); doc.addValue(path); for(int i = 0;idelete_document(uniqueterm); m_database_content->delete_document(uniqueterm); + qDebug()<<"delete path"<commit(); qDebug()<< "--delete finish--";