From 87b34eb567b5c65583308d3cb3a9ad68d8207cc5 Mon Sep 17 00:00:00 2001 From: Rachel Kim Date: Tue, 5 May 2020 21:41:46 -0400 Subject: [PATCH] merged with api --- cce_search/__init__.py | 3 +- cce_search/api.py | 10 +++++ cce_search/search.py | 100 ++++++++++++++++++++++++----------------- 3 files changed, 70 insertions(+), 43 deletions(-) diff --git a/cce_search/__init__.py b/cce_search/__init__.py index ba98f0d..abdc7d3 100644 --- a/cce_search/__init__.py +++ b/cce_search/__init__.py @@ -8,7 +8,8 @@ def create_app(test_config=None): app.config.from_mapping( SECRET_KEY='dev', #DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'), - API='http://sfr-bardo-copyright-development.us-east-1.elasticbeanstalk.com', + API='http://localhost:5000/', + # API='http://sfr-bardo-copyright-development.us-east-1.elasticbeanstalk.com', ) if test_config is None: diff --git a/cce_search/api.py b/cce_search/api.py index 7092c53..c1a80e0 100644 --- a/cce_search/api.py +++ b/cce_search/api.py @@ -1,6 +1,16 @@ from flask import current_app, g import requests +def new_search(param, page=0, per_page=10): + r = requests.get(current_app.config['API'] + '/search/multi', + params={'title': param["title"], + 'authors': param["authors"], + 'publishers': param["publishers"], + 'source': 'true', + 'page': page, + 'per_page': per_page}) + return r.json() + def search(term, page=0, per_page=10): r = requests.get(current_app.config['API'] + '/search/fulltext', params={'query': term, diff --git a/cce_search/search.py b/cce_search/search.py index 0d81817..4831de1 100644 --- a/cce_search/search.py +++ b/cce_search/search.py @@ -1,4 +1,4 @@ -from cce_search.api import search, reg_search, ren_search, registration, renewal +from cce_search.api import search, reg_search, ren_search, new_search, registration, renewal from flask import ( Blueprint, flash, g, redirect, render_template, request, url_for ) @@ -21,7 +21,8 @@ def index(): tempResults = None tempPaging = None tempArgs = None - + matched_results = [] + params = {} unique = 0 max_page = 0 @@ -43,45 +44,60 @@ def index(): paging = proc_pagination(results['data']['paging'], request.args.get('page')) unique = 1 #technically not 100% unique but should be very simplified for now - if request.args.get("title") and unique == 0: - title = request.args['title'] - tempResults = search(title, request.args.get('page'), - request.args.get('per_page')) - tempPaging = proc_pagination(tempResults['data']['paging'], - request.args.get('page')) - max_page = tempPaging['last_page'] - results = tempResults - paging = tempPaging - tempArgs = request.args['title'] - + if request.args.get("title") and unique==0: + params["title"] = request.args['title'] + else: + params["title"] = "*" if request.args.get("author") and unique == 0: - author = request.args['author'] - tempResults = search(author, request.args.get('page'), - request.args.get('per_page')) - tempPaging = proc_pagination(tempResults['data']['paging'], - request.args.get('page')) - if max_page > tempPaging['last_page'] or max_page == 0: - max_page = tempPaging['last_page'] - results = tempResults - paging = tempPaging - tempArgs = request.args['author'] + params["authors"] = request.args['author'] + else: + params["authors"] = "*" + + if request.args.get("publisher") and unique==0: + params['publishers'] = request.args['publisher'] + else: + params["publishers"] = "*" + + if unique==0: + results = new_search(params, request.args.get('page'), request.args.get('per_page')) + paging = proc_pagination(results['data']['paging'], request.args.get('page')) + # if request.args.get("title") and unique == 0: + # title = request.args['title'] + # tempResults = search(title, request.args.get('page'), + # request.args.get('per_page')) + # tempPaging = proc_pagination(tempResults['data']['paging'], + # request.args.get('page')) + # max_page = tempPaging['last_page'] + # results = tempResults + # paging = tempPaging + # tempArgs = request.args['title'] + + # if request.args.get("author") and unique == 0: + # author = request.args['author'] + # tempResults = search(author, request.args.get('page'), + # request.args.get('per_page')) + # tempPaging = proc_pagination(tempResults['data']['paging'], + # request.args.get('page')) + # if max_page > tempPaging['last_page'] or max_page == 0: + # max_page = tempPaging['last_page'] + # results = tempResults + # paging = tempPaging + # tempArgs = request.args['author'] + # if request.args.get("publisher") and unique == 0: + # publisher = request.args['publisher'] + # tempResults = search(publisher, request.args.get('page'), + # request.args.get('per_page')) + # tempPaging = proc_pagination(tempResults['data']['paging'], + # request.args.get('page')) + # if max_page > tempPaging['last_page'] or max_page == 0: + # max_page = tempPaging['last_page'] + # results = tempResults + # paging = tempPaging + # tempArgs = request.args['publisher'] - if request.args.get("publisher") and unique == 0: - publisher = request.args['publisher'] - tempResults = search(publisher, request.args.get('page'), - request.args.get('per_page')) - tempPaging = proc_pagination(tempResults['data']['paging'], - request.args.get('page')) - if max_page > tempPaging['last_page'] or max_page == 0: - max_page = tempPaging['last_page'] - results = tempResults - paging = tempPaging - tempArgs = request.args['publisher'] - - #Modifed Search Functionality - # matched_results = [] + # #Modifed Search Functionality # for i in range(max_page): # pageResults = proc_results(search(tempArgs, i, 10)) # for obj in pageResults: @@ -129,11 +145,11 @@ def index(): # print(procResults) - # print("PRINTING PAGING HERE") - # print(paging) - # print("----------------------------------------------------------") - # print("DATA PAGING") - # print(results['data']['paging']) + print("PRINTING PAGING HERE") + print(paging) + print("----------------------------------------------------------") + print("DATA PAGING") + print(results['data']['paging']) results = proc_results(results) # print(json.dumps(results))