Using a Google Search Appliance with a Sitecore Website Part 2

Thursday, June 13, 2013 @ 03:27

By: Jon Upchurch, Senior Developer

Part 2: Performing Queries

It’s not always easy to find useful code samples for working with the Google Search Appliance, and the best wrapper I found was woefully lacking in documentation. All I needed was a mechanism to perform queries, so if you need complex custom indices then this becomes far more complicated and will not be covered here. We are using a faceted search, but managing that via metadata and filtering the returned results.

To get started, you’ll need the GSALib wrapper by MC+A found here. Add this DLL to your solution and add the following to your config file:

    <add key="GSAHostAddress" value="http://yourGSAAddress/" />

Without this the library won’t know where to find your GSA. This can go in a web.config or an app.config or referenced in an external configuration section.

From here, the solution is fairly simple:


Click the image above to get source code for a DLL version, click here

If there is a network error this will pass the exception on, so be sure that you catch this in your own implementation.

From here it’s as simple as calling the GetGSAResults method. In the full code I provide several overloaded variations on the code, and the minimum required is a search string, an array of collection names, and a front end name. Results come back in the form of GSALib.GSA.Result, and have all of the expected properties such as getTitle(), getUrl(), etc. This .NET version of the library was adapted from the Java version which explains the unusual (for .NET) use of accessors and mutators over the use of properties.