Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Installing an Example Search API Application

Learning objectives

Prerequisites

Related

Amy Unruh, Oct 2012
Google Developer Relations

Introduction

In this lesson we'll install a sample Product Search application. This helps you check that you are set up to successfully develop and deploy an App Engine application, and gives you a platform for experimentation with the Search API throughout this course.

Introducing the Sample Application

Our sample program is a product search application. On initialization, it builds a product document index from sample product data and a second index from sample store location data. The store location documents include geopoint (latitude and longitude) information.

The application displays the products and allows users to rate products by submitting reviews. It supports full-text search over the indexed product information, using either simple term-based queries or more complex query syntax. The search results can be sorted in various ways, including by the product’s average rating and by a term-frequency relevance metric. Search results use the Search API’s snippeting feature to display salient document field substrings. The application also demonstrates the use of search offsets and limits to support pagination.

An example product search

Figure 1 : An example product search.

The screen shot above shows a typical search results page. The user has searched for items in the “books” category, and the query is

(stories OR novel) price < 20

giving a hint of the query language supported by the Search API. (This particular query is more complex than we’d expect the average user to input, but we’ve built our example application so that we can experiment with the query syntax). You’ll notice that the matched results show description snippets with search terms in bold, and that we’ve sorted the search results by product rating.

Showing off the Search API’s Geosearch capabilities, users can also search for store locations near them, as shown below:

Using Geosearch to find stores near the user

Figure 2 : Using Geosearch to find stores near the user.

The Geosearch form is accessed when viewing the details for a product. (Geosearch is currently supported only for deployed applications). The application also shows how to delete documents, create new documents, and perform batch indexing and reindexing of the product data.

Installing and Running the Example Application

To install the example application, first ensure that Python and the App Engine SDK are properly installed, and that you understand the basics of launching and deploying an application. (The Introduction to Google App Engine class or Getting Started tutorial will walk you through this process.) Then download the example application . You can do a read-only checkout of the App Engine search code samples like this:

% git clone git://github.com/GoogleCloudPlatform/appengine-search-python-java.git

Follow the instructions in the included README file to run the application in the Development Web Server ( dev_appserver.py ). Because the application uses cross-group (XG) transactions, you’ll need to use the --high_replication flag:

% dev_appserver.py --high_replication .

If you forget, you’ll see an error like this when you run the application:

BadRequestError: transactions on multiple entity groups only allowed with the High Replication datastore

Once the application is running, initialize its sample data. As described in the README file, this entails logging in as an administrator and clicking the Admin/Add sample data link in the sidebar, followed by the Delete all datastore and index product data, then load in sample product data link. The Development Web Server doesn't currently support all features of the Search API (like Geosearch), so you’ll eventually want to deploy the application to appspot.com . (You may first need to create an application ID for it.)

Once you’ve deployed the application and initialized its data, test it by typing a few simple test queries into the search box. For example, try:

(stories OR novel) price < 10

You can also click the Search button without inputting any query constraints, and page through all the sample products in the small data set. You’ll find the sample data in the application’s data directory. If you want, you can try changing some of the fields and then reinitializing.

Summary and Review

In this lesson, you've installed a sample Product Search App Engine application that uses the Search API. In upcoming lessons, you’ll be able to use the application’s code as a source of concrete examples and experimentation, and play with the Search API’s query syntax via its search interface. In the next lesson , we'll start by looking at the basics of the Search API.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.