Kaynağa Gözat

WIP: adding faceting for country and year to main search

solr_update
Simon Bowie 2 yıl önce
ebeveyn
işleme
0aee36643c
3 değiştirilmiş dosya ile 12 ekleme ve 4 silme
  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 Dosyayı Görüntüle

@@ -28,8 +28,10 @@ def basic_search():
search_results = solr.content_search(core, sort, search)
results = search_results[0]
num_found = search_results[1]
country_facet = search_results[2]
year_facet = search_results[3]
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:
return redirect(url_for('main.index'))


+ 5
- 3
web/app/solr.py Dosyayı Görüntüle

@@ -24,9 +24,9 @@ def content_search(core, sort, search=None, id=None):
solrurl = 'http://' + solr_hostname + ':' + solr_port + '/solr/' + core + '/select?q.op=OR&q=id%3A"' + id + '"&wt=json'
else:
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:
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
request = requests.get(solrurl)
@@ -47,7 +47,9 @@ def content_search(core, sort, search=None, id=None):
# parse result
result_output = parse_result(id, content)
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):


+ 4
- 0
web/app/templates/search.html Dosyayı Görüntüle

@@ -34,6 +34,10 @@
</form>
</div>

{{country_facet}}

{{year_facet}}

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

{{ results }}

Yükleniyor…
İptal
Kaydet