From 19e82a34cdfca1b3c7749f8cb5d490b3c5a72eef Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 27 Nov 2019 12:42:07 +0000 Subject: [PATCH] Optimize browse page facet query --- app.py | 2 ++ templates/query/facet.sparql | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index acf78fe..b40655a 100755 --- a/app.py +++ b/app.py @@ -572,6 +572,8 @@ def get_facets(params): label = row['objectLabel']['value'] count = int(row['count']['value']) + if pid not in find_more_props: + continue facets[pid].append({'qid': qid, 'label': label, 'count': count}) return { diff --git a/templates/query/facet.sparql b/templates/query/facet.sparql index 3699fd6..8ff8a9f 100644 --- a/templates/query/facet.sparql +++ b/templates/query/facet.sparql @@ -1,11 +1,11 @@ select ?property ?object ?objectLabel (count(*) as ?count) { - SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } - VALUES ?isa { {% for isa in isa_list %} wd:{{ isa }} {% endfor %} } + service wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } + values ?isa {{% for isa in isa_list %} wd:{{ isa }} {% endfor %}} ?item wdt:P31 ?isa . ?item wdt:P18 ?image . {% for pid, qid in params %} - ?item wdt:{{pid}} wd:{{qid}} . + ?item wdt:{{pid}} wd:{{qid}} . {% endfor %} - values ?property { {% for pid in properties %} wdt:{{pid}}{% endfor %} } + filter (strstarts(str(?property), "http://www.wikidata.org/prop/direct/P") ) ?item ?property ?object . } group by ?property ?propertyLabel ?object ?objectLabel