Page MenuHomePhabricator

Add ordinal variable to MWAPI service calls
Closed, ResolvedPublic

Description

Following the discussion at https://www.mediawiki.org/wiki/Topic:Tyz12m2b02qjhbuh, it may be needed to see in which order the results are returned from MWAPI - this may be relevant for search results, etc. Since the following joins may not preserve order, it may be useful to capture the order into a variable, such as:

?ordinal wikibase:apiOrdinal true .

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Smalyshev triaged this task as Medium priority.Oct 3 2017, 6:49 AM

Change 388287 had a related patch set uploaded (by Smalyshev; owner: Smalyshev):
[wikidata/query/rdf@master] Add option to fetch ordinal of the result in MWAPI query:

https://gerrit.wikimedia.org/r/388287

Change 388287 merged by jenkins-bot:
[wikidata/query/rdf@master] Add option to fetch ordinal of the result in MWAPI query:

https://gerrit.wikimedia.org/r/388287

Smalyshev claimed this task.
Smalyshev updated the task description. (Show Details)

Awesome, thanks very much for your work on this! Seems to work exactly as advertised and should make it possible to build some nicer suggesters with a single query. :)

It seems that ORDER BY ?ordinal in combination with mwapi:srlimit leads to perfomance degradation. Try the following with and without bd:serviceParam mwapi:srlimit 20 (or "20"):

SELECT * WHERE {
  SERVICE wikibase:mwapi {
      bd:serviceParam wikibase:api "Search" .
      bd:serviceParam wikibase:endpoint "www.wikidata.org"  .
      bd:serviceParam mwapi:srsearch "Merkel" .
      bd:serviceParam mwapi:srlimit 20 .
      ?item wikibase:apiOutputItem "@title" .
      ?ordinal wikibase:apiOrdinal true .
  }
  ?item wdt:P31 ?type .
} ORDER BY ASC (?ordinal) LIMIT 10

@Luitzen you may want to use bd:serviceParam wikibase:limit 20 .. With it, the query runs for 335 ms for me.