Search code examples
apimediawikiwikipediawikipedia-apimediawiki-api

True Search and Discover from Wikipedia api


I have a string to search "founder of google"

I use this request link: https://en.wikipedia.org/w/api.php?action=query&list=search&format=json&srwhat=text&rawcontinue&srprop=sectiontitle&srsearch=founder%20of%20google

But it returns


{
   "query-continue":{
      "search":{
         "sroffset":10
      }
   },
   "query":{
      "searchinfo":{
         "totalhits":14577
      },
      "search":[
         {
            "ns":0,
            "title":"Lars Rasmussen (software developer)"
         },
         {
            "ns":0,
            "title":"Wirth's law"
         },
         {
            "ns":0,
            "title":"Brin"
         },
         {
            "ns":0,
            "title":"H\u00e9ctor Garc\u00eda-Molina"
         },
         {
            "ns":0,
            "title":"Chris Wetherell"
         },
         {
            "ns":0,
            "title":"Forbes list of The World's Most Powerful People"
         },
         {
            "ns":0,
            "title":"Tamil American"
         },
         {
            "ns":0,
            "title":"Lars Rasmussen"
         },
         {
            "ns":0,
            "title":"List of Jewish American computer scientists"
         },
         {
            "ns":0,
            "title":"Larry"
         }
      ]
   }
}

But I want only these two true results:

{
   "ns":0,
   "title":"Brin"
},
{
   "ns":0,
   "title":"Larry"
}

Solution

  • (1) - https://www.wikidata.org/w/api.php?action=wbsearchentities&search= google &language=en&type=item&format=json
    
    (2) - https://www.wikidata.org/w/api.php?action=wbsearchentities&search= founder &language=en&type=property&format=json
    
    (3) - https://www.wikidata.org/w/api.php?action=wbgetclaims&entity={id of 1st link}&property={id of 2nd link}&format=json
    
    (4) - https://www.wikidata.org/w/api.php?action=wbgetentities&ids={ numeric-id of 3rd link }&languages=en&format=json&props=labels|descriptions|aliases