Add order of best match results;Fix best match dissplay bug;

This commit is contained in:
jixiaoxu 2021-08-03 16:08:30 +08:00
parent 4d4bf111fb
commit ba0e71c23d
6 changed files with 26 additions and 15 deletions

View File

@ -45,6 +45,6 @@ void TitleLabel::paintEvent(QPaintEvent * event) {
p.setBrush(opt.palette.color(QPalette::Text));
p.setOpacity(0.04);
p.setPen(Qt::NoPen);
p.drawRoundedRect(rect, 0, 0);
p.drawRoundedRect(rect, 6, 6);
return QLabel::paintEvent(event);
}

View File

@ -19,6 +19,7 @@
*
*/
#include "best-list-model.h"
#include "search-plugin-manager.h"
using namespace Zeeker;
BestListModel::BestListModel(QObject *parent)
@ -109,13 +110,28 @@ void BestListModel::appendInfo(const QString &pluginId, const SearchPluginIface:
return;
}
qDebug()<<"plugin ID:"<<pluginId<<"Repalce result. name ="<<info.name;
this->beginResetModel();
m_item->m_result_info_list.replace(m_plugin_id_list.lastIndexOf(pluginId), info);
this->endResetModel();
return;
}
this->beginResetModel();
qDebug()<<"plugin ID:"<<pluginId<<"Got a result. name ="<<info.name;
m_plugin_id_list.append(pluginId);
m_item->m_result_info_list.append(info);
QVector<SearchPluginIface::ResultInfo> result_info_list_tmp;
QVector<QString> plugin_id_list_tmp;
QStringList plugin_order = SearchPluginManager::getInstance()->getPluginIds();
Q_FOREACH (QString plugin, plugin_order) {
if (m_plugin_id_list.contains(plugin)) {
result_info_list_tmp.append(m_item->m_result_info_list.at(m_plugin_id_list.lastIndexOf(plugin)));
plugin_id_list_tmp.append(plugin);
}
}
m_item->m_result_info_list.clear();
m_item->m_result_info_list.swap(result_info_list_tmp);
m_plugin_id_list.clear();
m_plugin_id_list.swap(plugin_id_list_tmp);
this->endResetModel();
Q_EMIT this->itemListChanged(m_item->m_result_info_list.length());
@ -127,8 +143,8 @@ void BestListModel::startSearch(const QString &keyword)
this->beginResetModel();
m_plugin_id_list.clear();
m_item->m_result_info_list.clear();
//Q_EMIT this->itemListChanged(m_item->m_result_info_list.length());
this->endResetModel();
Q_EMIT this->itemListChanged(m_item->m_result_info_list.length());
}
}

View File

@ -77,7 +77,7 @@ QVariant SearchResultModel::data(const QModelIndex &index, int role) const
void SearchResultModel::appendInfo(const SearchPluginIface::ResultInfo &info)
{
this->beginResetModel();
qDebug()<<"Got a result. name ="<<info.name;
//qDebug()<<"Got a result. name ="<<info.name;
m_item->m_result_info_list.append(info);
this->endResetModel();
Q_EMIT this->itemListChanged(m_item->m_result_info_list.length());

View File

@ -222,7 +222,7 @@ int FileSearch::getResult(Xapian::MSet &result) {
}
}
// searchResult.append(path);
qDebug() << "doc=" << path << ",weight=" << docScoreWeight << ",percent=" << docScorePercent;
//qDebug() << "doc=" << path << ",weight=" << docScoreWeight << ",percent=" << docScorePercent;
}
// if(!pathTobeDelete->isEmpty())
// deleteAllIndex(pathTobeDelete)
@ -406,7 +406,7 @@ int FileContentSearch::getResult(Xapian::MSet &result, std::string &keyWord) {
return -1;
}
// searchResult.insert(path,snippets);
qDebug() << "path=" << path << ",weight=" << docScoreWeight << ",percent=" << docScorePercent;
//qDebug() << "path=" << path << ",weight=" << docScoreWeight << ",percent=" << docScorePercent;
}
// // if(!pathTobeDelete->isEmpty())
// // deleteAllIndex(pathTobeDelete)

View File

@ -23,6 +23,7 @@ bool SearchPluginManager::registerPlugin(Zeeker::SearchPluginIface *plugin)
return false;
}
m_map[plugin->name()] = plugin;
m_plugin_order[m_plugin_order.size()] = plugin->name();//按注册顺序绑定优先级
return true;
}
@ -37,8 +38,8 @@ SearchPluginManager *SearchPluginManager::getInstance()
const QStringList SearchPluginManager::getPluginIds()
{
QStringList list;
for (auto i = m_map.begin(); i != m_map.end(); i++) {
list.append((*i).first);
for (auto i = m_plugin_order.begin(); i != m_plugin_order.end(); i++) {
list.append(m_plugin_order[(*i).first]);//根据优先级返回plugin ID
}
return list;
}

View File

@ -6,13 +6,6 @@
namespace Zeeker {
struct cmpPluginId
{
bool operator ()(const QString& k1, const QString& k2){
return k1 > k2;
}
};
class SearchPluginManager : public QObject
{
Q_OBJECT
@ -26,7 +19,8 @@ public:
void close();
private:
std::map<QString, SearchPluginIface*, cmpPluginId> m_map;
std::map<QString, SearchPluginIface*> m_map;
std::map<int, QString> m_plugin_order;//绑定plugin ID和优先级
explicit SearchPluginManager(QObject *parent = nullptr);
~SearchPluginManager();