def search(cls, index_type, account, q, page, page_size, sort=None): if not index_type in ['article', 'journal', 'application']: raise DiscoveryException("There was an error executing your query for {0}. Unknown type.)".format(index_type)) if index_type == 'article': endpoint = 'search_articles' klass = models.Article elif index_type == 'journal': endpoint = 'search_journals' klass = models.Journal else: endpoint = 'search_applications' klass = models.Suggestion raw_query, page, page_size = cls._make_query(q, page, page_size, sort, index_type, False) # execute the query against the articles query_service = DOAJ.queryService() res = query_service.search('api_query', index_type, raw_query, account, None) # check to see if there was a search error if res.get("error") is not None: magic = uuid.uuid1() app.logger.error("Error executing discovery query search for {i}: {x} (ref: {y})".format(i=index_type, x=res.get("error"), y=magic)) raise DiscoveryException("There was an error executing your query (ref: {y})".format(y=magic)) obs = [klass(**raw) for raw in esprit.raw.unpack_json_result(res)] return cls._make_response(endpoint, res, q, page, page_size, sort, obs)
def query(path=None): """ Query endpoint for general queries via the web interface. Calls on the DOAJ.queryService for action :param path: :return: """ pathparts = request.path.strip('/').split('/') if len(pathparts) < 2: abort(400) domain = pathparts[0] index_type = pathparts[1] q = None # if this is a POST, read the contents out of the body if request.method == "POST": q = request.json # if there is a source param, load the json from it elif 'source' in request.values: q = json.loads(urllib.parse.unquote(request.values['source'])) try: account = None if current_user is not None and not current_user.is_anonymous: account = current_user._get_current_object() queryService = DOAJ.queryService() res = queryService.search(domain, index_type, q, account, request.values) except exceptions.AuthoriseException as e: abort(403) except exceptions.NoSuchObjectException as e: abort(404) resp = make_response(json.dumps(res)) resp.mimetype = "application/json" return resp
def query(path=None): """ Query endpoint for general queries via the web interface. Calls on the DOAJ.queryService for action :param path: :return: """ pathparts = request.path.strip('/').split('/') if len(pathparts) < 2: abort(400) domain = pathparts[0] index_type = pathparts[1] q = None # if this is a POST, read the contents out of the body if request.method == "POST": q = request.json # if there is a source param, load the json from it elif 'source' in request.values: q = json.loads(urllib2.unquote(request.values['source'])) try: account = None if current_user is not None and not current_user.is_anonymous: account = current_user._get_current_object() queryService = DOAJ.queryService() res = queryService.search(domain, index_type, q, account, request.values) except exceptions.AuthoriseException as e: abort(403) except exceptions.NoSuchObjectException as e: abort(404) resp = make_response(json.dumps(res)) resp.mimetype = "application/json" return resp
def scroll(cls, index_type, account, q, page_size, sort=None, scan=False): if not index_type in ['article', 'journal', 'application']: raise DiscoveryException("There was an error executing your query for {0}. Unknown type.)".format(index_type)) page = 1 # Not used in scroll raw_query, page, page_size = cls._make_query(q, page, page_size, sort, index_type, True) # execute the query against the articles query_service = DOAJ.queryService() for result in query_service.scroll('api_query', index_type, raw_query, account, page_size, scan=scan): yield result