Context: Defining a Programmable Search Engine
This page describes how to define your search engine specifications using a context file.
- Overview
- CustomSearchEngine Elements
Overview
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 downloaded from the Overview page.
The following code describes a search engine for climate change. Note that this search engine has image search enabled.
<CustomSearchEngine keywords="climate "global warming" "greenhouse gases""
language="en">
<Title>RealClimate</Title>
<Description>Science behind global warming and climate change.</Description>
<Context>
<BackgroundLabels>
<Label name="_include_" mode="FILTER"/>
<Label name="_exclude_" mode="ELIMINATE"/>
</BackgroundLabels>
</Context>
<LookAndFeel/>
<ImageSearchSettings enable="true"/>
</CustomSearchEngine>
CustomSearchEngine elements
A basic context file includes the following main elements and child elements.
Element |
Required |
Description |
CustomSearchEngine |
Required |
Encloses all information about the search engine. Has the following attributes:
keywords . Specifies a list (up to 100 characters long) of space-separated keywords associated with the search engine. If not specified, Programmable Search Engine will use an empty value.
language . Specifies one of the supported languages to display in the user interface. Specifying a language will boost results in that language, but will not filter out results in other languages. If not specified, Programmable Search Engine will use en (English). If the value is null, Programmable Search Engine will use the language of the locale of your user.
autocompletions . Indicates whether Programmable Search Engine should generate GLOSSARY autocompletions for your search engine. Allowed values are true or false . If true , note that generating autocompletions can take several hours. After setting this value, you must modify your search box code to request autocompletions. You can get the updated code from the Get code tab in the Control Panel. Only search engines that search included sites—a predetermined collection of websites—can have autocompleted queries.
|
Title |
Required |
The name of your search engine. It appears on your Programmable Search Engine homepage and the result pages.
|
Description |
Required |
The descriptive text that appears in your search engine overview page.
|
Context |
Required |
Holds information about labels. Includes the child elements BackgroundLabels and Facet . |
BackgroundLabels |
Optional |
Container for labels used to promote, include, or excludes sites and pages. Includes one or more child Label elements. |
Label |
Optional |
Label used to promote sites or determine inclusion/exclusion of sites. Has the following attributes:
name . The label name.
mode . FILTER (promotes or exclusively shows preferred sites) or ELIMINATE (excludes site). You can customize these labels as you wish.
|
LookAndFeel |
Required |
Controls the look and feel of your search engine. It has multiple attributes and child elements that are described in detail in the Look and Feel page.
|
ImageSearchSettings |
Optional |
Specifies if Image Search is enabled. Has the following attributes:
enable . Specifies whether Image Search is enabled for this search engine. Allowed values are true or false .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-08-21 UTC.
[null,null,["Last updated 2024-08-21 UTC."],[[["Custom Search Ads are customized using parameters categorized by their scope: Page Level, Configuration Settings, and Unit Level."],["Page Level parameters, such as `pubId` and `query`, manage ad behavior across the entire page while Unit Level parameters control individual ad units using attributes like `container` and `width`."],["Configuration settings provide control over aspects like ad filtering (`adsafe`), testing (`adtest`), and language targeting (`hl`)."],["Optional parameters offer further customization, such as defining ad click behavior (`linkTarget`), handling ad loading events (`adLoadedCallback`), and specifying the number of ads to display (`number`)."],["Parameters like `relatedSearchTargeting` and `terms` enable the implementation of related searches, enhancing the user experience by providing relevant content suggestions."]]],[]]