[FIX] Block dir won't take effect issue;
Remove '\n' when get text content.
This commit is contained in:
parent
7fcf2b1a9b
commit
6158b46487
|
@ -472,22 +472,21 @@ QStringList FileUtils::findMultiToneWords(const QString& hanzi)
|
||||||
* @param path: abs path
|
* @param path: abs path
|
||||||
* @return docx to QString
|
* @return docx to QString
|
||||||
*/
|
*/
|
||||||
QString *FileUtils::getDocxTextContent(QString &path)
|
void FileUtils::getDocxTextContent(QString &path,QString &textcontent)
|
||||||
{
|
{
|
||||||
QFileInfo info = QFileInfo(path);
|
QFileInfo info = QFileInfo(path);
|
||||||
if(!info.exists()||info.isDir())
|
if(!info.exists()||info.isDir())
|
||||||
return nullptr;
|
return;
|
||||||
QuaZip file(path);
|
QuaZip file(path);
|
||||||
if(!file.open(QuaZip::mdUnzip))
|
if(!file.open(QuaZip::mdUnzip))
|
||||||
return nullptr;
|
return;
|
||||||
|
|
||||||
if(!file.setCurrentFile("word/document.xml",QuaZip::csSensitive))
|
if(!file.setCurrentFile("word/document.xml",QuaZip::csSensitive))
|
||||||
return nullptr;
|
return;
|
||||||
QuaZipFile fileR(&file);
|
QuaZipFile fileR(&file);
|
||||||
|
|
||||||
fileR.open(QIODevice::ReadOnly); //读取方式打开
|
fileR.open(QIODevice::ReadOnly); //读取方式打开
|
||||||
|
|
||||||
QString *allText = new QString();
|
|
||||||
QDomDocument doc;
|
QDomDocument doc;
|
||||||
doc.setContent(fileR.readAll());
|
doc.setContent(fileR.readAll());
|
||||||
QDomElement first = doc.firstChildElement("w:document");
|
QDomElement first = doc.firstChildElement("w:document");
|
||||||
|
@ -498,19 +497,19 @@ QString *FileUtils::getDocxTextContent(QString &path)
|
||||||
while(!wr.isNull())
|
while(!wr.isNull())
|
||||||
{
|
{
|
||||||
QDomElement wt = wr.firstChildElement("w:t");
|
QDomElement wt = wr.firstChildElement("w:t");
|
||||||
allText->append(wt.text());
|
textcontent.append(wt.text().replace("\n",""));
|
||||||
wr = wr.nextSiblingElement();
|
wr = wr.nextSiblingElement();
|
||||||
}
|
}
|
||||||
first = first.nextSiblingElement();
|
first = first.nextSiblingElement();
|
||||||
}
|
}
|
||||||
return allText;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString *FileUtils::getTxtContent(QString &path)
|
void FileUtils::getTxtContent(QString &path, QString &textcontent)
|
||||||
{
|
{
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
|
if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
|
||||||
return nullptr;
|
return;
|
||||||
QString *allText = new QString(file.readAll());
|
textcontent = QString(file.readAll()).replace("\n","");
|
||||||
return allText;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,8 @@ public:
|
||||||
|
|
||||||
//parse text,docx.....
|
//parse text,docx.....
|
||||||
static QString getMimetype(QString &path, bool getsuffix = false);
|
static QString getMimetype(QString &path, bool getsuffix = false);
|
||||||
static QString *getDocxTextContent(QString &path);
|
static void getDocxTextContent(QString &path, QString &textcontent);
|
||||||
static QString *getTxtContent(QString &path);
|
static void getTxtContent(QString &path, QString &textcontent);
|
||||||
static size_t _max_index_count;
|
static size_t _max_index_count;
|
||||||
static size_t _current_index_count;
|
static size_t _current_index_count;
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
m_settings = new QSettings("org.ukui", "ukui-search", this);
|
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 = new QSettings("org.ukui","ukui-search-block-dirs",this);
|
||||||
|
m_block_dirs_settings->setIniCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
this->forceSync();
|
this->forceSync();
|
||||||
//the default number of transparency in mainwindow is 0.7
|
//the default number of transparency in mainwindow is 0.7
|
||||||
//if someone changes the num in mainwindow, here should be modified too
|
//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)
|
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)
|
if(remove)
|
||||||
{
|
{
|
||||||
m_block_dirs_settings->remove(pathKey);
|
m_block_dirs_settings->remove(path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//why QSetting's key can't start with "/"??
|
||||||
|
QString pathKey = path.right(path.length()-1);
|
||||||
|
|
||||||
QStringList blockDirs = m_block_dirs_settings->allKeys();
|
QStringList blockDirs = m_block_dirs_settings->allKeys();
|
||||||
for(QString i:blockDirs)
|
for(QString i:blockDirs)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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);
|
QString type =FileUtils::getMimetype(path,true);
|
||||||
if(type == "application/zip")
|
if(type == "application/zip")
|
||||||
return FileUtils::getDocxTextContent(path);
|
FileUtils::getDocxTextContent(path,textContent);
|
||||||
else if(type == "text/plain")
|
else if(type == "text/plain")
|
||||||
return FileUtils::getTxtContent(path);
|
FileUtils::getTxtContent(path,textContent);
|
||||||
|
|
||||||
return new QString();
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ class FileReader : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit FileReader(QObject *parent = nullptr);
|
explicit FileReader(QObject *parent = nullptr);
|
||||||
static QString* getTextContent(QString path);
|
static void getTextContent(QString path, QString &textContent);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -354,7 +354,7 @@ bool FileSearcher::isBlocked(QString &path)
|
||||||
QStringList blockList = GlobalSettings::getInstance()->getBlockDirs();
|
QStringList blockList = GlobalSettings::getInstance()->getBlockDirs();
|
||||||
for(QString i :blockList)
|
for(QString i :blockList)
|
||||||
{
|
{
|
||||||
if(path.startsWith(i))
|
if(path.startsWith(i.prepend("/")))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -79,7 +79,7 @@ void FirstIndex::run(){
|
||||||
//why???????????????????????????????????????????????????????????????
|
//why???????????????????????????????????????????????????????????????
|
||||||
//why not quit?
|
//why not quit?
|
||||||
// this->quit();
|
// this->quit();
|
||||||
exit(0);
|
return;
|
||||||
// return;
|
// return;
|
||||||
// this->wait();
|
// this->wait();
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ IndexGenerator::~IndexGenerator()
|
||||||
GlobalSettings::getInstance()->setValue(INDEX_GENERATOR_NORMAL_EXIT,"2");
|
GlobalSettings::getInstance()->setValue(INDEX_GENERATOR_NORMAL_EXIT,"2");
|
||||||
|
|
||||||
qDebug() << "QThread::currentThreadId()" << QThread::currentThreadId();
|
qDebug() << "QThread::currentThreadId()" << QThread::currentThreadId();
|
||||||
qDebug() << "~IndexGenerator 22222222222222222222";
|
qDebug() << "~IndexGenerator end";
|
||||||
}
|
}
|
||||||
|
|
||||||
void IndexGenerator::insertIntoDatabase(Document doc)
|
void IndexGenerator::insertIntoDatabase(Document doc)
|
||||||
|
@ -240,11 +240,12 @@ Document IndexGenerator::GenerateDocument(const QVector<QString> &list)
|
||||||
Document IndexGenerator::GenerateContentDocument(const QString &path)
|
Document IndexGenerator::GenerateContentDocument(const QString &path)
|
||||||
{
|
{
|
||||||
// 构造文本索引的document
|
// 构造文本索引的document
|
||||||
QString *content = FileReader::getTextContent(path);
|
QString content;
|
||||||
|
FileReader::getTextContent(path,content);
|
||||||
QString uniqueterm = QString::fromStdString(FileUtils::makeDocUterm(path));
|
QString uniqueterm = QString::fromStdString(FileUtils::makeDocUterm(path));
|
||||||
QVector<SKeyWord> term = ChineseSegmentation::getInstance()->callSegement(content);
|
QVector<SKeyWord> term = ChineseSegmentation::getInstance()->callSegement(&content);
|
||||||
Document doc;
|
Document doc;
|
||||||
doc.setData(*content);
|
doc.setData(content);
|
||||||
doc.setUniqueTerm(uniqueterm);
|
doc.setUniqueTerm(uniqueterm);
|
||||||
doc.addValue(path);
|
doc.addValue(path);
|
||||||
for(int i = 0;i<term.size();++i)
|
for(int i = 0;i<term.size();++i)
|
||||||
|
@ -349,6 +350,7 @@ bool IndexGenerator::deleteAllIndex(QStringList *pathlist)
|
||||||
qDebug()<<"--delete start--";
|
qDebug()<<"--delete start--";
|
||||||
m_datebase_path->delete_document(uniqueterm);
|
m_datebase_path->delete_document(uniqueterm);
|
||||||
m_database_content->delete_document(uniqueterm);
|
m_database_content->delete_document(uniqueterm);
|
||||||
|
qDebug()<<"delete path"<<doc;
|
||||||
qDebug()<<"delete md5"<<QString::fromStdString(uniqueterm);
|
qDebug()<<"delete md5"<<QString::fromStdString(uniqueterm);
|
||||||
m_datebase_path->commit();
|
m_datebase_path->commit();
|
||||||
qDebug()<< "--delete finish--";
|
qDebug()<< "--delete finish--";
|
||||||
|
|
Loading…
Reference in New Issue