ONLamp.com
oreilly.comSafari Books Online.Conferences.

advertisement


Creating Google Custom Search Engines
Pages: 1, 2, 3

Refining Your Search Engine

Now that you have the context and annotation files on your system, there are several ways in which you can refine your search engine. First I'll show you how to personalize your engine by changing the colors on the resulting page.



I made the changes shown below to the downloaded context file. These set the color of the background of the results pages, the border that goes around Google advertisements, and the title at the top of each search result returned.

<?xml version="1.0" encoding="UTF-8"?>
<GoogleCustomizations>
  <CustomSearchEngine version="1.0" volunteers="true" 
  keywords="homecooking "easy to prepare" "simple cooking"" 
  Title="Simple Recipes Search Engine" 
  Description="Easy-to-prepare recipes for home cooks. If you want to have a meal ready in 60 minutes, look here for good recipes that you can use immediately." 
  language="en" visible="true">
    <Context>
      <BackgroundLabels>
        <Label name="_cse_rlplbd3nkfw" mode="FILTER"/>
        <Label name="_cse_exclude_rlplbd3nkfw" mode="ELIMINATE"/>
      </BackgroundLabels>
    </Context>
    <LookAndFeel nonprofit="false">
      <Colors background="#FEFAFF" 
         border="#000033" title="#993300" />
    </LookAndFeel>
  </CustomSearchEngine>
</GoogleCustomizations>

I can then go back to the Advanced tab in the control panel for my search engine and upload this new file (remembering to first save a copy of the original file). Immediately after the upload has completed, I can use the Preview tab to see what the changes look like.

Here are the various color parameters that can be set and what they change on the search engine results page.

Parameter Defines color for
Background Background for the results page
Border Border drawn around advertisements and above results
Title Title of the URL above each search result
Text Text shown for each search result
URL Non-working URL shown below each search result
Visited Title URL after it has been visited
Light Other information beside URL. Cached or refinement labels

By making changes to the annotations file you really control the heart of your search engine. As well as defining more sites to include, you can also specify categories for each site and given them a higher or lower priority.

Google calls the categories Refinements. These appear at the top of the results page and are used to focus in on a set of the total results. For the Diabetes Search Engine the results page has several of these including symptoms, complications, and research.

refinements figure
Figure 7. Refinements

You can see that each result is displayed with a set of labels indicating how it was categorized. And by clicking on one of the label hyperlinks, the results for sites with that label only are returned.

To create a refinement, you must first modify the context file to specify the label names that will appear on the results page.

<?xml version="1.0" encoding="UTF-8"?>
<GoogleCustomizations>
  <CustomSearchEngine version="1.0" volunteers="true" ...>
    <Context>
      <Facet>
        <FacetItem Title="Lunch">
          <Label name="lunch" mode="BOOST" Rewrite="" IgnoreBackgroundLabels="false" weight="0.7"/>
        </FacetItem>
      </Facet>
      <Facet>
        <FacetItem Title="Dinner">
          <Label name="dinner" mode="FILTER" Rewrite="" IgnoreBackgroundLabels="false"/>
        </FacetItem>
      </Facet>
      <BackgroundLabels>
        <Label name="_cse_rlplbd3nkfw" mode="FILTER"/>
        <Label name="_cse_exclude_rlplbd3nkfw" mode="ELIMINATE"/>
      </BackgroundLabels>
    </Context>
    ... 
  </CustomSearchEngine>
</GoogleCustomizations>

I've defined two different labels that can be assigned to each site in the search engine. When the Lunch hyperlink is clicked, all sites with this label assigned have their priority boosted so they appear closer to the top of the search results. In this case, unlabeled sites can also appear in the results. We could boost by a larger amount (up to 1) to emphasize them even more.

When the Dinner one is chosen, only sites that are labeled with the Dinner refinement will appear in the results. All others, including unlabelled sites, will not be shown.

Now that we have some refinements, I can change the annotations file to assign these labels to the sites that I want. Each site is already defined in an <Annotation> node, and I simply add new <Label> nodes for each refinement that I want to assign.

    <Annotation about="www.absoluterecipes.com/*">
      <Label name="_cse_rlplbd3nkfw"/>
      <Label name="lunch"/>
      <Label name="dinner"/>
    </Annotation>
    <Annotation about="www.allfood.com/mmeal.cfm*">
      <Label name="_cse_rlplbd3nkfw"/>
      <Label name="dinner"/>
    </Annotation>

Once I've completed these changes I can load my new annotations file up to my search engine. Don't forget to backup the original annotations first!

If you'd like to know more about these files, Google has pages documenting both the context file format and the annotations file format.

Conclusion

This article is intended to provide you with enough of an introduction to Google Custom Search Engines that you can create one of your own. This will give you a chance to use your expertise in a specific area to assist people who are looking for answers or help in that area. The detail on the advanced topics will also allow you to customize the data your engine returns and how it's presented to people.

References

Google's CSE FAQ answers some common questions about CSEs.

CSE Documentation will help you figure out some of the more difficult parts of customization.

The Google Custom Search blog will keep you updated on new facilities and changes.

You can get help from other CSE users in the Google Custom Search Help groups

Google has some featured CSE examples that may inspire you.

Bernard Farrell is a software architect focusing on user experience issues. He has over 30 years experience in software design and development including user interfaces for early workstations. He created the diabetes search engine and write a blog about diabetes technology.


Return to ONLamp.



Sponsored by: