fix(search-interface):完善内容搜索接口
This commit is contained in:
parent
5b547a6699
commit
39e72434f2
|
@ -22,6 +22,7 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QMutexLocker>
|
||||||
|
|
||||||
static const QString INDEX_SETTINGS = QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-service.conf";
|
static const QString INDEX_SETTINGS = QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-service.conf";
|
||||||
static const QString CONTENT_INDEX_TARGET_TYPE = "contentIndexTarget";
|
static const QString CONTENT_INDEX_TARGET_TYPE = "contentIndexTarget";
|
||||||
|
@ -120,6 +121,7 @@ QStringList FileIndexerConfig::currentBlackListOfIndex()
|
||||||
|
|
||||||
bool FileIndexerConfig::isFileIndexEnable()
|
bool FileIndexerConfig::isFileIndexEnable()
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
if(m_gsettings) {
|
if(m_gsettings) {
|
||||||
if(m_gsettings->keys().contains(FILE_INDEX_ENABLE_KEY)) {
|
if(m_gsettings->keys().contains(FILE_INDEX_ENABLE_KEY)) {
|
||||||
return m_gsettings->get(FILE_INDEX_ENABLE_KEY).toBool();
|
return m_gsettings->get(FILE_INDEX_ENABLE_KEY).toBool();
|
||||||
|
@ -135,6 +137,7 @@ bool FileIndexerConfig::isFileIndexEnable()
|
||||||
|
|
||||||
bool FileIndexerConfig::isContentIndexEnable()
|
bool FileIndexerConfig::isContentIndexEnable()
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
if(m_gsettings) {
|
if(m_gsettings) {
|
||||||
if(m_gsettings->keys().contains(CONTENT_INDEX_ENABLE_KEY)) {
|
if(m_gsettings->keys().contains(CONTENT_INDEX_ENABLE_KEY)) {
|
||||||
return m_gsettings->get(CONTENT_INDEX_ENABLE_KEY).toBool();
|
return m_gsettings->get(CONTENT_INDEX_ENABLE_KEY).toBool();
|
||||||
|
@ -150,6 +153,7 @@ bool FileIndexerConfig::isContentIndexEnable()
|
||||||
|
|
||||||
bool FileIndexerConfig::isFuzzySearchEnable()
|
bool FileIndexerConfig::isFuzzySearchEnable()
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
if(m_gsettings) {
|
if(m_gsettings) {
|
||||||
if(m_gsettings->keys().contains(CONTENT_FUZZY_SEARCH_KEY)) {
|
if(m_gsettings->keys().contains(CONTENT_FUZZY_SEARCH_KEY)) {
|
||||||
return m_gsettings->get(CONTENT_FUZZY_SEARCH_KEY).toBool();
|
return m_gsettings->get(CONTENT_FUZZY_SEARCH_KEY).toBool();
|
||||||
|
@ -165,6 +169,7 @@ bool FileIndexerConfig::isFuzzySearchEnable()
|
||||||
|
|
||||||
bool FileIndexerConfig::isOCREnable()
|
bool FileIndexerConfig::isOCREnable()
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
if(m_gsettings) {
|
if(m_gsettings) {
|
||||||
if(m_gsettings->keys().contains(CONTENT_INDEX_ENABLE_OCR_KEY)) {
|
if(m_gsettings->keys().contains(CONTENT_INDEX_ENABLE_OCR_KEY)) {
|
||||||
return m_gsettings->get(CONTENT_INDEX_ENABLE_OCR_KEY).toBool();
|
return m_gsettings->get(CONTENT_INDEX_ENABLE_OCR_KEY).toBool();
|
||||||
|
@ -185,16 +190,19 @@ bool FileIndexerConfig::isMetaDataIndexEnable()
|
||||||
|
|
||||||
QMap<QString, bool> FileIndexerConfig::contentIndexTarget()
|
QMap<QString, bool> FileIndexerConfig::contentIndexTarget()
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
return m_targetFileTypeMap;
|
return m_targetFileTypeMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, bool> FileIndexerConfig::ocrContentIndexTarget()
|
QMap<QString, bool> FileIndexerConfig::ocrContentIndexTarget()
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
return m_targetPhotographTypeMap;
|
return m_targetPhotographTypeMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileIndexerConfig::sync()
|
void FileIndexerConfig::sync()
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
m_settings->sync();
|
m_settings->sync();
|
||||||
m_settings->beginGroup(CONTENT_INDEX_TARGET_TYPE);
|
m_settings->beginGroup(CONTENT_INDEX_TARGET_TYPE);
|
||||||
if(m_settings->allKeys().isEmpty()) {
|
if(m_settings->allKeys().isEmpty()) {
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QGSettings>
|
#include <QGSettings>
|
||||||
|
#include <QMutex>
|
||||||
#include "dir-watcher.h"
|
#include "dir-watcher.h"
|
||||||
namespace UkuiSearch{
|
namespace UkuiSearch{
|
||||||
|
|
||||||
|
@ -145,7 +146,7 @@ private:
|
||||||
DirWatcher *m_dirWatcher = nullptr;
|
DirWatcher *m_dirWatcher = nullptr;
|
||||||
QGSettings *m_gsettings = nullptr;
|
QGSettings *m_gsettings = nullptr;
|
||||||
QSettings *m_settings = nullptr;
|
QSettings *m_settings = nullptr;
|
||||||
|
QMutex m_mutex;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // FILEINDEXERCONFIG_H
|
#endif // FILEINDEXERCONFIG_H
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "result-item.h"
|
#include "result-item.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "file-utils.h"
|
#include "file-utils.h"
|
||||||
|
#include "file-indexer-config.h"
|
||||||
|
|
||||||
//Qt
|
//Qt
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
@ -79,7 +80,8 @@ void FileContentSearchTask::setEnable(bool enable)
|
||||||
|
|
||||||
bool FileContentSearchTask::isEnable()
|
bool FileContentSearchTask::isEnable()
|
||||||
{
|
{
|
||||||
return m_enable && IndexStatusRecorder::getInstance()->contentIndexDatabaseEnable();
|
int state = IndexStatusRecorder::getInstance()->getStatus(CONTENT_INDEX_DATABASE_STATE_KEY).toInt();
|
||||||
|
return m_enable && state == IndexStatusRecorder::State::Ready || state == IndexStatusRecorder::State::Updating;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FileContentSearchTask::getCustomSearchType()
|
QString FileContentSearchTask::getCustomSearchType()
|
||||||
|
@ -125,13 +127,12 @@ void FileContentSearchWorker::run()
|
||||||
dir = dir.mid(0, dir.length() - 1);
|
dir = dir.mid(0, dir.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO 指定黑名单
|
|
||||||
m_validDirectories.append(dir);
|
m_validDirectories.append(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool finished = true;
|
bool finished = true;
|
||||||
if (IndexStatusRecorder::getInstance()->contentIndexDatabaseEnable()) {
|
if (m_fileContentSearchTask->isEnable()) {
|
||||||
qDebug() << "content index ready";
|
qDebug() << "content index enable";
|
||||||
finished = execSearch();
|
finished = execSearch();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -155,20 +156,25 @@ bool FileContentSearchWorker::execSearch()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Xapian::Database db(CONTENT_INDEX_PATH.toStdString());
|
Xapian::Database db(CONTENT_INDEX_PATH.toStdString());
|
||||||
|
if(FileIndexerConfig::getInstance()->isOCREnable()) {
|
||||||
|
db.add_database(Xapian::Database(OCR_CONTENT_INDEX_PATH.toStdString()));
|
||||||
|
}
|
||||||
|
|
||||||
Xapian::Enquire enquire(db);
|
Xapian::Enquire enquire(db);
|
||||||
|
|
||||||
enquire.set_query(createQuery());
|
enquire.set_query(createQuery());
|
||||||
|
|
||||||
FileContentSearchFilter filter(this);
|
FileContentSearchFilter filter(this);
|
||||||
|
|
||||||
Xapian::MSet result = enquire.get_mset(0, m_searchController->maxResults(), 0, &filter);
|
Xapian::MSet result = enquire.get_mset(0, m_searchController->maxResults(), nullptr, &filter);
|
||||||
|
|
||||||
for (auto it = result.begin(); it != result.end(); ++it) {
|
for (auto it = result.begin(); it != result.end(); ++it) {
|
||||||
if (m_searchController->beginSearchIdCheck(m_currentSearchId)) {
|
if (m_searchController->beginSearchIdCheck(m_currentSearchId)) {
|
||||||
QString path = QString::fromStdString(it.get_document().get_value(CONTENT_DATABASE_PATH_SLOT));
|
QString path = QString::fromStdString(it.get_document().get_value(CONTENT_DATABASE_PATH_SLOT));
|
||||||
|
|
||||||
SearchResultProperties properties = m_searchController->getResultProperties(SearchProperty::SearchType::File);
|
SearchResultProperties properties = m_searchController->getResultProperties(SearchProperty::SearchType::FileContent);
|
||||||
ResultItem resultItem(m_currentSearchId);
|
ResultItem resultItem(m_currentSearchId);
|
||||||
|
resultItem.setItemKey(path);
|
||||||
|
|
||||||
if(properties.contains(SearchProperty::SearchResultProperty::FilePath)) {
|
if(properties.contains(SearchProperty::SearchResultProperty::FilePath)) {
|
||||||
resultItem.setValue(SearchProperty::SearchResultProperty::FilePath, path);
|
resultItem.setValue(SearchProperty::SearchResultProperty::FilePath, path);
|
||||||
|
@ -217,8 +223,14 @@ inline Xapian::Query FileContentSearchWorker::createQuery()
|
||||||
v.emplace_back(c.word);
|
v.emplace_back(c.word);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Xapian::Query query;
|
||||||
|
if(FileIndexerConfig::getInstance()->isFuzzySearchEnable()) {
|
||||||
|
query = Xapian::Query(Xapian::Query::OP_OR, v.begin(), v.end());
|
||||||
|
} else {
|
||||||
|
query = Xapian::Query(Xapian::Query::OP_AND, v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
return {Xapian::Query::OP_AND, v.begin(), v.end()};
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue