Skip to content
Snippets Groups Projects
Commit 75f00695 authored by anonymous's avatar anonymous
Browse files

ODPSH-6: reimplement qa search

parent 38e6fb85
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -329,3 +329,18 @@ msgstr "mehr anzeigen"
msgid "Show Less"
msgstr "weniger anzeigen"
msgid "0OL"
msgstr "offene Lizenz"
msgid "1RE"
msgstr "maschinenlesbar"
msgid "2OF"
msgstr "offenes Format"
msgid "3URI"
msgstr "verwendet URIs"
msgid "4LD"
msgstr "Linked Data"
\ No newline at end of file
......@@ -349,7 +349,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
return OrderedDict({'organization': _('Herausgeber'),
'res_format': _('Dateiformat'),
'license_title': _('Lizenz'),
'groups': _('Kategorie')})
'groups': _('Kategorie'),
'openness': _('Open-Data-Eigenschaften')})
def organization_facets(self, facets_dict, organization_type, package_type):
return OrderedDict({'organization': _('Herausgeber'),
......@@ -423,20 +424,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
'odsh_validate_temporal_end': odsh_validate_extra_date_factory('temporal_end'),
'odsh_tag_name_validator': odsh_tag_name_validator}
def process_score_in_search_params(self,search_params):
extras = search_params.get('extras')
score = 0
for i in range(1,6):
if extras.get('ext_score_'+str(i)):
score = max([score,i])
if score>0:
fq = search_params['fq']
fq = "{fq} qa:/.*'openness_score':.[{score}-5].*/".format(fq=fq, score=i)
search_params['fq'] = fq
# Add the custom parameters to Solr's facet queries
# use several daterange queries agains temporal_start and temporal_end field
# TODO: use field of type date_range in solr index instead
......@@ -447,15 +434,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
# There are no extras in the search params, so do nothing.
return search_params
self.process_score_in_search_params(search_params)
fq = search_params['fq']
score = extras.get('ext_score')
if score:
fq = "{fq} qa:/.*'openness_score':.[{score}-5].*/".format(fq=fq, score=score)
search_params['fq'] = fq
start_date=None
end_date=None
try:
......@@ -511,6 +491,21 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
return search_params
scores = [ ['0OL'], ['0OL','1RE'], ['0OL','1RE','2OF'], ['0OL','1RE','2OF','3URI'], ['0OL','1RE','2OF','3URI','4LD']]
def map_qa_score(self, dict_pkg):
if 'validated_data_dict' in dict_pkg and 'openness_score' in dict_pkg['validated_data_dict']:
d = json.loads(dict_pkg['validated_data_dict'])
score = -1
for r in d['resources']:
if 'qa' in r:
i = r['qa'].find('openness_score')
s = int(r['qa'][i+17])
if s > score:
score=s
if score > 0:
dict_pkg['openness']=OdshPlugin.scores[score-1]
def before_index(self, dict_pkg):
# make special date fields solr conform
fields = ["issued", "temporal_start", "temporal_end"]
......@@ -518,9 +513,12 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
field = 'extras_' + field
if field in dict_pkg and dict_pkg[field]:
d = parse(dict_pkg[field])
dict_pkg[field] = '{0.year:4d}-{0.month:02d}-{0.day:02d}T00:00:00Z'.format(
d)
dict_pkg[field] = '{0.year:4d}-{0.month:02d}-{0.day:02d}T00:00:00Z'.format(d)
# if 'res_format' in dict_pkg:
# dict_pkg['res_format']=[e.lower() for e in dict_pkg['res_format']]
self.map_qa_score(dict_pkg)
return dict_pkg
\ No newline at end of file
......@@ -102,29 +102,6 @@ default_extent="{ \"type\": \"Polygon\", \"coordinates\": [[[7.6574,53.1632],[11
</nav>
</section>
{% endblock %}
{% block qa_search%}
<section class="module module-narrow module-shallow">
<nav>
<div class="nav-title">{{_('Score')}}</div>
<ul class="unstyled nav nav-simple nav-facet">
{% set titles=['offene Lizenz', 'maschinenlesbar', 'offenes Format', 'verwendet URIs', 'Linked Data'] %}
{%- for stars in range(1,6)-%}
{%- set score = request.params['ext_score_'+stars|string]=='on'-%}
<li class='nav-item'>
<div class='facet_label'>
<input name='ext_score_{{stars}}' type="checkbox" {% if score %} checked {% endif %} class="filter-checkbox" id="check-score-{{stars}}"/>
<label class='label-score label-score-{{stars}}' for='check-score-{{stars}}'></label>
<div class='search-score search-score-{{stars}}' title="offene Lizenz">
<span>{{titles[stars-1]}}</span>
</div>
</div>
</li>
{%- endfor -%}
</ul>
</nav>
</section>
{% endblock %}
</div>
{% endblock %}
......
......@@ -18,6 +18,9 @@
item.active else h.add_url_param(new_params={name: item.name}, extras=extras, alternative_url=alternative_url)
%}
{% set label = label_function(item) if label_function else item.display_name %}
{% if title=='Open-Data-Eigenschaften'%}
{% set label = _(label)%}
{% endif%}
{% set count = count_label(item['count']) if count_label else ('%d' % item['count']) %}
{% set label_truncated = h.truncate(label, 25) if not label_function else label %}
<li class="{{ nav_item_class or 'nav-item' }}">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment