My favorites | English | Sign in

More personalization in Google Friend Connect New!

Google Custom Search API

Defining Your Search Engine Specifications

The Basics page introduced you to the components of custom search engines. This page shows you how you can define your search engine specifications using a context file.

Contents

This page includes the following sections:

Overview Updated!

A context file describes the structure of your search engine and defines its behavior. The best way to start learning about context files is by viewing a simple example. As you build your confidence, you might want to start experimenting with various elements and attributes. You can play with the settings in the control panel, and then view the generated XML version in the Advanced tab.

The following code describes a search engine for climate change.

<CustomSearchEngine volunteers="false"
                    keywords="climate &quot;global warming&quot; &quot;greenhouse gases&quot;"
                    language="en"
                    visible="false"
                    encoding="UTF-8">
    <Title>RealClimate</Title>
    <Description>Science behind global warming and climate change.</Description>
    <Context>
      <BackgroundLabels>
        <Label name="_cse_hwbuiarvsbo" mode="FILTER"/>
        <Label name="_cse_exclude_hwbuiarvsbo" mode="ELIMINATE"/>
      </BackgroundLabels>
    </Context>
    <LookAndFeel nonprofit="false"/> 
</CustomSearchEngine>

A basic context file includes the following main elements and child elements.

CustomSearchEngine is the main element that describes the search engine. It encloses the metadata that describes your search engine, and it has attributes and child elements. Except for Label (and an optional element, none of its child element can have a sibling; that is, you can have only one Title element, one Description element, and one Look and Feel element.

The context file also have other optional elements that you would only need to define if you want to enable other features. They have the following structure:

When you are ready to create your context file, do not create it from scratch. Download and modify the context file generated by the control panel. For instructions, see The Basics page.

Back to top

The Attributes of the CustomSearchEngine Element

All the CustomSearchEngine attributes are optional, which means that you do not have to use them, and Custom Search will just use the default value. For example, if you do not define the language and encoding attributes of the CustomSEarchEngine element, Custom Search will interpret that to mean that the language value is "en" (English) and the encoding value is "UTF-8".

The following is an example of a CustomSearchEngine element with fully defined attributes:

<CustomSearchEngine volunteers="false"
                    keywords="climate &quot;global warming&quot; &quot;greenhouse gases&quot;"
                    language="en"
                    visible="false"
                    encoding="UTF-8">
</CustomSearchEngine>      

The following table lists the optional attributes of CustomSearchEngine and their values.

Attribute Description Value
volunteers Indicates whether your search engine is accepting volunteer applications. Specify either:
  • false - Default. Users cannot collaborate with you.
  • true - Other users can volunteer to collaborate with you. Once you accept these users, they can include and exclude sites, as well as apply refinement labels. (To learn more about labels, see the Helping Your Users Refine Their Searches page.) You maintain administrative control over the social search engine, and you can rescind your permission at any time.

    If you are not uploading the context file to the control panel, but are instead hosting it in your own website, you will not be able to take advantage of the collaborative features. Hosted context files can't have volunteers.

keywords Specifies a list of keywords associated with the search engine. Keywords are one way of fine-tuning your search results. If you do not define a keyword, Custom Search will simply use an empty value; that is: keywords=" ". Custom Search will not boost results based on keywords.

But if you want to create keywords, you use up to 100 characters. Separate words by using a single space. You do not need to use other separators, such as commas.

To learn more about about keywords and tweaking search results, see Changing the Ranking of Your Search Results.

language Determines which of the available 40 languages to display in the user interface (UI) of your search engine. The language attribute also boosts results in that language; however it does not filter out results in other languages. If you do not specify a language, Custom Search will use en (English) as the default value. If you use an empty value (that is, language=" "), Custom Search will use the locale of your user. To see the 40 language values that are available, see the Language Code Values reference page.
visible Indicates whether your search engine, once it becomes popular, should be included in the Custom Search directory or not. Specify either:
  • true - Default. If your search engine is active and popular, it will be included in the Custom Search directory. You can search for active search engines in the Custom Search Featured Examples page.

    Setting the value to true does not mean your search engine gets included automatically listed in the directory; however, it will be added once your search engine has gained more users and activities.

  • false - Your search engine will not be listed in the directory; however, people can still find your search engine if they know the URL of your custom search engine homepage.
encoding Specifies the encoding for your search results page. Encoding tells computers how to store and transmit text over the network. If you are not planning to embed a search box in a webpage, you can ignore this. But if you are, the encoding of the search box must match the encoding of your webpage. In the vast majority of cases, the default value, UTF-8, works best. In fact, many text issues in the results page can be resolved by keeping the UTF-8 value.

To see the encoding values that are available, see the Encoding Values reference page.

Back to top

The Child Elements of CustomSearchEngine Updated!

The following tables list the required and optional child elements of CustomSearchEngine; these elements should all be nested within the <CustomSearchEngine> </CustomSearchEngine> tags. The content of your definition should be within the opening and closing tags of the child element. For example:

<CustomSearchEngine>
    <!--The following are the required elements-->
    <Title>Sample Search Engine</Title>
    <Description>Search engine to illustrate the elements in a Custom Search context file</Description>
    <Context> ... </Context>
    <LookAndFeel nonprofit="false">... </LookAndFeel>
    <!--The following are elements for enabling other features-->
    <SubscribedLinks />
    <Adsense />
    <EnterpriseAccount />
    <t13n_languages>hi</t13n_languages>    
</CustomSearchEngine>            

Required Elements Updated!

This table lists child elements that you must include in your context files.

Element Description
Title The name of your search engine. It appears on your custom search engine homepage and the result pages.
Description The descriptive text that appears in your search engine homepage.
Context Holds information about labels. It has child elements, one of which ( BackgroundLabels) is described in more detail in the next section.
LookAndFeel Determines whether your search results show ads. Only legitimate non-profit organizations may use Google Custom Search without ads. If your custom search engine is not for a registered non-profit organization, but you do not want Google to display ads in the search results page, consider upgrading to Google Site Search.

The element has one attribute, nonprofit, and takes one of the following values:

  • false - Default. Google displays ads with your search results page. You can share in the ad revenue.
  • true - If you are creating a search engine on behalf of a registered non-profit organization, Google will not display ads in the search results page.

Example:

<LookAndFeel nonprofit="false"/>

Back to top

Optional Elements New!

The table list child elements that you do not need to include in your context file unless you want to activate the features, which are discussed in greater detail in other pages in the developer's guide.

Element Description More information
SubscribedLinks

Enables subscribed links in your search results page. Subscribed links is a form of special results that you create for a set of pre-defined queries. It is a way to directly answer your users' questions in the results page.

Creating Special Results
AdSense Associates the search engine with your AdSense account. Make money with your custom search engine by connecting it with your Google AdSense account. When users click on an ad in your search results, you get a share of the ad revenue.

If you already have an existing AdSense account, do not create a new one, even if you create multiple search engines. Google automatically associates your search engines with the same AdSense account. Creating another AdSense account might result in the termination of your AdSense account.

Making Money
Enterprise Account

If you upgraded to Google Site Search, it lists your contact information. You can change the attribute values to update your information.

Google Site Search
(The site discusses the features, not the XML elements.)

Back to top

The Context Element

The Context element, which is one of the child elements of CustomSearchEngine, houses information about labels. It has two child elements: BackgroundLabel and Facet. Facet elements have to do with refinement labels, which let you help your users refine their search. This section will mostly discuss the BackgroundLabel element. If you decide to add refinements to your search results, you can learn more about the Facet element, which is described in greater detail in the Helping Your Users Refine their Searches page.

The Context section of a simple context file (one that does not include refinement labels) might look like the following:

    <Context>
      <BackgroundLabels>
        <Label name="_cse_hwbuiarvsbo" mode="FILTER"/>
        <Label name="_cse_exclude_hwbuiarvsbo" mode="ELIMINATE"/>
      </BackgroundLabels>
    </Context>

It has the following structure:

  • Context
    • BackgroundLabels (labels for the search engine)
      • Label (for promoting sites or for showing certain sites exclusively)
      • Label (for excluding sites)

Custom Search associates the context specifications with the annotations through search engine labels. The context section includes labels that identify the search engine; you then use these search engine labels to tag each site in the annotations file.

The context section starts out with two search engine labels under BackgroundLabels. One search engine label either promotes or exclusively shows only the preferred sites, and the other label excludes sites. Custom Search displays search results based on how sites have been annotated with these two labels. To learn more about search engine labels, see Changing the Ranking of Your Search Results.

Custom Search generates two search engine labels for each of your search engines, but you can change these labels to something that is more meaningful to you. When you start creating more labels, you might want to name them according to how they affect the search results. For example, if a label is meant to exclude sites about vegetables you despise, then its name could be cse_exclude_boringvegetables. The label names should be unique across your search engines. If you change the name of the search engine label in the context file, you have to update all the annotations that have been tagged with the old search engine label.

Back to top

Taking the Next Step

After you create the context file that defines the specification of your search engine, you can start listing the sites for your custom search engine.

 

< Back to The Basics of Custom Search | Forward to Selecting Sites to Search >