Exemplo n.º 1
0
    def results(self, query=None, batch=True, b_size=10, b_start=0):
        results_pessoas = []

        tipo_busca = self.request.form.get('facet.tipo', 'intranet')
        term = self.request.form.get('SearchableText', '')

        if not query:
            query = {}

        if term:
            query = {'SearchableText': quote_bad_chars(term) + '*' }

        if tipo_busca == 'intranet':
            if term:
                results_pessoas = FuncDetails.get_AllFuncDetails(unicode(term, 'utf-8'))[:2]

            plone_utils = getToolByName(self.context, 'plone_utils')
            all_types = plone_utils.getUserFriendlyTypes([])
            
            #Removendo filtro de busca
            #Intranet deve buscar tudo
            #for i in ['Image','File', 'Servico']:
            #    all_types.remove(i)

            query['portal_type'] = all_types

        elif tipo_busca == 'pessoas':
            results = []
            if term:
                results = FuncDetails.get_AllFuncDetails(unicode(term, 'utf-8'), search_all_fields=False)
                if batch:
                    results = Batch(results, b_size, b_start)
            return results,[]

        elif tipo_busca == 'servico':
            query['portal_type'] = ['Servico']

        elif tipo_busca == 'biblioteca':
            query['portal_type'] = ['File','VindulaVideo', 'VindulaStreaming', 'VindulaPhotoAlbum']
        
        
        if tipo_busca == 'structure':
            p_catalog = getToolByName(self.context, 'portal_catalog')
            query['portal_type'] = ['OrganizationalStructure']
            results_catalog = p_catalog(**query)
            
            UIDS=[]
            for item in results_catalog:
                UIDS.append(item.UID)
                
            data_structures = ModelsContent.getAllByContentType('OrganizationalStructure', True)
            for structure in data_structures:
                if structure.uid in UIDS:
                    UIDS.remove(structure.uid)
            
            result = [i for i in results_catalog if i.UID in UIDS]
            result = IContentListing(result)
            result = Batch(result, b_size, b_start)
        else:   
            result = super(SearchView,self).results(query=query,batch=batch,b_size=b_size, b_start=b_start)

        return result, results_pessoas
Exemplo n.º 2
0
    def results(self, query=None, batch=True, b_size=10, b_start=0):
        results_pessoas = []
        _q_session = self.request.SESSION.get('_q')
        tipo_busca_session = self.request.SESSION.get('facet.tipo')

        _q = self.request.form.get('q', _q_session)
        tipo_busca = self.request.form.get('facet.tipo', tipo_busca_session)

        if (not _q_session and _q) or (_q_session != _q):
            self.request.SESSION['_q'] = _q

        if (not tipo_busca_session and tipo_busca) or (tipo_busca_session != tipo_busca):
            self.request.SESSION['facet.tipo'] = tipo_busca

        if not query:
            query = {}

        for char in ('?', '-', '+', '*', multispace):
            _q = _q.replace(char, ' ')

        r = _q.split()
        r = " AND ".join(r)
        r = quote_bad_chars(r) + '*'
        searchterms = url_quote_plus(r)
        
        query = {'SearchableText': r }

        if tipo_busca == 'intranet':
            results_pessoas = FuncDetails.get_AllFuncDetails(unicode(_q, 'utf-8'))[:2]
            plone_utils = getToolByName(self.context, 'plone_utils')
            all_types = plone_utils.getUserFriendlyTypes([])
            
            #Removendo filtro de busca. 
            #Intranet deve buscar tudo
            #for i in ['Image','File', 'Servico']:
            #    all_types.remove(i)

            query['portal_type'] = all_types

        elif tipo_busca == 'pessoas':
            results = []
            if _q:
                results = FuncDetails.get_AllFuncDetails(unicode(_q, 'utf-8'), search_all_fields=False)
                if batch:
                    results = Batch(results, b_size, b_start)

            return results,[]

        elif tipo_busca == 'servico':
            query['portal_type'] = ['Servico']

        elif tipo_busca == 'biblioteca':
            query['portal_type'] = ['File','VindulaVideo', 'VindulaStreaming', 'VindulaPhotoAlbum']
            
        if tipo_busca == 'structure':
            p_catalog = getToolByName(self.context, 'portal_catalog')
            query['portal_type'] = ['OrganizationalStructure']
            results_catalog = p_catalog(**query)
            
            UIDS=[]
            for item in results_catalog:
                UIDS.append(item.UID)
                
            data_structures = ModelsContent.getAllByContentType('OrganizationalStructure', True)
            for structure in data_structures:
                if structure.uid in UIDS:
                    UIDS.remove(structure.uid)
            
            result = [i for i in results_catalog if i.UID in UIDS]
            result = IContentListing(result)
            result = Batch(result, b_size, b_start)
        else:   
            result = super(UpdatedSearchView,self).results(query=query,batch=batch,b_size=b_size, b_start=b_start)

#         query.update(query)

        return result, results_pessoas