当前位置: 首页>>代码示例>>Python>>正文


Python EmptySearchQuerySet.load_all方法代码示例

本文整理汇总了Python中haystack.query.EmptySearchQuerySet.load_all方法的典型用法代码示例。如果您正苦于以下问题:Python EmptySearchQuerySet.load_all方法的具体用法?Python EmptySearchQuerySet.load_all怎么用?Python EmptySearchQuerySet.load_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在haystack.query.EmptySearchQuerySet的用法示例。


在下文中一共展示了EmptySearchQuerySet.load_all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: personal_search

# 需要导入模块: from haystack.query import EmptySearchQuerySet [as 别名]
# 或者: from haystack.query.EmptySearchQuerySet import load_all [as 别名]
def personal_search(request):
    """    
    The user can search any item within his own collections and can search **only shared items** of other users
    
    TODO: Build a hash table to store item_id in the result of user_item to reduce time from O(n^2) to O(n)
    
    Reference: http://docs.haystacksearch.org/dev/searchqueryset_api.html#field-lookups
    """
    #Two parameters to tune
    RESULTS_PER_PAGE = 10
    load_all = False
    
    query = request.GET['q'].strip()  #Heystack only accepts key name as 'q'
    user_id = int(request.GET['pid'])
    if query == '':
        sqs = EmptySearchQuerySet()
    else:
        searchqueryset = SearchQuerySet()
        if user_id == request.user.pk:
            pronoun = '我'
            own_items = User_Item.objects.filter(user__pk=request.user.pk)
        else:
            pronoun = Profile.objects.get(pk=user_id).name
            own_items = User_Item.objects.filter(user__pk=user_id).exclude(status=1)
            
        own_items_ids = []
        for oi in own_items:
            own_items_ids.append(int(oi.item_id))
        sqs = searchqueryset.auto_query(query).filter(primary_key__in=own_items_ids)
        
    if load_all:
            sqs = sqs.load_all()
    paginator = Paginator(sqs, RESULTS_PER_PAGE)   
    try:
        page = paginator.page(request.GET.get('page', 1))
        feeds_id = ''
        for result in page.object_list:
            feeds_id += str(result.object.id) + ','
        feeds_id = feeds_id[:-1]
        topics_of_item_dict = get_topics_of_item(feeds_id, request.user.pk)
        friends_of_item_dict = get_friends_of_item(feeds_id, request.user.pk)
        user_item_status_dict = get_user_items(feeds_id, request.user.pk)
    except InvalidPage:
        raise Http404
    context = {
            'query': query,
            'page': page,
            'page_type':'search',
            'topics_of_item_dict':topics_of_item_dict,
            'friends_of_item_dict':friends_of_item_dict,
            'user_item_status_dict':user_item_status_dict,
            'paginator': paginator,
            'suggestion': None,
            'pronoun': pronoun,
            'num_results': len(sqs),
            'user_id': user_id
        }
    from django.template import add_to_builtins
    add_to_builtins('haystack.templatetags.highlight')
    return render_to_response('main/search/personal_search_results.html', context, context_instance=RequestContext(request))
开发者ID:alexdiao,项目名称:3805,代码行数:62,代码来源:search.py

示例2: search

# 需要导入模块: from haystack.query import EmptySearchQuerySet [as 别名]
# 或者: from haystack.query.EmptySearchQuerySet import load_all [as 别名]
def search(request):
    """
    Modification/Combination based on two haystack classes:
    1,haystack/views/SearchView
    2,haystack/forms/SearchForm/search()
    
    Reference:
       #. http://docs.haystacksearch.org/dev/
       #. http://lucene.apache.org/solr/tutorial.html
    """
    #Two parameters to tune
    RESULTS_PER_PAGE = 10
    load_all = False
    
    query = request.GET['q'].strip()  #Heystack only accepts key name as 'q'
    if query == '':
        sqs = EmptySearchQuerySet()
    else:
        searchqueryset = SearchQuerySet()
        sqs = searchqueryset.auto_query(query) #The default auto_query method has been modified to use OR instead of AND
    if load_all:
            sqs = sqs.load_all()
    paginator = Paginator(sqs, RESULTS_PER_PAGE)   
    try:
        page = paginator.page(request.GET.get('page', 1))
        feeds_id = ''
        for result in page.object_list:
            feeds_id += str(result.object.id) + ',' #If an item is deleted and not reindexed, then error
        feeds_id = feeds_id[:-1]
        topics_of_item_dict = get_topics_of_item(feeds_id, request.user.pk)
        friends_of_item_dict = get_friends_of_item(feeds_id, request.user.pk)
        user_item_status_dict = get_user_items(feeds_id, request.user.pk)
    except InvalidPage:
        raise Http404
    context = {
            'query': query,
            'page': page,
            'page_type':'search',
            'topics_of_item_dict':topics_of_item_dict,
            'friends_of_item_dict':friends_of_item_dict,
            'user_item_status_dict':user_item_status_dict,
            'paginator': paginator,
            'suggestion': None,
            'num_results': len(sqs),
        }
    from django.template import add_to_builtins
    add_to_builtins('haystack.templatetags.highlight')  #Changed haystack.utils.Highlighter.highliht to not use window
    return render_to_response('main/search/web_search_results.html', context, context_instance=RequestContext(request))
开发者ID:alexdiao,项目名称:3805,代码行数:50,代码来源:search.py


注:本文中的haystack.query.EmptySearchQuerySet.load_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。