Reputation: 724
I've been trying to get a list of possible results (same you would get as you perform a search in Wikipedia) and a small summary of the article, usually the first paragraph.
So far all I can get is either the list of titles:
or the summary for a single page:
Is it possible to combine both these queries in a form similar to this
or will I have to iterate all results from the first query and then get the extract for each one?
Upvotes: 2
Views: 1078
Reputation: 7036
You can combine the results from two or more queries by using generator parameter. So the idea is to generate a list of search results (your first query) including extracts property for each one result (your second query):
action=query&generator=search&prop=extracts
Then we need to add some parameters for generator (all they prefixed with a "g")
gsrsearch=Albert%20Einstein&gsrlimit=20
and parameters for all query properties (in our case only for extracts):
exintro=1&explaintext=1&exchars=250&exlimit=20
The final query will be:
https://en.wikipedia.org/w/api.php?action=query&origin=*&generator=search&prop=extracts&gsrsearch=Albert%20Einstein&gsrlimit=20&exintro=1&explaintext=1&exchars=350&exlimit=20
Upvotes: 2