Exemplo n.º 1
0
 def test_package_search(self):
     import ckanext.hdx_search.controllers.search_controller as search
     import ckanext.hdx_search.actions.actions as hdx_actions
     user = model.User.by_name('hdx')
     data_dict = {
             'q': '',
             'fq': '',
             'facet.field': ['vocab_Topics','groups','organizations'],
             'rows': 25,
             'start': (1 - 1) * 25,
             'sort': None,
             'extras': {}
         }
     context = {'model': model, 'session': model.Session,
                    'user': user, 'for_view': True, 'auth_user_obj': user}
     s = hdx_actions.package_search(context, data_dict)
     assert len(s['results']) > 0
Exemplo n.º 2
0
    def _performing_search(self, q, fq, facet_keys, limit, page, sort_by,
                           search_extras, pager_url, context):
        data_dict = {
            'q': q,
            'fq': fq.strip(),
            'facet.field': facet_keys,
            'rows': limit,
            'start': (page - 1) * limit,
            'sort': sort_by,
            'extras': search_extras
        }

        self._decide_adding_dataset_criteria(data_dict)

        query = hdx_actions.package_search(context, data_dict)

        if not query.get('results', None):
            log.warn('No query results found for data_dict: {}. Query dict is: {}. Query time {}'.format(
                str(data_dict), str(query), datetime.datetime.now()))

        all_result = search_for_all(context, data_dict)
        c.dataset_counts, c.indicator_counts = extract_counts(all_result)

        c.count = c.dataset_counts + c.indicator_counts
        if not c.count:
            log.warn('Dataset counts are zero for data_dict: {}. all_results dict is: {}. Query time {}'.format(
                str(data_dict), str(query), datetime.datetime.now()))

        if c.tab == "all":
            # c.features = isolate_features(
            #     context, query['search_facets'], q, c.tab)
            c.indicator = extract_one_indicator(all_result)
            if c.indicator:
                get_action('populate_related_items_count')(context, {'pkg_dict_list': c.indicator})
            c.facets = all_result['facets']
            c.search_facets = all_result['search_facets']
        else:
            c.facets = query['facets']
            c.search_facets = query['search_facets']

#             if c.tab == 'features':
#                 c.features, c.count = isolate_features(
# context, query['search_facets'], q, c.tab, ((page - 1) * limit), limit)


#             if c.tab == 'features':
#                 c.page = h.Page(
#                     collection=c.features,
#                     page=page,
#                     url=pager_url,
#                     item_count=c.count,
#                     items_per_page=limit
#                 )
# c.facets = query['facets']
# c.search_facets = query['search_facets']
#                 c.page.items = c.features
#             else:
#                 c.page = h.Page(
#                     collection=query['results'],
#                     page=page,
#                     url=pager_url,
#                     item_count=query['count'],
#                     items_per_page=limit
#                 )
# c.facets = query['facets']
# c.search_facets = query['search_facets']
#                 c.page.items = query['results']

        get_action('populate_related_items_count')(context, {'pkg_dict_list':query['results']})

        c.page = h.Page(
            collection=query['results'],
            page=page,
            url=pager_url,
            item_count=query['count'],
            items_per_page=limit
        )
        c.page.items = query['results']
        c.sort_by_selected = query['sort']

        return query, all_result