On Wed, Jul 26, 2017 at 4:05 PM, Stas Malyshev smalyshev@wikimedia.org wrote:
Another note is that you can call wbsearchentities from SPARQL:
(...)
Not sure whether it fits your use case or not, but offering it as one more option.
Hi Stas,
Thanks for the tips & pointer to the MW API integration. It may be possible to replace the two queries powering my autocomplete box with a single WDQS query, which seems like a major potential improvement.
My main problem with the example query below is that, with the filter condition, it messes up the original sort order as returned by the API. Can you think of a way to preserve the sort order?
Thanks again for all the helpful tips, Erik
SELECT * WHERE { FILTER NOT EXISTS { # Excluded classes: disambiguation pages, Wikinews articles, etc. { ?item wdt:P31 wd:Q4167410 } UNION { ?item wdt:P31 wd:Q17633526 } UNION { ?item wdt:P31 wd:Q11266439 } UNION { ?item wdt:P31 wd:Q4167836 } UNION { ?item wdt:P31 wd:Q14204246 } } SERVICE wikibase:mwapi { bd:serviceParam wikibase:api "EntitySearch" . bd:serviceParam wikibase:endpoint "www.wikidata.org" . bd:serviceParam mwapi:search "revival" . bd:serviceParam mwapi:language "en" . bd:serviceParam mwapi:uselang "en" . bd:serviceParam mwapi:limit 50 . ?item wikibase:apiOutputItem mwapi:item . ?label wikibase:apiOutput "@label" . ?matchType wikibase:apiOutput "match/@type" . ?matchLang wikibase:apiOutput "match/@language" . ?matchText wikibase:apiOutput "match/@text" . ?description wikibase:apiOutput "@description" . } }