Google Custom Search Refinements and the CSBE API

As part of my duties at Site­Point, I’m imple­ment­ing a Google Cus­tom Search Engine (Busi­ness Edition).

One of the neat fea­tures of Google’s CSE is Refine­ments. You can tag por­tions of your site — sub­di­rec­to­ries, sub­do­mains, or even sep­a­rate sites that you’ve added to your engine — with labels. You can then cre­ate refine­ments that will either boost results from these tagged regions of your site, list only results from spec­i­fied tags, or exclude cer­tain tags alto­gether from the result set.

Unfor­tu­nately the means of using these pro­gram­mat­i­cally are not so well doc­u­mented — the API doc­u­men­ta­tion doesn’t spec­ify how to include or exclude cer­tain labels (as far as I’ve been able to determine).

So! For the record, the solu­tion is to use the strings ‘more:<label>’ and ‘less:<label>’ in your query string.

If you have a refine­ment called ‘Forums’, for exam­ple, and you’ve set your cus­tom search engine to ‘search only labeled sites’, enter­ing a query like ‘toast more:forums’ will show results only from your Forums refine­ment. Sim­i­larly, the query string ‘toast less:forums’ will remove results from the result set that would have been taken from sites you’ve labelled ‘Forums’.

You can also com­bine refine­ment labels — if you have labels ‘Forum’, ‘Blogs’ and ‘Arti­cles’, and you want to exclude forums and blogs, you could con­struct a search like ‘win­nebago less:forum less:blogs’, and this will only show your arti­cle results.

The more you know!


2 Responses to “Google Custom Search Refinements and the CSBE API

Leave a Reply