forked from openkylin/ukui-search
解决首次索引后,重启后无法搜索部分文件的问题
This commit is contained in:
parent
9678b6f6db
commit
8d83d2f828
|
@ -29,13 +29,12 @@ BasicIndexer::BasicIndexer(const QString& filePath): m_filePath(filePath)
|
|||
bool BasicIndexer::index()
|
||||
{
|
||||
QFileInfo info = QFileInfo(m_filePath);
|
||||
|
||||
//添加数据
|
||||
m_document.setData(m_filePath);
|
||||
//唯一term
|
||||
m_document.setUniqueTerm(FileUtils::makeDocUterm(m_filePath));
|
||||
//上层文件夹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-文件
|
||||
m_document.addValue(1, QString((info.isDir() && (!info.isSymLink())) ? "1" : "0"));
|
||||
//修改时间
|
||||
|
|
|
@ -51,7 +51,7 @@ bool fileContentIndexer::index()
|
|||
term.shrink_to_fit();
|
||||
|
||||
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(2, suffix);
|
||||
m_document.setIndexTime(info.lastModified().toString("yyyyMMddHHmmsszzz"));
|
||||
|
|
|
@ -141,7 +141,6 @@ void FirstRunIndexer::basicIndex()
|
|||
qDebug() << indexTimes.size() << "documents need remove.";
|
||||
for(std::string uniqueTerm : indexTimes.keys()) {
|
||||
basicDb.removeDocument(uniqueTerm);
|
||||
basicDb.setMetaData(uniqueTerm, "");
|
||||
}
|
||||
basicDb.commit();
|
||||
}
|
||||
|
@ -231,7 +230,6 @@ void FirstRunIndexer::contentIndex()
|
|||
qDebug() << indexTimes.size() << "documents need remove";
|
||||
for(std::string uniqueTerm : indexTimes.keys()) {
|
||||
contentDb.removeDocument(uniqueTerm);
|
||||
contentDb.setMetaData(uniqueTerm, "");
|
||||
}
|
||||
contentDb.commit();
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ FirstRunIndexer::Targets IndexScheduler::checkAndRebuild()
|
|||
&& m_config->isFileIndexEnable()) {
|
||||
qDebug() << "Content database need rebuild";
|
||||
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);
|
||||
return target;
|
||||
|
|
|
@ -45,6 +45,9 @@ void IndexUpdater::UpdateIndex()
|
|||
if(file.shouldRemoveIndex()) {
|
||||
qDebug() << "| remove:" <<file.path();
|
||||
basicDb.removeDocument(file.path());
|
||||
if(file.isDir()) {
|
||||
basicDb.removeChildrenDocument(file.path());
|
||||
}
|
||||
} else {
|
||||
qDebug() << "| index:" <<file.path();
|
||||
BasicIndexer indexer(file.path());
|
||||
|
@ -80,12 +83,12 @@ void IndexUpdater::UpdateIndex()
|
|||
if(file.shouldRemoveIndex()) {
|
||||
qDebug() << "| remove:" <<file.path();
|
||||
if(file.isDir()) {
|
||||
contentDb.removeDocument(file.path());
|
||||
contentDb.removeChildrenDocument(file.path());
|
||||
} else if(true == suffixMap[suffix]) {
|
||||
contentDb.removeDocument(file.path());
|
||||
}
|
||||
} 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());
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ bool WritableDatabase::open()
|
|||
}
|
||||
QDir database(m_path);
|
||||
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 {
|
||||
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)
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
void addDocument(const Document& doc);
|
||||
void removeDocument(const QString& path);
|
||||
void removeDocument(const std::string uniqueTerm);
|
||||
void removeChildrenDocument(const QString& path);
|
||||
void setMetaData(const QString& key, const QString& value);
|
||||
void setMetaData(const std::string& key, const std::string& value);
|
||||
const std::string getMetaData(const std::string &key);
|
||||
|
|
Loading…
Reference in New Issue