Replace $search with $in for mongodb v2.4.

        This is a workaround for mongo v2.4 not supporting the $search keyword.
        This workaround is hardcoded specifically for the 'q' query param. The
        text search is executed first and the ids of the found documents are
        used to replace the $search filter with a $in filter.

def search_alternative(self, limit, **kwargs):
        """Replace $search with $in for mongodb v2.4.

        This is a workaround for mongo v2.4 not supporting the $search keyword.
        This workaround is hardcoded specifically for the 'q' query param. The
        text search is executed first and the ids of the found documents are
        used to replace the $search filter with a $in filter.
        """
        search_term = kwargs['$or'][0]['$text']['$search']
        response = self._collection.database.command(
            'text', self._collection.name,
            search=search_term,
            project={'_id': 1},
            limit=limit
        )
        id_list = [e['obj']['_id'] for e in response['results']]
        kwargs['$or'][0] = {'_id': {'$in': id_list}}
        return kwargs