Browse Source

WIP: adding faceting for country and year to main search

solr_update
Simon Bowie 2 years ago
parent
commit
0aee36643c
3 changed files with 12 additions and 4 deletions
  1. +3
    -1
      web/app/search.py
  2. +5
    -3
      web/app/solr.py
  3. +4
    -0
      web/app/templates/search.html

+ 3
- 1
web/app/search.py View File

search_results = solr.content_search(core, sort, search) search_results = solr.content_search(core, sort, search)
results = search_results[0] results = search_results[0]
num_found = search_results[1] num_found = search_results[1]
country_facet = search_results[2]
year_facet = search_results[3]
total_number = solr.get_total_number(core) total_number = solr.get_total_number(core)
return render_template('search.html', results=results, num_found=num_found, total_number=total_number, search=search, core=core, sort=sort)
return render_template('search.html', results=results, num_found=num_found, total_number=total_number, country_facet=country_facet, year_facet=year_facet, search=search, core=core, sort=sort)
else: else:
return redirect(url_for('main.index')) return redirect(url_for('main.index'))



+ 5
- 3
web/app/solr.py View File

solrurl = 'http://' + solr_hostname + ':' + solr_port + '/solr/' + core + '/select?q.op=OR&q=id%3A"' + id + '"&wt=json' solrurl = 'http://' + solr_hostname + ':' + solr_port + '/solr/' + core + '/select?q.op=OR&q=id%3A"' + id + '"&wt=json'
else: else:
if (sort == 'relevance'): if (sort == 'relevance'):
solrurl = 'http://' + solr_hostname + ':' + solr_port + '/solr/' + core + '/select?q.op=OR&q=content%3A' + urllib.parse.quote_plus(search) + '&wt=json'
solrurl = 'http://' + solr_hostname + ':' + solr_port + '/solr/' + core + '/select?q.op=OR&q=content%3A' + urllib.parse.quote_plus(search) + '&wt=json&facet.field=country&facet.field=year&facet.sort=count&facet=true'
else: else:
solrurl = 'http://' + solr_hostname + ':' + solr_port + '/solr/' + core + '/select?q.op=OR&q=content%3A' + urllib.parse.quote_plus(search) + '&wt=json&sort=' + sort
solrurl = 'http://' + solr_hostname + ':' + solr_port + '/solr/' + core + '/select?q.op=OR&q=content%3A' + urllib.parse.quote_plus(search) + '&wt=json&sort=' + sort + '&facet.field=country&facet.field=year&facet.sort=count&facet=true'


# get result # get result
request = requests.get(solrurl) request = requests.get(solrurl)
# 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, num_found
country_facet = json['facet_counts']['facet_fields']['country']
year_facet = json['facet_counts']['facet_fields']['year']
return output, num_found, country_facet, year_facet


def term_search(core, sort, field, input): def term_search(core, sort, field, input):



+ 4
- 0
web/app/templates/search.html View File

</form> </form>
</div> </div>


{{country_facet}}

{{year_facet}}

{% if results == 'no results found' %} {% if results == 'no results found' %}


{{ results }} {{ results }}

Loading…
Cancel
Save