sort = request.form.get('sort') | sort = request.form.get('sort') | ||||
else: | else: | ||||
sort = 'relevance' | sort = 'relevance' | ||||
results = solr.solr_search(core, sort, search) | |||||
return render_template('search.html', results=results, search=search, core=core, sort=sort) | |||||
search_results = solr.solr_search(core, sort, search) | |||||
results = search_results[0] | |||||
num_found = search_results[1] | |||||
return render_template('search.html', results=results, num_found=num_found, search=search, core=core, sort=sort) | |||||
# route for id_search page | # route for id_search page | ||||
@search.route('/search/id/') | @search.route('/search/id/') | ||||
else: | else: | ||||
sort = 'relevance' | sort = 'relevance' | ||||
id = request.args.get('id') | id = request.args.get('id') | ||||
results = solr.solr_search(core, sort, search, id) | |||||
search_results = solr.solr_search(core, sort, search, id) | |||||
results = search_results[0] | |||||
for result in results: | for result in results: | ||||
publication_details = ops.get_publication_details(result['doc_ref']) | publication_details = ops.get_publication_details(result['doc_ref']) |
# turn the API response into useful Json | # turn the API response into useful Json | ||||
json = request.json() | json = request.json() | ||||
if (json['response']['numFound'] == 0): | |||||
num_found = json['response']['numFound'] | |||||
if (num_found == 0): | |||||
output = 'no results found' | output = 'no results found' | ||||
else: | else: | ||||
output = [] | output = [] | ||||
# parse result | # parse result | ||||
result_output = parse_result(id, content) | result_output = parse_result(id, content) | ||||
output.append(result_output) | output.append(result_output) | ||||
return output | |||||
return output, num_found | |||||
def parse_result(id, input): | def parse_result(id, input): | ||||
<p class="mt-2 text-center">a <span id="time"></span> minute read out of 6375081 minutes reading time</p> | <p class="mt-2 text-center">a <span id="time"></span> minute read out of 6375081 minutes reading time</p> | ||||
<a href="{{ url_for('main.index') }}" class="h1 text-left"> ⇽ </a> | <a href="{{ url_for('main.index') }}" class="h1 text-left"> ⇽ </a> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<div id="alltext"> | <div id="alltext"> |
<div class="col m-5"> | <div class="col m-5"> | ||||
<a href="{{ url_for('main.index') }}" class="h1 text-left"> ⇽ </a> | <a href="{{ url_for('main.index') }}" class="h1 text-left"> ⇽ </a> | ||||
<p class="h1 text-center">a timeline of inventions</p> | <p class="h1 text-center">a timeline of inventions</p> | ||||
<p class="mt-2 text-center">{{ num_found }} patents found out of 320,000</p> | |||||
</div> | </div> | ||||
</div> | </div> | ||||