Google Knowledge Graph Search

Recently, I built out a quick search widget using the Google Knowledge Graph Search Widget. The widget is a Javascript module that allows you to add topics to your input fields (I’ve limited mine to People) such as Movies, Places, etc. When a user starts typing, the widget finds a relevant match and it’s rendered to the DOM.

In this project, I called the KGSearchWidget() passed in a configuration object, limiting the language, type (here I chose Person) and event handler for selecting an item. In the config variable, I limit the number of results in the dropdown, the language searched, the entity type I want returned and the maximum number of characters in the description of each entity.

var config = {
  'limit': 10,
  'languages': ['en'],
  'types': ['Person'],
  'maxDescChars': 100,
};

config['selectHandler'] = function(e) {
  console.log(e.row);

  artObject = {
    name: e.row.name,
    desc: e.row.description,
    content: e.row.json.detailedDescription.articleBody,
    url: e.row.json.detailedDescription.url,
    image: e.row.json.image.contentUrl
  }
}

KGSearchWidget(KG_API, document.getElementById("myInput"), config);