3

\P                 @   s   d dl mZ d dlmZ d dlmZ d dlmZmZ eddZ	eddZ
ed	d
Zed	dZeddZdd ZG dd de
ZG dd de
ZG dd deZdS )    )settings)import_string)MultipleObjectMixin)	get_class	get_modelzsearch.formsBrowseCategoryFormzsearch.search_handlersSearchHandlerzsearch.featuresis_solr_supportedis_elasticsearch_supported	catalogueProductc               C   sB   t jdk	rtt jS t r$tddS t r4tddS tddS dS )z
    Determine the search handler to use.

    Currently only Solr is supported as a search backend, so it falls
    back to rudimentary category browsing if that isn't enabled.
    Nzcatalogue.search_handlersSolrProductSearchHandlerESProductSearchHandlerSimpleProductSearchHandler)r   OSCAR_PRODUCT_SEARCH_HANDLERr   r	   r   r
    r   r   ?/var/www/html/oscar2019/oscar/apps/catalogue/search_handlers.py get_product_search_handler_class   s    


r   c                   s>   e Zd ZdZeZegZej	Z
d fdd	Z fddZ  ZS )r   z
    Search handler specialised for searching products.  Comes with optional
    category filtering. To be used with a Solr search backend.
    Nc                s   || _ t j|| d S )N)
categoriessuper__init__)selfrequest_data	full_pathr   )	__class__r   r   r   ,   s    z!SolrProductSearchHandler.__init__c                s<   t  j  | jr8dj fdd| jD } jd|   S )Nz OR c                s   g | ]}d  j j|j qS )z"%s")queryclean	full_name).0c)sqsr   r   
<listcomp>6   s    z@SolrProductSearchHandler.get_search_queryset.<locals>.<listcomp>zcategory_exact:(%s))r   get_search_querysetr   joinnarrow)r   pattern)r   )r    r   r"   0   s    
z,SolrProductSearchHandler.get_search_queryset)N)__name__
__module____qualname____doc__r   
form_classr   model_whitelistr   OSCAR_PRODUCTS_PER_PAGEpaginate_byr   r"   __classcell__r   r   )r   r   r   #   s   r   c                   s>   e Zd ZdZeZegZej	Z
d fdd	Z fddZ  ZS )r   z
    Search handler specialised for searching products.  Comes with optional
    category filtering. To be used with an ElasticSearch search backend.
    Nc                s   || _ t j|| d S )N)r   r   r   )r   r   r   r   )r   r   r   r   D   s    zESProductSearchHandler.__init__c                s2   t  j }| jr.x| jD ]}|j|jd}qW |S )N)category)r   r"   r   	filter_orr   )r   r    r/   )r   r   r   r"   H   s
    
z*ESProductSearchHandler.get_search_queryset)N)r&   r'   r(   r)   r   r*   r   r+   r   r,   r-   r   r"   r.   r   r   )r   r   r   ;   s   r   c               @   s0   e Zd ZdZejZd	ddZdd Zdd Z	dS )
r   a=  
    A basic implementation of the full-featured SearchHandler that has no
    faceting support, but doesn't require a Haystack backend. It only
    supports category browsing.

    Note that is meant as a replacement search handler and not as a view
    mixin; the mixin just does most of what we need it to do.
    Nc             C   s&   || _ d|jddi| _| j | _d S )Npage   )r   getkwargsget_querysetobject_list)r   r   r   r   r   r   r   r   [   s    z#SimpleProductSearchHandler.__init__c             C   s*   t jj j }| jr&|j| jdj }|S )N)Zcategories__in)r   objects	browsablebase_querysetr   filterdistinct)r   qsr   r   r   r5   `   s    z'SimpleProductSearchHandler.get_querysetc             C   s&   || _ | j| jd}|d j||< |S )N)r6   page_obj)context_object_nameget_context_datar6   )r   r>   contextr   r   r   get_search_context_dataf   s    z2SimpleProductSearchHandler.get_search_context_data)N)
r&   r'   r(   r)   r   r,   r-   r   r5   rA   r   r   r   r   r   P   s
   
r   N)django.confr   django.utils.module_loadingr   django.views.generic.listr   oscar.core.loadingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   <module>   s   




