Exemplo n.º 1
0
    def _index(self, qs):
        paginator = Paginator(qs, CHUNK_SIZE)
        total = paginator.num_pages

        for i in range(1, total+1):
            topics = paginator.page(i)
            SolrSearcher.index_topics(topics)
            print_progress(i, total)
Exemplo n.º 2
0
def search_topic(request, board_alias, query):
    cursor = connection.cursor()
    try:
        board = Board.objects.get(alias=board_alias)
    except ObjectDoesNotExist:
        raise Http404

    page  = get_page_from_request(request)
    start = (page-1) * settings.LURKERFAQS_TOPICS_PER_PAGE
    count = settings.LURKERFAQS_TOPICS_PER_PAGE

    # topic ids should be date descending ordered
    total_results, topic_gfaqs_ids = SolrSearcher.search_topic(query, board_alias, start, count)
    topics_unordered = list(Topic.objects.filter(gfaqs_id__in=topic_gfaqs_ids))

    # reorder topics
    topics = []
    for gid in topic_gfaqs_ids:
        for t in topics_unordered:
            if t.gfaqs_id == gid:
                topics.append(t)
                break

    # create a page guide for pagination
    topics_per_page = settings.LURKERFAQS_PAGES_TO_DISPLAY
    page_guide = create_page_guide(total_results/count + 1,
            settings.LURKERFAQS_PAGES_TO_DISPLAY, page)

    t = loader.get_template('topic_search.html')
    c = build_context(request, topics=topics, board=board, query=query,
        current_page=page, page_guide=page_guide)
    return HttpResponse(t.render(c))
Exemplo n.º 3
0
def show_topic(request, board_alias, topic_num):
    # /boards/<board_alias>/<topic_num>?page=2
    try:
        board = Board.objects.get(alias=board_alias)
        topic = Topic.objects.get(gfaqs_id=topic_num)
        if topic.is_hidden():
            raise Http404
    except ObjectDoesNotExist:
        raise Http404

    qs = Post.objects.filter(topic=topic).order_by('date')
    posts, current_page, page_guide = get_qs_paged(
        request, qs, settings.LURKERFAQS_POSTS_PER_PAGE)

    if not posts:
        t = loader.get_template('posts_none.html')
        c = build_context(request, topic=topic, board=topic.board)
        return HttpResponse(t.render(c))

    posts = remove_hidden_posts(posts)
    for post in posts:
        post.contents = linkify(post.contents, settings.LURKERFAQS_LINKIFY_IMG)
    op_post = posts[0]

    # get related topics to this one
    related_topics_gids = SolrSearcher.search_related_topics(
            topic, settings.LURKERFAQS_RELATED_TOPICS_COUNT)
    related_topics = list(
        Topic.objects.filter(gfaqs_id__in=related_topics_gids)
    )
    for tp in related_topics:
        load_status_icon(tp)

    payment_enabled = settings.ENABLE_PAYMENTS

    t = loader.get_template('posts_new.html')
    c = build_context(request, board=topic.board, topic=topic,
            posts=posts, op_post=op_post, related_topics=related_topics,
            current_page=current_page, page_guide=page_guide,
            payment_enabled=payment_enabled)
    return HttpResponse(t.render(c))