Search code examples
mediawiki-api

MediaWiki API: search pages by keyword and fetch information


I'm using wiki api to embed search on my site. User types some keyword, then script searches pages connected to keyword and displays thumbnail/title/description/categories (example: http://drive.google.com/uc?export=view&id=0B77izt5MEPt2TUw3eUEyVVg3SUE)

Now I'm using:

GET //en.wikipedia.org/w/api.php?action=query&list=search&srsearch=KEYWORD

foreach TITLE:
  GET //en.wikipedia.org/w/api.php?action=query&titles=TITLE&prop=extracts|pageimages|categories&exchars=300

Works fine, but the amount of api calls is too big. So I'm looking for some way to optimize it. It's possible to pass multiple titles in second GET, but the wiki server will split response (using continue) so there are no difference.

Any ideas?


Solution

  • Have a look at how generators work:

    action=query&prop=categories|extracts|pageimages&format=json&exlimit=500&exintro=&explaintext=&exsectionformat=plain&piprop=thumbnail&pithumbsize=1000&pilimit=500&generator=search&redirects=&gsrsearch=doom&gsrnamespace=0&gsrwhat=text