I want to essentially build my own search bar into wikipedia's api. Given a string entered by a user, it should return the first section from the wikipedia page that best matches that search string.
It works perfectly if the title entered is exactly the right page, but if there is a typo or similar, it returns an xml file with no content.
This is the url I am using to query: http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&rvsection=0&titles=TITLE_GOES_HERE&format=xml
An example would be looking for the page on civil engineering. (http://en.wikipedia.org/wiki/Civil_engineering)
If I search on wikipedia for civil engineering I can find it no problem. Same thing goes for if I search for it with my url: http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&rvsection=0&titles=civil+engineering&format=xml
Then, if I were to mistype my search string to, say, "civul engineering" on wikipedia, it says " there is no page matching that - did you mean 'civil engineering'? " which I can click to go the proper page. (http://en.wikipedia.org/w/index.php?search=civul+engineering&title=Special%3ASearch&go=Go)
However, if I make the same mistake in my query url, it returns the following xml:
<api>
<query>
<normalized>
<n from="civul engineering" to="Civul engineering"/>
</normalized>
<pages>
<page ns="0" title="Civul engineering" missing=""/>
</pages>
</query>
</api>
There are no suggested redirects or anything. How can I pull the closest result rather than only the result that matches the string exactly?