| @@ -77,9 +77,35 @@ def country_search(): | |||
| core = 'all' | |||
| if sort is None: | |||
| sort = 'relevance' | |||
| search_results = solr.country_search(core, sort, country_code) | |||
| field = 'country' | |||
| search_results = solr.term_search(core, sort, field, country_code) | |||
| results = search_results[0] | |||
| num_found = search_results[1] | |||
| total_number = solr.get_total_number(core) | |||
| return render_template('search.html', results=results, num_found=num_found, total_number=total_number, country_code=country_code, core=core, sort=sort) | |||
| # route for year search page | |||
| @search.route('/search/year/', methods=['GET', 'POST']) | |||
| def year_search(): | |||
| if request.method == 'POST': | |||
| year = request.form.get('year') | |||
| core = request.form.get('core') | |||
| sort = request.form.get('sort') | |||
| else: | |||
| year = request.args.get('year') | |||
| core = request.args.get('core') | |||
| sort = request.args.get('sort') | |||
| if year is None: | |||
| return redirect(url_for('main.index')) | |||
| if core is None: | |||
| core = 'all' | |||
| if sort is None: | |||
| sort = 'relevance' | |||
| field = 'year' | |||
| search_results = solr.term_search(core, sort, field, year) | |||
| results = search_results[0] | |||
| num_found = search_results[1] | |||
| total_number = solr.get_total_number(core) | |||
| return render_template('search.html', results=results, num_found=num_found, total_number=total_number, year=year, core=core, sort=sort) | |||
| @@ -49,13 +49,13 @@ def content_search(core, sort, search=None, id=None): | |||
| output.append(result_output) | |||
| return output, num_found | |||
| def country_search(core, sort, country_code): | |||
| def term_search(core, sort, field, input): | |||
| # Assemble a query string to send to Solr. This uses the Solr hostname from config.env. Solr's query syntax can be found at many sites including https://lucene.apache.org/solr/guide/6_6/the-standard-query-parser.html | |||
| if (sort == 'relevance'): | |||
| solrurl = 'http://' + solr_hostname + ':' + solr_port + '/solr/' + core + '/select?q.op=OR&q=%7B!term%20f%3Dcountry%7D' + country_code + '&wt=json' | |||
| solrurl = 'http://' + solr_hostname + ':' + solr_port + '/solr/' + core + '/select?q.op=OR&q=%7B!term%20f%3D' + field + '%7D' + input + '&wt=json' | |||
| else: | |||
| solrurl = 'http://' + solr_hostname + ':' + solr_port + '/solr/' + core + '/select?q.op=OR&q=%7B!term%20f%3Dcountry%7D' + country_code + '&wt=json&sort=' + sort | |||
| solrurl = 'http://' + solr_hostname + ':' + solr_port + '/solr/' + core + '/select?q.op=OR&q=%7B!term%20f%3D' + field + '%7D' + input + '&wt=json&sort=' + sort | |||
| # get result | |||
| request = requests.get(solrurl) | |||
| @@ -14,7 +14,9 @@ There are a total of {{ total_number }} patents. | |||
| {% if i % 2 %} | |||
| {{ year_data[i] }}<br> | |||
| {% else %} | |||
| {{ year_data[i] }}: | |||
| <a href="{{ url_for('search.year_search', year=year_data[i]) }}"> | |||
| {{ year_data[i] }}: | |||
| </a> | |||
| {% endif %} | |||
| {% endfor %} | |||
| </div> | |||
| @@ -17,6 +17,9 @@ | |||
| {% elif country_code is defined %} | |||
| <form action="{{ url_for('search.country_search') }}" method="POST"> | |||
| <input type="hidden" name="country_code" value="{{ country_code }}"> | |||
| {% elif year is defined %} | |||
| <form action="{{ url_for('search.year_search') }}" method="POST"> | |||
| <input type="hidden" name="year" value="{{ year }}"> | |||
| {% endif %} | |||
| <input type="hidden" name="searchopt" value="{{ core }}"> | |||
| sort by: | |||