diff options
author | Yuri Gorshenin <y@maps.me> | 2017-05-02 11:31:43 +0300 |
---|---|---|
committer | Yuri Gorshenin <y@maps.me> | 2017-05-02 12:22:19 +0300 |
commit | 2a650a513212db0c95430c71b1cf72503ab7593d (patch) | |
tree | 8a732323bfdb9e2acb2dcb7daa03719384dd3d52 /search | |
parent | baaddc479ae50f43ea330aa12babbc9bab3e57f1 (diff) |
[assessment-tool] Added support for related queries.
Diffstat (limited to 'search')
-rw-r--r-- | search/search_quality/assessment_tool/sample_view.cpp | 57 | ||||
-rw-r--r-- | search/search_quality/assessment_tool/sample_view.hpp | 8 | ||||
-rw-r--r-- | search/search_quality/sample.cpp | 6 | ||||
-rw-r--r-- | search/search_quality/sample.hpp | 1 | ||||
-rw-r--r-- | search/search_quality/search_quality_tests/sample_test.cpp | 7 |
5 files changed, 69 insertions, 10 deletions
diff --git a/search/search_quality/assessment_tool/sample_view.cpp b/search/search_quality/assessment_tool/sample_view.cpp index f584ede107..21dde29059 100644 --- a/search/search_quality/assessment_tool/sample_view.cpp +++ b/search/search_quality/assessment_tool/sample_view.cpp @@ -20,20 +20,35 @@ #include <QtWidgets/QHeaderView> #include <QtWidgets/QLabel> #include <QtWidgets/QLineEdit> +#include <QtWidgets/QListWidget> #include <QtWidgets/QPushButton> #include <QtWidgets/QVBoxLayout> namespace { template <typename Layout> -Layout * BuildSubLayout(QLayout & mainLayout, QWidget & parent) +Layout * BuildSubLayout(QLayout & mainLayout, QWidget & parent, QWidget ** box) { - auto * box = new QWidget(&parent); - auto * subLayout = BuildLayoutWithoutMargins<Layout>(box /* parent */); - box->setLayout(subLayout); - mainLayout.addWidget(box); + *box = new QWidget(&parent); + auto * subLayout = BuildLayoutWithoutMargins<Layout>(*box /* parent */); + (*box)->setLayout(subLayout); + mainLayout.addWidget(*box); return subLayout; } + +template <typename Layout> +Layout * BuildSubLayout(QLayout & mainLayout, QWidget & parent) +{ + QWidget * box = nullptr; + return BuildSubLayout<Layout>(mainLayout, parent, &box); +} + +void SetVerticalStretch(QWidget & widget, int stretch) +{ + auto policy = widget.sizePolicy(); + policy.setVerticalStretch(stretch); + widget.setSizePolicy(policy); +} } // namespace SampleView::SampleView(QWidget * parent, Framework & framework) @@ -76,7 +91,19 @@ SampleView::SampleView(QWidget * parent, Framework & framework) } { - auto * layout = BuildSubLayout<QVBoxLayout>(*mainLayout, *this /* parent */); + auto * layout = + BuildSubLayout<QVBoxLayout>(*mainLayout, *this /* parent */, &m_relatedQueriesBox); + SetVerticalStretch(*m_relatedQueriesBox, 1 /* stretch */); + layout->addWidget(new QLabel(tr("Related queries"))); + + m_relatedQueries = new QListWidget(); + layout->addWidget(m_relatedQueries); + } + + { + auto * layout = + BuildSubLayout<QVBoxLayout>(*mainLayout, *this /* parent */, &m_foundResultsBox); + SetVerticalStretch(*m_foundResultsBox, 4 /* stretch */); { auto * subLayout = BuildSubLayout<QHBoxLayout>(*layout, *this /* parent */); @@ -91,13 +118,16 @@ SampleView::SampleView(QWidget * parent, Framework & framework) } { - auto * layout = BuildSubLayout<QVBoxLayout>(*mainLayout, *this /* parent */); + auto * layout = + BuildSubLayout<QVBoxLayout>(*mainLayout, *this /* parent */, &m_nonFoundResultsBox); + SetVerticalStretch(*m_nonFoundResultsBox, 2 /* stretch */); layout->addWidget(new QLabel(tr("Non found results"))); m_nonFoundResults = new ResultsView(*this /* parent */); layout->addWidget(m_nonFoundResults); } + setLayout(mainLayout); Clear(); @@ -118,6 +148,12 @@ void SampleView::SetContents(search::Sample const & sample, bool positionAvailab m_showViewport->setEnabled(true); m_showPosition->setEnabled(positionAvailable); + m_relatedQueries->clear(); + for (auto const & query : sample.m_relatedQueries) + m_relatedQueries->addItem(ToQString(query)); + if (m_relatedQueries->count() != 0) + m_relatedQueriesBox->show(); + ClearAllResults(); } @@ -147,12 +183,16 @@ void SampleView::ShowNonFoundResults(std::vector<search::Sample::Result> const & static_cast<SearchMarkPoint *>(guard.m_controller.CreateUserMark(result.m_pos)); mark->SetCustomSymbol("non-found-search-result"); } + + if (!results.empty()) + m_nonFoundResultsBox->show(); } void SampleView::ClearAllResults() { m_foundResults->Clear(); m_nonFoundResults->Clear(); + m_nonFoundResultsBox->hide(); m_framework.ClearSearchResultsMarks(); } @@ -169,6 +209,9 @@ void SampleView::Clear() m_showViewport->setEnabled(false); m_showPosition->setEnabled(false); + + m_relatedQueriesBox->hide(); + ClearAllResults(); OnSearchCompleted(); } diff --git a/search/search_quality/assessment_tool/sample_view.hpp b/search/search_quality/assessment_tool/sample_view.hpp index 2da066310d..820e0e862d 100644 --- a/search/search_quality/assessment_tool/sample_view.hpp +++ b/search/search_quality/assessment_tool/sample_view.hpp @@ -9,6 +9,7 @@ class Framework; class QLabel; +class QListWidget; class QPushButton; class ResultsView; class Spinner; @@ -51,10 +52,17 @@ private: QLabel * m_query = nullptr; QLabel * m_langs = nullptr; + + QListWidget * m_relatedQueries = nullptr; + QWidget * m_relatedQueriesBox = nullptr; + QPushButton * m_showViewport = nullptr; QPushButton * m_showPosition = nullptr; ResultsView * m_foundResults = nullptr; + QWidget * m_foundResultsBox = nullptr; + ResultsView * m_nonFoundResults = nullptr; + QWidget * m_nonFoundResultsBox = nullptr; QMargins m_rightAreaMargins; QMargins m_defaultMargins; diff --git a/search/search_quality/sample.cpp b/search/search_quality/sample.cpp index bc666f8012..988149c270 100644 --- a/search/search_quality/sample.cpp +++ b/search/search_quality/sample.cpp @@ -123,7 +123,9 @@ bool Sample::operator<(Sample const & rhs) const return m_posAvailable < rhs.m_posAvailable; if (m_viewport != rhs.m_viewport) return LessRect(m_viewport, rhs.m_viewport); - return Less(m_results, rhs.m_results); + if (!Equal(m_results, rhs.m_results)) + return Less(m_results, rhs.m_results); + return Less(m_relatedQueries, rhs.m_relatedQueries); } bool Sample::operator==(Sample const & rhs) const { return !(*this < rhs) && !(rhs < *this); } @@ -171,6 +173,7 @@ void Sample::DeserializeFromJSONImpl(json_t * root) FromJSONObject(root, "viewport", m_viewport); FromJSONObjectOptional(root, "results", m_results); + FromJSONObjectOptional(root, "related_queries", m_relatedQueries); } void Sample::SerializeToJSONImpl(json_t & root) const @@ -180,6 +183,7 @@ void Sample::SerializeToJSONImpl(json_t & root) const ToJSONObject(root, "position", m_pos); ToJSONObject(root, "viewport", m_viewport); ToJSONObject(root, "results", m_results); + ToJSONObject(root, "related_queries", m_relatedQueries); } void Sample::FillSearchParams(search::SearchParams & params) const diff --git a/search/search_quality/sample.hpp b/search/search_quality/sample.hpp index 4614d8f8b1..94cfcdceae 100644 --- a/search/search_quality/sample.hpp +++ b/search/search_quality/sample.hpp @@ -62,6 +62,7 @@ struct Sample bool m_posAvailable = false; m2::RectD m_viewport = m2::RectD(0, 0, 0, 0); std::vector<Result> m_results; + std::vector<strings::UniString> m_relatedQueries; }; void FromJSONObject(json_t * root, string const & field, Sample::Result::Relevance & relevance); diff --git a/search/search_quality/search_quality_tests/sample_test.cpp b/search/search_quality/search_quality_tests/sample_test.cpp index 542e50892d..c37f87f1d0 100644 --- a/search/search_quality/search_quality_tests/sample_test.cpp +++ b/search/search_quality/search_quality_tests/sample_test.cpp @@ -39,6 +39,8 @@ void SampleTest::Init() cubaRes.m_pos = {-80.832886, 15.521132748163712}; cubaRes.m_houseNumber = ""; m_cuba.m_results = {cubaRes}; + m_cuba.m_relatedQueries = {strings::MakeUniString("Cuba Libre"), + strings::MakeUniString("Patria o Muerte")}; m_riga.m_query = strings::MakeUniString("riga"); m_riga.m_locale = "en"; @@ -90,7 +92,8 @@ UNIT_CLASS_TEST(SampleTest, Smoke) }, "houseNumber": "" } - ] + ], + "related_queries": ["Cuba Libre", "Patria o Muerte"] } )EOF"; @@ -138,7 +141,7 @@ UNIT_CLASS_TEST(SampleTest, Arrays) { string lines; lines.append( - R"({"query": "cuba", "locale": "en", "position": {"x": 37.618706, "y": 99.53730574302003}, "viewport": {"minx": 37.1336, "miny": 67.1349, "maxx": 38.0314, "maxy": 67.7348}, "results": [{"name": "Cuba", "relevancy": "relevant", "types": ["place-country"], "position": {"x": -80.832886, "y": 15.521132748163712}, "houseNumber": ""}]})"); + R"({"query": "cuba", "locale": "en", "position": {"x": 37.618706, "y": 99.53730574302003}, "viewport": {"minx": 37.1336, "miny": 67.1349, "maxx": 38.0314, "maxy": 67.7348}, "results": [{"name": "Cuba", "relevancy": "relevant", "types": ["place-country"], "position": {"x": -80.832886, "y": 15.521132748163712}, "houseNumber": ""}], "related_queries": ["Patria o Muerte", "Cuba Libre"]})"); lines.append("\n"); lines.append( |