forked from openkylin/ukui-search
解决首次索引后,重启后无法搜索部分文件的问题
This commit is contained in:
parent
f2236096b3
commit
15c4331da8
|
@ -29,13 +29,12 @@ BasicIndexer::BasicIndexer(const QString& filePath): m_filePath(filePath)
|
||||||
bool BasicIndexer::index()
|
bool BasicIndexer::index()
|
||||||
{
|
{
|
||||||
QFileInfo info = QFileInfo(m_filePath);
|
QFileInfo info = QFileInfo(m_filePath);
|
||||||
|
|
||||||
//添加数据
|
//添加数据
|
||||||
m_document.setData(m_filePath);
|
m_document.setData(m_filePath);
|
||||||
//唯一term
|
//唯一term
|
||||||
m_document.setUniqueTerm(FileUtils::makeDocUterm(m_filePath));
|
m_document.setUniqueTerm(FileUtils::makeDocUterm(m_filePath));
|
||||||
//上层文件夹term,用于在上层文件夹删除时删除自己
|
//上层文件夹term,用于在上层文件夹删除时删除自己
|
||||||
m_document.addTerm(FileUtils::makeDocUterm(m_filePath.section("/", 0, -2, QString::SectionIncludeLeadingSep)));
|
m_document.addTerm("PARENTTERM" + FileUtils::makeDocUterm(m_filePath.section("/", 0, -2, QString::SectionIncludeLeadingSep)));
|
||||||
//1-目录, 0-文件
|
//1-目录, 0-文件
|
||||||
m_document.addValue(1, QString((info.isDir() && (!info.isSymLink())) ? "1" : "0"));
|
m_document.addValue(1, QString((info.isDir() && (!info.isSymLink())) ? "1" : "0"));
|
||||||
//修改时间
|
//修改时间
|
||||||
|
|
|
@ -51,7 +51,7 @@ bool fileContentIndexer::index()
|
||||||
term.shrink_to_fit();
|
term.shrink_to_fit();
|
||||||
|
|
||||||
m_document.setUniqueTerm(FileUtils::makeDocUterm(m_filePath));
|
m_document.setUniqueTerm(FileUtils::makeDocUterm(m_filePath));
|
||||||
m_document.addTerm(FileUtils::makeDocUterm(m_filePath.section("/", 0, -2, QString::SectionIncludeLeadingSep)));
|
m_document.addTerm("PARENTTERM" + FileUtils::makeDocUterm(m_filePath.section("/", 0, -2, QString::SectionIncludeLeadingSep)));
|
||||||
m_document.addValue(1, m_filePath);
|
m_document.addValue(1, m_filePath);
|
||||||
m_document.addValue(2, suffix);
|
m_document.addValue(2, suffix);
|
||||||
m_document.setIndexTime(info.lastModified().toString("yyyyMMddHHmmsszzz"));
|
m_document.setIndexTime(info.lastModified().toString("yyyyMMddHHmmsszzz"));
|
||||||
|
|
|
@ -141,7 +141,6 @@ void FirstRunIndexer::basicIndex()
|
||||||
qDebug() << indexTimes.size() << "documents need remove.";
|
qDebug() << indexTimes.size() << "documents need remove.";
|
||||||
for(std::string uniqueTerm : indexTimes.keys()) {
|
for(std::string uniqueTerm : indexTimes.keys()) {
|
||||||
basicDb.removeDocument(uniqueTerm);
|
basicDb.removeDocument(uniqueTerm);
|
||||||
basicDb.setMetaData(uniqueTerm, "");
|
|
||||||
}
|
}
|
||||||
basicDb.commit();
|
basicDb.commit();
|
||||||
}
|
}
|
||||||
|
@ -231,7 +230,6 @@ void FirstRunIndexer::contentIndex()
|
||||||
qDebug() << indexTimes.size() << "documents need remove";
|
qDebug() << indexTimes.size() << "documents need remove";
|
||||||
for(std::string uniqueTerm : indexTimes.keys()) {
|
for(std::string uniqueTerm : indexTimes.keys()) {
|
||||||
contentDb.removeDocument(uniqueTerm);
|
contentDb.removeDocument(uniqueTerm);
|
||||||
contentDb.setMetaData(uniqueTerm, "");
|
|
||||||
}
|
}
|
||||||
contentDb.commit();
|
contentDb.commit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ FirstRunIndexer::Targets IndexScheduler::checkAndRebuild()
|
||||||
&& m_config->isFileIndexEnable()) {
|
&& m_config->isFileIndexEnable()) {
|
||||||
qDebug() << "Content database need rebuild";
|
qDebug() << "Content database need rebuild";
|
||||||
target |= FirstRunIndexer::Target::Content;
|
target |= FirstRunIndexer::Target::Content;
|
||||||
m_statusRecorder->setStatus(INDEX_DATABASE_STATE_KEY, IndexStatusRecorder::State::Initializing);
|
m_statusRecorder->setStatus(CONTENT_INDEX_DATABASE_STATE_KEY, IndexStatusRecorder::State::Initializing);
|
||||||
}
|
}
|
||||||
startIndexJob(mode, target);
|
startIndexJob(mode, target);
|
||||||
return target;
|
return target;
|
||||||
|
|
|
@ -45,6 +45,9 @@ void IndexUpdater::UpdateIndex()
|
||||||
if(file.shouldRemoveIndex()) {
|
if(file.shouldRemoveIndex()) {
|
||||||
qDebug() << "| remove:" <<file.path();
|
qDebug() << "| remove:" <<file.path();
|
||||||
basicDb.removeDocument(file.path());
|
basicDb.removeDocument(file.path());
|
||||||
|
if(file.isDir()) {
|
||||||
|
basicDb.removeChildrenDocument(file.path());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "| index:" <<file.path();
|
qDebug() << "| index:" <<file.path();
|
||||||
BasicIndexer indexer(file.path());
|
BasicIndexer indexer(file.path());
|
||||||
|
@ -80,12 +83,12 @@ void IndexUpdater::UpdateIndex()
|
||||||
if(file.shouldRemoveIndex()) {
|
if(file.shouldRemoveIndex()) {
|
||||||
qDebug() << "| remove:" <<file.path();
|
qDebug() << "| remove:" <<file.path();
|
||||||
if(file.isDir()) {
|
if(file.isDir()) {
|
||||||
contentDb.removeDocument(file.path());
|
contentDb.removeChildrenDocument(file.path());
|
||||||
} else if(true == suffixMap[suffix]) {
|
} else if(true == suffixMap[suffix]) {
|
||||||
contentDb.removeDocument(file.path());
|
contentDb.removeDocument(file.path());
|
||||||
}
|
}
|
||||||
} else if(true == suffixMap[suffix] && !file.isDir()) {
|
} else if(true == suffixMap[suffix] && !file.isDir()) {
|
||||||
if(FileUtils::isEncrypedOrUnsupport(file.path(), suffix)) {
|
if(FileUtils::isEncrypedOrUnsupport(file.path(), suffix) && file.isModified()) {
|
||||||
contentDb.removeDocument(file.path());
|
contentDb.removeDocument(file.path());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ bool WritableDatabase::open()
|
||||||
}
|
}
|
||||||
QDir database(m_path);
|
QDir database(m_path);
|
||||||
if(!database.exists()) {
|
if(!database.exists()) {
|
||||||
qDebug() << "Create basic writable database" << m_path<< database.mkpath(m_path);
|
qDebug() << "Create writable database" << m_path<< database.mkpath(m_path);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
m_xpDatabase = new Xapian::WritableDatabase(m_path.toStdString(), Xapian::DB_CREATE_OR_OPEN);
|
m_xpDatabase = new Xapian::WritableDatabase(m_path.toStdString(), Xapian::DB_CREATE_OR_OPEN);
|
||||||
|
@ -145,7 +145,13 @@ void WritableDatabase::removeDocument(const QString &path)
|
||||||
|
|
||||||
void WritableDatabase::removeDocument(const std::string uniqueTerm)
|
void WritableDatabase::removeDocument(const std::string uniqueTerm)
|
||||||
{
|
{
|
||||||
DATABASE_TRY(m_xpDatabase->delete_document(uniqueTerm);)
|
DATABASE_TRY(m_xpDatabase->delete_document(uniqueTerm);
|
||||||
|
m_xpDatabase->set_metadata(uniqueTerm, "");)
|
||||||
|
}
|
||||||
|
|
||||||
|
void WritableDatabase::removeChildrenDocument(const QString &path)
|
||||||
|
{
|
||||||
|
DATABASE_TRY(m_xpDatabase->delete_document("PARENTTERM" + FileUtils::makeDocUterm(path));)
|
||||||
}
|
}
|
||||||
|
|
||||||
void WritableDatabase::setMetaData(const QString &key, const QString &value)
|
void WritableDatabase::setMetaData(const QString &key, const QString &value)
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
void addDocument(const Document& doc);
|
void addDocument(const Document& doc);
|
||||||
void removeDocument(const QString& path);
|
void removeDocument(const QString& path);
|
||||||
void removeDocument(const std::string uniqueTerm);
|
void removeDocument(const std::string uniqueTerm);
|
||||||
|
void removeChildrenDocument(const QString& path);
|
||||||
void setMetaData(const QString& key, const QString& value);
|
void setMetaData(const QString& key, const QString& value);
|
||||||
void setMetaData(const std::string& key, const std::string& value);
|
void setMetaData(const std::string& key, const std::string& value);
|
||||||
const std::string getMetaData(const std::string &key);
|
const std::string getMetaData(const std::string &key);
|
||||||
|
|
Loading…
Reference in New Issue