def get(self, request, *args, **kwargs): """ Constructs a SolrSearch object using the search request; specifically, it parses and prepares the query and assigns it to s note: Filters, sorts, and other modifiers to solr search are handled in the helper script solrsearch.py :param request: :param args: :param kwargs: :return: """ s = SolrSearch(request) user = self.request.user # Filter out hidden pieces and movements if the user is not super. if not user.is_superuser: s.solr_params['fq'].append('hidden:False') # TODO add here when facets are decided facets = s.facets(facet_fields=['type', 'composer_name', 'tags', 'parent_collection_names', 'number_of_voices']) facets.facet_counts['facet_fields'] = parse_facets(facets) # Do the search. search_results = s.search() # Paginate results paginator = paginate.SolrPaginator(search_results) paged_results = get_paged_results(paginator, get_page_number(request)) try: result = paged_results.__dict__ except AttributeError: return Response({'object_list': []}, status=status.HTTP_200_OK) # Format the results format_search_result(result, facets, paginator, request) return Response(result, status=status.HTTP_200_OK)
def get(self, request, *args, **kwargs): """ Constructs a SolrSearch object using the search request; specifically, it parses and prepares the query and assigns it to s note: Filters, sorts, and other modifiers to solr search are handled in the helper script solrsearch.py :param request: :param args: :param kwargs: :return: """ # Grab the cart cart = request.session.get('cart', {}) # Set up the Solr connection s = SolrSearch(request) facets = s.facets(facet_fields=['type', 'composer_name', 'tags', 'parent_collection_names', 'number_of_voices']) facets.facet_counts['facet_fields'] = parse_facets(facets) user = self.request.user if user.is_superuser: search_results = s.search() else: search_results = s.search(fq='*:* AND !hidden:True') #search_results.append(s.search(fq='creator:user')) # Paginate results paginator = paginate.SolrPaginator(search_results) # Loop through the result pages and add everything to the cart total = 0 cart = ElvisCart(request) for page_number in range(paginator.num_pages): results = paginator.page(page_number + 1).result # Get the items from the page for search_object in (r for r in results if r in ElvisCart.ACCEPTABLE_TYPES): cart.add_item({'item_type': search_object["type"], 'id': search_object["uuid"]}) total += 1 # Save the modified cart cart.save() return Response({"count": len(cart)}, status=status.HTTP_200_OK)