Example #1
0
    def get_context_data(self, **kwargs):
        ctx = super(SearchMixin, self).get_context_data(**kwargs)

        query = None
        results_count_context_name = self.results_context_name + "_count"

        filters = self.get_filters()
        q = self.get_keywords()

        # The API wrapper should possibly handle the need for the following ifs
        if q or filters:
            query = Index(name=self.index_name).search(self.document_class)

        if query:
            if q:
                query = query.keywords(q)
            if filters:
                query = query.filter(**filters)

            ctx[self.results_context_name] = query[: self.results_limit]
            ctx[results_count_context_name] = query.count()

        ctx[self.query_param_name] = q
        ctx[self.filters_context_name] = filters
        ctx.setdefault(self.results_context_name, [])
        ctx.setdefault(results_count_context_name, 0)

        return ctx
Example #2
0
    def search_projects(self, request):
        """
            API Endpoint to quick search user projects.

            TODO: This endpoint may need extending to search all
            public projects at a global level at some point. However, this
            means adding more context to the ProjectDocument search index.
            We are trying to keep them small and only add fields as required.
            For now this will suit our needs.

            DEPERECATED
            -----------
            This code is currently deprecated as this search has been removed
            from all designs and concepts along with the PRD. Leaving code here
            in case the client decides to re-implement at some point in the
            future.
        """
        projects = []
        search_query = Index(name='projects').search(ProjectDocument)

        if request.q:
            search_query = search_query.keywords(request.q)

        for p in search_query.filter(
                assigned_users=self.current_user.pk)[:1000]:
            projects.append(self.project_index_mapper.map(p))
        return OneSearchProjectListResponse(items=projects, is_list=True)