...

Google App Engine: The Search API


by Phil Plante on September 26, 2014

Google App Engine is a Platform as a Service (PAAS) for developing and hosting web applications on Google's infrastructure. It removes much of the pain involved with provisioning, configuring, and maintaining servers for running a web site. Google consistently adds new features to the App Engine platform, and one of the best is the Search API.

Have you ever visited a site and the site's search feature is so slow, or the results so inaccurate, that you instead run the search from Google, and the Google search results are faster and more accurate. The App Engine Search API let's you perform Google-like full-text searches on pages and structures on your site. Your searches will be lighting fast and can span multiple fields from a database.

So if you have an App Engine site with lots of pages or an expansive catalog of products, it's a good idea to optimize the site for Search using the App Engine Search API.

App Engine Search API Example

We recently built a site for a new startup here in Williamsburg, Rev City Sports. Rev City Sports is a news site covering local sports.

Rev City Sports is updated with new articles frequently, and recent articles can scroll off the home page within a couple of days. Articles are assigned to categories to help organize them into groups, but sometimes a user doesn't want to browse general groups, he or she wants to run a quick search for a specific phrase, for example an athlete's name.

Here's where the Search API comes to the rescue. Simply type a word or group of words into the Search box, and the application uses the Search API to find matches across all of the articles on the site.

How does it work

When a new article is added to the site, it's also indexed for searching. Wow, that's sounds tricky, how is an article indexed for searching? Well, if you had to do this complete on your own it would be the house of pain. Fortunately the Search API handles much of this for you.

I'm not going to get into all of the details, it's best to consult the documents for that, but at a high level here's what you need to do:

  • Create a search document and add the information you'd like to make searchable, like product names, inventory numbers, or even pages of html.
  • Add that document to an index.
  • Search the index for a word or groups of words. Matching documents are found and returned. Display those results to the user.
Obviously there's a bit more to the implementation, but from the high level that's the gist of it. If you need to add full-text search to your site, the App Engine Search API abstracts much of the low-level pain.