~knitzsche/scope-aggregator/persistent_cat_ids_bug1507666

« back to all changes in this revision

Viewing changes to src/query.cpp

  • Committer: Gary.Wzl
  • Date: 2015-09-16 02:38:14 UTC
  • mfrom: (147.2.3 fix_1490828)
  • Revision ID: gary.wang@canonical.com-20150916023814-vix4qaruem5j1wxj
Tags: 1.5.28
1.Enable keyword scope which does not use a shared category display 
  when changing depts
2.Add exclude_list key for keywords json object to make it possible 
  not to display specific child scopes in keywords category
3.Add link_to_child property in keyword object.

Show diffs side-by-side

added added

removed removed

Lines of Context:
289
289
        us::CannedQuery canned_query = query();
290
290
        std::string dept_id = canned_query.department_id();
291
291
 
 
292
        // skip to next if scope is not registered in the system
 
293
        auto reg_scopes = registry_->list();
 
294
        us::MetadataMap::const_iterator scope_it;
 
295
        scope_it = reg_scopes.find(localId_id_m[local_id]);
 
296
        if (scope_it == reg_scopes.end()) {
 
297
            qWarning () << QString("%1: scope is NOT REGISTERED, skipping: %2").arg(qstr(SCOPE_ID), qstr(localId_id_m[local_id]));
 
298
            continue;
 
299
        }
 
300
 
292
301
        //TODO: add to docs note that when declaring a scope more than once, all must be in different depts
293
302
        if (using_departments)
294
303
        {
295
304
            if (dept_id == "") //is root dept
296
305
            {
297
306
                if(scope->department() != dept_id_of_root)
298
 
                    continue;
 
307
                   continue;
299
308
            }
300
309
            else if(scope->department() != query().department_id())
301
310
                continue;
302
311
        }
303
 
 
304
 
        // skip to next if scope is not registered in the system
305
 
        auto reg_scopes = registry_->list();
306
 
        us::MetadataMap::const_iterator scope_it;
307
 
        scope_it = reg_scopes.find(localId_id_m[local_id]);
308
 
        if (scope_it == reg_scopes.end()) {
309
 
            qWarning () << QString("%1: scope is NOT REGISTERED, skipping: %2").arg(qstr(SCOPE_ID), qstr(localId_id_m[local_id]));
310
 
            continue;
311
 
        }
312
 
 
 
312
        
313
313
        // if scope is not in the currently enabled list, skip it
314
314
        bool found_as_enabled = false;
315
315
        for (auto cs : current_child_scopes)//FQ ids
322
322
                }
323
323
            }
324
324
        }
 
325
 
325
326
        if (!found_as_enabled)
326
327
        {
327
328
            qWarning () << QString("%1: scope is NOT ENABLED, skipping: %2").arg(qstr(SCOPE_ID), qstr(localId_id_m[local_id]));
328
329
            continue;
329
330
        }
330
331
 
 
332
        // if scope is in exclude scopes list, skip it
 
333
        bool found_as_exclude = false;
 
334
        for (auto kw : keywords)
 
335
        {
 
336
            if (kw->id == scope->keyword()) {
 
337
                auto iter = std::find(kw->exclude_scopes.begin(), kw->exclude_scopes.end(), scope->id());
 
338
                if (iter != kw->exclude_scopes.end())
 
339
                {
 
340
                    found_as_exclude = true;
 
341
                    qWarning () << QString("==== FOUND AS EXCLUDE:  %1: scope is in exclude scopes of keyword: %2")
 
342
                                   .arg(qstr(scope->id()), qstr(scope->keyword()));
 
343
                }
 
344
            }
 
345
        }
 
346
 
 
347
        if (found_as_exclude) {
 
348
            continue;
 
349
        }
 
350
 
 
351
 
331
352
        if (query_string.empty() && scope->only_in_search() == true)
332
353
        {
333
354
            continue;
612
633
                        }
613
634
                        if (!upstream_reply->lookup_category(cat_id))
614
635
                        {
615
 
                            scope->set_category(upstream_reply->register_category
616
 
                            (
617
 
                                cat_id,
618
 
                                cat_title,
619
 
                                 "",
620
 
                                us::CategoryRenderer(rdr)
621
 
                            ));
 
636
                           if (scope->category_link_to_child()) 
 
637
                           {
 
638
                               scope->set_category
 
639
                               (
 
640
                                   upstream_reply->register_category
 
641
                                   (
 
642
                                    cat_id,
 
643
                                    cat_title,
 
644
                                    "",
 
645
                                    us::CannedQuery(scope->id(), query_string, scope->child_department()),
 
646
                                    us::CategoryRenderer(rdr)
 
647
                                   ) 
 
648
                               );
 
649
                           }
 
650
                           else
 
651
                           {
 
652
                               scope->set_category
 
653
                               (
 
654
                                   upstream_reply->register_category
 
655
                                   (
 
656
                                    cat_id,
 
657
                                    cat_title,
 
658
                                    "",
 
659
                                    us::CategoryRenderer(rdr)
 
660
                                   )
 
661
                               );
 
662
                           }
622
663
                        }
623
664
                    }
624
665
                    res.set_category(scope->category());
1049
1090
                {
1050
1091
                    if (!rdr.empty()) // should not ever be empty!
1051
1092
                    {
1052
 
                        if (scope->category_link_to_child())
1053
 
                        {
1054
 
                            if (!upstream_reply->lookup_category(cat_id))
1055
 
                            {
1056
 
                                scope->set_category
1057
 
                                (
1058
 
                                    upstream_reply->register_category
1059
 
                                    (
1060
 
                                        cat_id,
1061
 
                                        cat_title,
1062
 
                                         "",
1063
 
                                        us::CannedQuery(scope->id(), query_string, scope->child_department()),
1064
 
                                        us::CategoryRenderer(rdr)
1065
 
                                    )
1066
 
                                );
1067
 
                            }
1068
 
                        }
1069
 
                        else
1070
 
                        {
1071
 
                            if (!upstream_reply->lookup_category(cat_id))
1072
 
                            {
1073
 
                                scope->set_category
1074
 
                                (
1075
 
                                    upstream_reply->register_category
1076
 
                                    (
1077
 
                                        cat_id,
1078
 
                                        cat_title,
1079
 
                                         "",
1080
 
                                        us::CategoryRenderer(rdr)
1081
 
                                    )
1082
 
                                );
1083
 
                            }
1084
 
                        }
 
1093
                        if (!upstream_reply->lookup_category(cat_id))
 
1094
                        {
 
1095
                            if (scope->category_link_to_child())
 
1096
                            {
 
1097
                                scope->set_category
 
1098
                                (
 
1099
                                   upstream_reply->register_category
 
1100
                                   (
 
1101
                                    cat_id,
 
1102
                                    cat_title,
 
1103
                                    "",
 
1104
                                    us::CannedQuery(scope->id(), query_string, scope->child_department()),
 
1105
                                    us::CategoryRenderer(rdr)
 
1106
                                   )
 
1107
                                );
 
1108
                            } 
 
1109
                            else
 
1110
                            {
 
1111
                               scope->set_category
 
1112
                               (
 
1113
                                   upstream_reply->register_category
 
1114
                                   (
 
1115
                                    cat_id,
 
1116
                                    cat_title,
 
1117
                                    "",
 
1118
                                    us::CategoryRenderer(rdr)
 
1119
                                   )
 
1120
                               );
 
1121
                           }
 
1122
                       }
1085
1123
                    }
1086
1124
                    else
1087
1125
                        qWarning() << QString("Warning: Scope %1 renderer is empty.").arg(qstr(scope->id()));