Exemple #1
0
def _execute_search(request, query, page_size):
    search = Search(request, separate_replies=True)
    for agg in aggregations_for(query):
        search.append_aggregation(agg)

    query = query.copy()
    page = request.params.get('page', 1)

    try:
        page = int(page)
    except ValueError:
        page = 1

    # Don't allow negative page numbers.
    if page < 1:
        page = 1

    query['limit'] = page_size
    query['offset'] = (page - 1) * page_size

    search_result = search.run(query)
    return search_result
Exemple #2
0
def _execute_search(request, query, page_size):
    search = Search(request, separate_replies=True, stats=request.stats)
    for agg in aggregations_for(query):
        search.append_aggregation(agg)

    query = query.copy()
    page = request.params.get('page', 1)

    try:
        page = int(page)
    except ValueError:
        page = 1

    # Don't allow negative page numbers.
    if page < 1:
        page = 1

    query['limit'] = page_size
    query['offset'] = (page - 1) * page_size

    search_result = search.run(query)
    return search_result
Exemple #3
0
def execute(request, query, page_size):
    search = Search(request)
    search.append_filter(TopLevelAnnotationsFilter())
    for agg in aggregations_for(query):
        search.append_aggregation(agg)

    query = query.copy()
    page = request.params.get('page', '')
    if not page:
        page = '1'
    query['limit'] = page_size
    query['offset'] = (int(page) - 1) * page_size
    search_result = search.run(query)
    result = ActivityResults(total=search_result.total,
                             aggregations=search_result.aggregations,
                             timeframes=[])

    if result.total == 0:
        return result

    # Load all referenced annotations from the database, bucket them, and add
    # the buckets to result.timeframes.
    anns = _fetch_annotations(request.db, search_result.annotation_ids)
    result.timeframes.extend(bucketing.bucket(anns))

    # Fetch all groups
    group_pubids = set([a.groupid
                        for t in result.timeframes
                        for b in t.document_buckets.values()
                        for a in b.annotations])
    groups = {g.pubid: g for g in _fetch_groups(request.db, group_pubids)}

    # Add group information to buckets and present annotations
    for timeframe in result.timeframes:
        for bucket in timeframe.document_buckets.values():
            for index, annotation in enumerate(bucket.annotations):
                bucket.annotations[index] = {
                    'annotation': presenters.AnnotationHTMLPresenter(annotation),
                    'group': groups.get(annotation.groupid)
                }

    return result
Exemple #4
0
def execute(request, query):
    search = Search(request)
    search.append_filter(TopLevelAnnotationsFilter())
    for agg in aggregations_for(query):
        search.append_aggregation(agg)

    search_result = search.run(query)
    result = ActivityResults(total=search_result.total,
                             aggregations=search_result.aggregations,
                             timeframes=[])

    if result.total == 0:
        return result

    # Load all referenced annotations from the database, bucket them, and add
    # the buckets to result.timeframes.
    anns = _fetch_annotations(request.db, search_result.annotation_ids)
    result.timeframes.extend(bucketing.bucket(anns))

    # Fetch all groups
    group_pubids = set([a.groupid
                        for t in result.timeframes
                        for b in t.document_buckets.values()
                        for a in b.annotations])
    groups = {g.pubid: g for g in _fetch_groups(request.db, group_pubids)}

    # Add group information to buckets and present annotations
    for timeframe in result.timeframes:
        for bucket in timeframe.document_buckets.values():
            for index, annotation in enumerate(bucket.annotations):
                bucket.annotations[index] = {
                    'annotation': presenters.AnnotationHTMLPresenter(annotation),
                    'group': groups.get(annotation.groupid)
                }

    return result