~unity-team/unity-scope-click/devel

« back to all changes in this revision

Viewing changes to scope/clickstore/store-query.cpp

  • Committer: Tarmac
  • Author(s): Pawel Stolowski
  • Date: 2014-07-16 13:57:55 UTC
  • mfrom: (310.2.13 populate-departments-db)
  • Revision ID: tarmac-20140716135755-bsuqlp22axfwvvd5
Populate departments database in the store scope. Use slugs for unique department ids when parsing. Implemented a tool that initializes or updates departments db.

Approved by Alejandro J. Cura, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "store-query.h"
33
33
#include "store-scope.h"
34
34
#include <click/qtbridge.h>
 
35
#include <click/departments-db.h>
35
36
 
36
37
#include <click/key_file_locator.h>
37
38
 
114
115
struct click::Query::Private
115
116
{
116
117
    Private(click::Index& index, click::DepartmentLookup& depts,
 
118
            std::shared_ptr<click::DepartmentsDb> depts_db,
117
119
            click::HighlightList& highlights, const scopes::SearchMetadata& metadata)
118
120
        : index(index),
119
121
          department_lookup(depts),
 
122
          depts_db(depts_db),
120
123
          highlights(highlights),
121
124
          meta(metadata)
122
125
    {
123
126
    }
124
127
    click::Index& index;
125
128
    click::DepartmentLookup& department_lookup;
 
129
    std::shared_ptr<click::DepartmentsDb> depts_db;
126
130
    click::HighlightList& highlights;
127
131
    scopes::SearchMetadata meta;
128
132
    click::web::Cancellable search_operation;
129
133
};
130
134
 
131
135
click::Query::Query(unity::scopes::CannedQuery const& query, click::Index& index, click::DepartmentLookup& depts,
 
136
        std::shared_ptr<click::DepartmentsDb> depts_db,
132
137
        click::HighlightList& highlights,
133
138
        scopes::SearchMetadata const& metadata)
134
139
    : unity::scopes::SearchQueryBase(query, metadata),
135
 
      impl(new Private(index, depts, highlights, metadata))
 
140
      impl(new Private(index, depts, depts_db, highlights, metadata))
136
141
{
137
142
}
138
143
 
234
239
    root->set_subdepartments(departments);
235
240
}
236
241
 
 
242
// recursively store all departments in the departments database
 
243
void click::Query::store_departments(const click::DepartmentList& depts)
 
244
{
 
245
    assert(impl->depts_db);
 
246
 
 
247
    try
 
248
    {
 
249
        impl->depts_db->store_departments(depts, search_metadata().locale());
 
250
    }
 
251
    catch (const std::exception &e)
 
252
    {
 
253
        qWarning() << "Failed to update database: " << QString::fromStdString(e.what());
 
254
    }
 
255
}
 
256
 
237
257
void click::Query::push_package(const scopes::SearchReplyProxy& searchReply, scopes::Category::SCPtr category, const PackageSet &installedPackages, const Package& pkg)
238
258
{
239
259
    qDebug() << "pushing result" << QString::fromStdString(pkg.name);
400
420
                    impl->department_lookup.rebuild(rdeps);
401
421
                    impl->highlights = highlights;
402
422
                    qDebug() << "Total number of departments:" << impl->department_lookup.size() << ", highlights:" << highlights.size();
 
423
 
 
424
                    if (impl->depts_db)
 
425
                    {
 
426
                        qDebug() << "Storing departments in the database";
 
427
                        store_departments(deps);
 
428
                    }
 
429
                    else
 
430
                    {
 
431
                        qWarning() << "Departments db not available";
 
432
                    }
403
433
                }
404
434
                else
405
435
                {