def search(self, q, *args, **kwargs):
        """
        Performs the search and massages data into schema.org JSON-LD. If
        you pass in raw=True you will get the raw summon response instead.
        """
        t = datetime.now()
        summon_response = self._summon.search(q, *args, **kwargs)
        elapsed = datetime.now() - t
        logging.debug("summon %s: %s: %s - %s", q, args, kwargs, elapsed)

        # calculate some things to include in our response that Summon
        # responses don't explicitly include
        total_results = summon_response['recordCount']
        page = kwargs.get("pn", 1)
        items_per_page = kwargs.get("ps", 10)
        start_index = items_per_page - (page * items_per_page)

        # return raw Summon response if that's what they want
        if kwargs.get("raw", False):
            return summon_response

        # django templates don't use @ prefixed parameters from json-ld
        for_template = kwargs.get('for_template', False)

        response = {
            "query": q,
            "totalResults": total_results,
            "itemsPerPage": items_per_page,
            "startIndex": start_index,
            "results": []
        }

        # summarize facets
        if 'facetFields' in summon_response:
            response['facets'] = []
            for ff in summon_response['facetFields']:
                facet = {'name': ff['displayName'], 'counts': []}
                for c in ff['counts']:
                    facet['counts'].append({
                        'name': c['value'],
                        'count': c['count']
                    })
                response['facets'].append(facet)

        seen = {}
        for doc in summon_response['documents']:
            item = self._convert(doc)
            if item:
                # only include items that are held by a library
                if len(item['offers']) == 0:
                    continue
                # sometimes (rarely) the same item appears more than once?
                # e.g. search for "statistics"
                if item['@id'] in seen:
                    continue
                seen[item['@id']] = True
                if for_template:
                    item['id'] = item.pop('@id')
                    item['type'] = item.pop('@type')
                response['results'].append(item)

        return response
dataset/ETHPy150Open gwu-libraries/launchpad/lp/ui/summon.py/Summon.search/swapped operands of `-`