Esempio n. 1
0
def index(request):
    accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '')
    user_langs = get_user_languages_from_request(request)
    
    if 'q' in request.REQUEST:
        form = SearchForm(request.user, user_langs, request.REQUEST)
    else:
        form = SearchForm(request.user, user_langs)
    
    qs = SearchQuerySet().none()
    
    display_mode = 'all'
    
    if form.is_valid():
        qs = form.search_qs(SearchQuerySet().models(Video))
        display_mode = form.cleaned_data.get('display', 'all')
        
    if settings.HAYSTACK_SEARCH_ENGINE == 'dummy' and settings.DEBUG:
        q = request.REQUEST.get('q', '')
        qs = Video.objects.filter(title__icontains=q)
    
    context = {
        'query': request.REQUEST.get('q', ''),
        'form': form,
        'display_mode': display_mode
    }
        
    return object_list(request, queryset=qs,
                       paginate_by=30,
                       template_name='search/index.html',
                       template_object_name='result',
                       extra_context=context)   
Esempio n. 2
0
def index(request):
    accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '')
    user_langs = get_user_languages_from_request(request)

    if 'q' in request.REQUEST:
        form = SearchForm(request.user, user_langs, request.REQUEST)
    else:
        form = SearchForm(request.user, user_langs)

    qs = SearchQuerySet().none()

    display_mode = 'all'

    if form.is_valid():
        qs = form.search_qs(SearchQuerySet().models(Video).load_all())
        display_mode = form.cleaned_data.get('display', 'all')

    if settings.HAYSTACK_SEARCH_ENGINE == 'dummy' and settings.DEBUG:
        q = request.REQUEST.get('q', '')
        qs = Video.objects.filter(title__icontains=q)

    context = {
        'query': request.REQUEST.get('q', ''),
        'form': form,
        'display_mode': display_mode
    }

    return object_list(request,
                       queryset=qs,
                       paginate_by=20,
                       template_name='search/index.html',
                       template_object_name='result',
                       extra_context=context)
Esempio n. 3
0
    def search(self, rdata, user, testing=False):
        sqs = SearchQuerySet().result_class(VideoSearchResult) \
                .models(Video)
        
        rdata['q'] = rdata['q'] or u' '
        q = rdata.get('q')

        if q:
            sqs = SearchForm.apply_query(q, sqs)
            form = SearchForm(rdata, sqs=sqs)
        else:
            form = SearchForm(rdata)
        
        if form.is_valid():
            qs = form.search_qs(sqs)
        else:
            qs = SearchQuerySet().none()    

        #result = [item.object for item in qs]
        #qs1 = Video.objects.filter(title__contains=rdata['q'])
        #for o in qs1:
        #    if not o in result:
        #        print o.title
        
        display_views = form.get_display_views()
        output = render_page(rdata.get('page', 1), qs, 20, display_views=display_views)
        output['sidebar'] = render_to_string('search/_sidebar.html', dict(form=form, rdata=rdata))
        
        if testing:
            output['sqs'] = qs
        
        return output
Esempio n. 4
0
    def search(self, rdata, user, testing=False):
        sqs = SearchQuerySet().result_class(VideoSearchResult) \
                .models(Video)

        q = rdata.get('q')
        if q:
            sqs = SearchForm.apply_query(q, sqs)
            form = SearchForm(rdata, sqs=sqs)
        else:
            form = SearchForm(rdata)

        if form.is_valid():
            qs = form.search_qs(sqs)
        else:
            qs = SearchQuerySet().none()

        #result = [item.object for item in qs]
        #qs1 = Video.objects.filter(title__contains=rdata['q'])
        #for o in qs1:
        #    if not o in result:
        #        print o.title

        display_views = form.get_display_views()
        output = render_page(rdata.get('page', 1),
                             qs,
                             20,
                             display_views=display_views)
        output['sidebar'] = render_to_string('search/_sidebar.html',
                                             dict(form=form, rdata=rdata))

        if testing:
            output['sqs'] = qs

        return output
Esempio n. 5
0
    def search(self, rdata, user, testing=False):
        sqs = VideoIndex.public()

        rdata['q'] = rdata['q'] or u' '
        q = rdata.get('q')

        if q:
            sqs = SearchForm.apply_query(q, sqs)
            form = SearchForm(rdata, sqs=sqs)
        else:
            form = SearchForm(rdata)

        if form.is_valid():
            qs = form.search_qs(sqs)
        else:
            qs = VideoIndex.public().none()

        #result = [item.object for item in qs]
        #qs1 = Video.objects.filter(title__contains=rdata['q'])
        #for o in qs1:
        #    if not o in result:
        #        print o.title

        display_views = form.get_display_views()
        output = render_page(rdata.get('page', 1),
                             qs,
                             20,
                             display_views=display_views)
        output['sidebar'] = render_to_string('search/_sidebar.html',
                                             dict(form=form, rdata=rdata))

        # Assume we're currently indexing if the number of public
        # indexed vids differs from the count of video objects by
        # more than 1000
        is_indexing = cache.get('is_indexing')
        if is_indexing is None:
            is_indexing = Video.objects.all().count() - VideoIndex.public(
            ).count() > 1000
            cache.set('is_indexing', is_indexing, 300)

        output['is_indexing'] = is_indexing

        if testing:
            output['sqs'] = qs

        return output