Reduced resource footprint and increased indexing time.

This commit is contained in:
MouseZhangZh 2021-02-27 10:51:19 +08:00
parent 95ae9a168e
commit 5466590bec
6 changed files with 41 additions and 18 deletions

View File

@ -57,10 +57,6 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
} }
} }
GlobalSettings::~GlobalSettings()
{
}
const QVariant GlobalSettings::getValue(const QString &key) const QVariant GlobalSettings::getValue(const QString &key)
{ {
return m_cache.value(key); return m_cache.value(key);

View File

@ -74,7 +74,7 @@ public Q_SLOTS:
private: private:
explicit GlobalSettings(QObject *parent = nullptr); explicit GlobalSettings(QObject *parent = nullptr);
~GlobalSettings(); ~GlobalSettings() = default;
QSettings* m_settings; QSettings* m_settings;
QGSettings* m_gsettings; QGSettings* m_gsettings;

View File

@ -83,6 +83,7 @@ void FirstIndex::DoSomething(const QFileInfo& fileInfo){
} }
void FirstIndex::run(){ void FirstIndex::run(){
QTime t1 = QTime::currentTime();
int fifo_fd; int fifo_fd;
char buffer[2]; char buffer[2];
@ -120,7 +121,9 @@ void FirstIndex::run(){
} }
} }
else{ else{
p_indexGenerator = IndexGenerator::getInstance(false,this); // p_indexGenerator = IndexGenerator::getInstance(false,this);
p_indexGenerator = IndexGenerator::getInstance(true,this);
} }
QSemaphore sem(5); QSemaphore sem(5);
QMutex mutex1, mutex2, mutex3; QMutex mutex1, mutex2, mutex3;
@ -134,21 +137,38 @@ void FirstIndex::run(){
this->setPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); this->setPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
this->Traverse(); this->Traverse();
FileUtils::_max_index_count = this->q_index->length(); FileUtils::_max_index_count = this->q_index->length();
qDebug()<<"max_index_count:"<<FileUtils::_max_index_count;
sem.release(5); sem.release(5);
}); });
QtConcurrent::run([&](){ QtConcurrent::run([&](){
sem.acquire(2); sem.acquire(2);
mutex2.unlock(); mutex2.unlock();
qDebug() << "index start;"; qDebug() << "index start;";
this->p_indexGenerator->creatAllIndex(this->q_index); QQueue<QVector<QString>>* tmp = new QQueue<QVector<QString>>();
while (!this->q_index->empty()) {
for (size_t i = 0; (i < 8192) && (!this->q_index->empty()); ++i){
tmp->enqueue(this->q_index->dequeue());
}
this->p_indexGenerator->creatAllIndex(tmp);
tmp->clear();
}
delete tmp;
qDebug() << "index end;"; qDebug() << "index end;";
sem.release(2); sem.release(2);
}); });
QtConcurrent::run([&](){ QtConcurrent::run([&](){
sem.acquire(2); sem.acquire(2);
mutex3.unlock(); mutex3.unlock();
qDebug() << "content index start;"; QQueue<QString>* tmp = new QQueue<QString>();;
this->p_indexGenerator->creatAllIndex(this->q_content_index); while (!this->q_content_index->empty()) {
// for (size_t i = 0; (i < this->u_send_length) && (!this->q_content_index->empty()); ++i){
for (size_t i = 0; (i < 30) && (!this->q_content_index->empty()); ++i){
tmp->enqueue(this->q_content_index->dequeue());
}
this->p_indexGenerator->creatAllIndex(tmp);
tmp->clear();
}
delete tmp;
qDebug() << "content index end;"; qDebug() << "content index end;";
sem.release(2); sem.release(2);
}); });
@ -190,6 +210,9 @@ void FirstIndex::run(){
qWarning("write error\n"); qWarning("write error\n");
} }
qDebug("write data ok!\n"); qDebug("write data ok!\n");
QTime t2 = QTime::currentTime();
qWarning() << t1;
qWarning() << t2;
return; return;

View File

@ -70,6 +70,9 @@ private:
// QString(".xls"), // QString(".xls"),
// QString(".xlsx"), // QString(".xlsx"),
QString(".txt")}; QString(".txt")};
//xapian will auto commit per 10,000 changes, donnot change it!!!
const size_t u_send_length = 8192;
}; };
#endif // FIRSTINDEX_H #endif // FIRSTINDEX_H

View File

@ -74,14 +74,14 @@ bool IndexGenerator::creatAllIndex(QQueue<QVector<QString> > *messageList)
// 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); // m_indexer.set_stemming_strategy(Xapian::TermGenerator::STEM_SOME);
int count =0; // int count =0;
for (auto i : *_doc_list_path){ for (auto i : *_doc_list_path){
insertIntoDatabase(i); insertIntoDatabase(i);
if(++count > 8999){ // if(++count > 8999){
count = 0; // count = 0;
m_database_path->commit(); // m_database_path->commit();
} // }
} }
m_database_path->commit(); m_database_path->commit();
} }
@ -148,10 +148,10 @@ IndexGenerator::IndexGenerator(bool rebuild, QObject *parent) : QObject(parent)
{ {
QDir database(QString::fromStdString(INDEX_PATH)); QDir database(QString::fromStdString(INDEX_PATH));
if(database.exists()) if(database.exists())
database.removeRecursively(); qDebug()<<"remove"<<database.removeRecursively();
database.setPath(QString::fromStdString(CONTENT_INDEX_PATH)); database.setPath(QString::fromStdString(CONTENT_INDEX_PATH));
if(database.exists()) if(database.exists())
database.removeRecursively(); qDebug()<<"remove"<<database.removeRecursively();
} }
m_database_path = new Xapian::WritableDatabase(INDEX_PATH, Xapian::DB_CREATE_OR_OPEN); m_database_path = new Xapian::WritableDatabase(INDEX_PATH, Xapian::DB_CREATE_OR_OPEN);
m_database_content = new Xapian::WritableDatabase(CONTENT_INDEX_PATH, Xapian::DB_CREATE_OR_OPEN); m_database_content = new Xapian::WritableDatabase(CONTENT_INDEX_PATH, Xapian::DB_CREATE_OR_OPEN);
@ -266,7 +266,8 @@ void IndexGenerator::HandlePathList(QQueue<QString> *messageList)
ChineseSegmentation::getInstance(); ChineseSegmentation::getInstance();
ConstructDocumentForContent *constructer; ConstructDocumentForContent *constructer;
QThreadPool pool; QThreadPool pool;
pool.setMaxThreadCount(((QThread::idealThreadCount() - 1) / 2) + 1); // pool.setMaxThreadCount(((QThread::idealThreadCount() - 1) / 2) + 1);
pool.setMaxThreadCount(1);
pool.setExpiryTimeout(100); pool.setExpiryTimeout(100);
while(!messageList->isEmpty()) while(!messageList->isEmpty())
{ {

View File

@ -402,7 +402,7 @@ fork:
int rc; int rc;
timeval* read_timeout = (timeval*)malloc(sizeof(timeval)); timeval* read_timeout = (timeval*)malloc(sizeof(timeval));
read_timeout->tv_sec = 60; read_timeout->tv_sec = 40;
read_timeout->tv_usec = 0; read_timeout->tv_usec = 0;
for(;;) for(;;)
{ {