google.load('search', '1');
// the cse class encapsulates a left and right search control
// both controls are driven by a shared search form
function cse() {
var searcher;
var options;
var sFormDiv = document.getElementById("searchForm");
var leftScDiv = document.getElementById("leftSearchControl");
var rightScDiv = document.getElementById("rightSearchControl");
// create the search control
this.control = new google.search.SearchControl();
this.control.setResultSetSize(GSearch.LARGE_RESULTSET);
// pref for a cref style custom search engine
//直接使用个性化搜索引擎的XML站点文件
var crefUrl = "http://www.google.com/cse/samples/vegetarian.xml";
// Create and add searchers
// left side cref based searcher, no refinements
searcher = new google.search.WebSearch();
searcher.setSiteRestriction({crefUrl : crefUrl});//限定站点使用个性化搜索引擎,为限定标签
searcher.setUserDefinedLabel("Vegan CSE");
options = new google.search.SearcherOptions();
options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
options.setRoot(leftScDiv);
this.control.addSearcher(searcher, options);
// right side cref based searcher using "recipes" as a refinement
searcher = new google.search.WebSearch();
searcher.setSiteRestriction({crefUrl : crefUrl}, "recipes");//限定站点标签
searcher.setUserDefinedLabel("Recipes");
options = new google.search.SearcherOptions();
options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
options.setRoot(rightScDiv);
this.control.addSearcher(searcher, options);
this.control.draw(sFormDiv);
// execute a starter search
this.control.execute("Pasta Marinara");
}
function OnLoad() {
new cse();
}
google.setOnLoadCallback(OnLoad, true);
阅读笔记 Google Example Code:Linked Custom Search Engines
地址:http://www.google.com/uds/samples/cse/cref.html
This sample demonstrates the latest addition to Custom Search Engines, the Linked Custom Search Engine. You will note that we use an object for
Vegan CSE - powered by The Google AJAX Search API and Google Custom Search Engines
结论:针对个性化搜索引擎进行搜索,包括左右两个搜索控件
通过直接使用个性化搜索引擎的站点限定XML文件作为限定站点的输入
左边是针对整个个性化搜索引擎进行搜索
右边是针对个性化搜索引擎下的一个标签进行搜索
存疑:无
可用代码:
var crefUrl = "http://www.google.com/cse/samples/vegetarian.xml";
searcher = new google.search.WebSearch();
searcher.setSiteRestriction({crefUrl : crefUrl});//限定站点使用个性化搜索引擎,为限定标签
searcher.setUserDefinedLabel("Vegan CSE");
This sample demonstrates the latest addition to Custom Search Engines, the Linked Custom Search Engine. You will note that we use an object for
site and in the crefUrl property we supply the url of a Custom Search Engine definition file.Vegan CSE - powered by The Google AJAX Search API and Google Custom Search Engines
结论:针对个性化搜索引擎进行搜索,包括左右两个搜索控件
通过直接使用个性化搜索引擎的站点限定XML文件作为限定站点的输入
左边是针对整个个性化搜索引擎进行搜索
右边是针对个性化搜索引擎下的一个标签进行搜索
存疑:无
可用代码:
var crefUrl = "http://www.google.com/cse/samples/vegetarian.xml";
searcher = new google.search.WebSearch();
searcher.setSiteRestriction({crefUrl : crefUrl});//限定站点使用个性化搜索引擎,为限定标签
searcher.setUserDefinedLabel("Vegan CSE");
源码注释:Custom Search Engine Refinements (部分)
google.load('search', '1');
// the cse class encapsulates a left and right search control
// both controls are driven by a shared search form
function cse() {
var sFormDiv = document.getElementById("searchForm");
var leftScDiv = document.getElementById("leftSearchControl");
var rightScDiv = document.getElementById("rightSearchControl");
// create a left, right search control
// create a custom search form
this.leftControl = new google.search.SearchControl();
this.rightControl = new google.search.SearchControl();
this.searchForm = new google.search.SearchForm(true, sFormDiv);
// bind clear and submit functions
this.searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit);
this.searchForm.setOnClearCallback(this, cse.prototype.onClear);
// set up for large result sets
//设置了搜索结果框大小,以结果显示的链接打开方式(本例选择了在当前窗口打开)
this.leftControl.setResultSetSize(GSearch.LARGE_RESULTSET);
this.rightControl.setResultSetSize(GSearch.LARGE_RESULTSET);
this.leftControl.setLinkTarget(GSearch.LINK_TARGET_SELF);
this.rightControl.setLinkTarget(GSearch.LINK_TARGET_SELF);
var searcher;
var options;
// configure left control
// Site Restrict to CSE ID for Curriculum Search
//搜索定制的个性化搜索引擎,使用该搜索引擎的一个子集,即一个标签下的站点限制
var cseId = "017576662512468239146:omuauf_lfve";
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
//设置了按下more results链接后的页面样式,使用类似于第三个参数给定的站点样式
searcher.setSiteRestriction(cseId, null,
"http://code.google.com/edu/curriculumsearch/results.html?cx=017576662512468239146%3Aomuauf_lfve&q=__QUERY__&sa=Search&client=google-coop-np&cof=FORID%3A9%3BCX%3ACurriculum&hl=__HL__");
searcher.setUserDefinedLabel("Curriculum Search");
options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
this.leftControl.addSearcher(searcher, options);
// configure right control for
// -- Lectures Refinement
// -- Assignments Refinement
// -- Reference Refinement
// -- blog search
// -- web search
// -- news search
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction(cseId, "Lectures");//仅搜索cse下的Lectures标签中的站点
searcher.setUserDefinedLabel("Lectures");
this.rightControl.addSearcher(searcher, options);
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction(cseId, "Assignments");
searcher.setUserDefinedLabel("Assignments");
this.rightControl.addSearcher(searcher, options);
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction(cseId, "Reference");
searcher.setUserDefinedLabel("Reference");
this.rightControl.addSearcher(searcher, options);
searcher = new google.search.BlogSearch();
this.rightControl.addSearcher(searcher);
searcher = new google.search.WebSearch();
this.rightControl.addSearcher(searcher);
// draw the left and right controls
// the right control is drawn in tabbed mode
var drawOptions = new google.search.DrawOptions();
drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
this.leftControl.draw(leftScDiv);
this.rightControl.draw(rightScDiv, drawOptions);
// execute a starter search
this.searchForm.execute("RSA Encryption");
}
// when the form fires a submit, grab its
// value and call the left and right control
cse.prototype.onSubmit = function(form) {
var q = form.input.value;
if (q && q!= "") {
this.leftControl.execute(q);
this.rightControl.execute(q);
}
return false;
}
// when the form fires a clear, call the left and right control
cse.prototype.onClear = function(form) {
this.leftControl.clearAllResults();
this.rightControl.clearAllResults();
form.input.value = "";
return false;
}
function OnLoad() {
new cse();
}
google.setOnLoadCallback(OnLoad, true);
// the cse class encapsulates a left and right search control
// both controls are driven by a shared search form
function cse() {
var sFormDiv = document.getElementById("searchForm");
var leftScDiv = document.getElementById("leftSearchControl");
var rightScDiv = document.getElementById("rightSearchControl");
// create a left, right search control
// create a custom search form
this.leftControl = new google.search.SearchControl();
this.rightControl = new google.search.SearchControl();
this.searchForm = new google.search.SearchForm(true, sFormDiv);
// bind clear and submit functions
this.searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit);
this.searchForm.setOnClearCallback(this, cse.prototype.onClear);
// set up for large result sets
//设置了搜索结果框大小,以结果显示的链接打开方式(本例选择了在当前窗口打开)
this.leftControl.setResultSetSize(GSearch.LARGE_RESULTSET);
this.rightControl.setResultSetSize(GSearch.LARGE_RESULTSET);
this.leftControl.setLinkTarget(GSearch.LINK_TARGET_SELF);
this.rightControl.setLinkTarget(GSearch.LINK_TARGET_SELF);
var searcher;
var options;
// configure left control
// Site Restrict to CSE ID for Curriculum Search
//搜索定制的个性化搜索引擎,使用该搜索引擎的一个子集,即一个标签下的站点限制
var cseId = "017576662512468239146:omuauf_lfve";
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
//设置了按下more results链接后的页面样式,使用类似于第三个参数给定的站点样式
searcher.setSiteRestriction(cseId, null,
"http://code.google.com/edu/curriculumsearch/results.html?cx=017576662512468239146%3Aomuauf_lfve&q=__QUERY__&sa=Search&client=google-coop-np&cof=FORID%3A9%3BCX%3ACurriculum&hl=__HL__");
searcher.setUserDefinedLabel("Curriculum Search");
options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
this.leftControl.addSearcher(searcher, options);
// configure right control for
// -- Lectures Refinement
// -- Assignments Refinement
// -- Reference Refinement
// -- blog search
// -- web search
// -- news search
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction(cseId, "Lectures");//仅搜索cse下的Lectures标签中的站点
searcher.setUserDefinedLabel("Lectures");
this.rightControl.addSearcher(searcher, options);
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction(cseId, "Assignments");
searcher.setUserDefinedLabel("Assignments");
this.rightControl.addSearcher(searcher, options);
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction(cseId, "Reference");
searcher.setUserDefinedLabel("Reference");
this.rightControl.addSearcher(searcher, options);
searcher = new google.search.BlogSearch();
this.rightControl.addSearcher(searcher);
searcher = new google.search.WebSearch();
this.rightControl.addSearcher(searcher);
// draw the left and right controls
// the right control is drawn in tabbed mode
var drawOptions = new google.search.DrawOptions();
drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
this.leftControl.draw(leftScDiv);
this.rightControl.draw(rightScDiv, drawOptions);
// execute a starter search
this.searchForm.execute("RSA Encryption");
}
// when the form fires a submit, grab its
// value and call the left and right control
cse.prototype.onSubmit = function(form) {
var q = form.input.value;
if (q && q!= "") {
this.leftControl.execute(q);
this.rightControl.execute(q);
}
return false;
}
// when the form fires a clear, call the left and right control
cse.prototype.onClear = function(form) {
this.leftControl.clearAllResults();
this.rightControl.clearAllResults();
form.input.value = "";
return false;
}
function OnLoad() {
new cse();
}
google.setOnLoadCallback(OnLoad, true);
源码注释:Custom Search Engines (部分)
google.load('search', '1');
// the cse class encapsulates a left and right search control
// both controls are driven by a shared search form
function cse() {
//创建变量,分别对应搜索框和左右结果框
var sFormDiv = document.getElementById("searchForm");
var leftScDiv = document.getElementById("leftSearchControl");
var rightScDiv = document.getElementById("rightSearchControl");
// create a left, right search control
// create a custom search form
//创建搜索控件,分别对应左右搜索结果框,和搜索输入框
this.leftControl = new google.search.SearchControl();
this.rightControl = new google.search.SearchControl();
this.searchForm = new google.search.SearchForm(true, sFormDiv);
// bind clear and submit functions
//继续创建searchForm对象的后续两个步骤,提交按钮和清除按钮
this.searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit);
this.searchForm.setOnClearCallback(this, cse.prototype.onClear);
// set up for small result sets
//设置结果集大小
this.leftControl.setResultSetSize(google.search.Search.SMALL_RESULTSET);
this.rightControl.setResultSetSize(google.search.Search.SMALL_RESULTSET);
var searcher;
var options;
// configure left control
// Site Restrict to CSE ID for reviews
//配置左边的搜索引擎,使用定制的个性化搜索引擎作为限定站点
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction("000455696194071821846:reviews");
//该搜索引擎就是000455696194071821846:reviews,其中reviews不是搜索引擎内的标签
searcher.setUserDefinedLabel("Product Reviews");
options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);//设置结果展示模式
this.leftControl.addSearcher(searcher, options);
// configure right control for
// -- cse for comparisons
// -- cse for community
// -- cse for shopping
// -- blog search
// -- news search
//配置右边的搜索引擎,设置了六个搜索引擎
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction("000455696194071821846:comparisons");
searcher.setUserDefinedLabel("Prices");
this.rightControl.addSearcher(searcher, options);
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction("000455696194071821846:community");
searcher.setUserDefinedLabel("Forums");
this.rightControl.addSearcher(searcher, options);
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction("000455696194071821846:shopping");
searcher.setUserDefinedLabel("Shopping");
this.rightControl.addSearcher(searcher, options);
searcher = new google.search.BlogSearch();
this.rightControl.addSearcher(searcher);
searcher = new google.search.WebSearch();
this.rightControl.addSearcher(searcher);
searcher = new google.search.NewsSearch();
this.rightControl.addSearcher(searcher);
// draw the left and right controls
// the right control is drawn in tabbed mode
//绘制结果,使用标签模式排列
var drawOptions = new google.search.DrawOptions();
drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
this.leftControl.draw(leftScDiv);
this.rightControl.draw(rightScDiv, drawOptions);
// bind in a videobar
//绑定视频搜索结果显示框,和视频播放框
var videoBarDiv = document.getElementById("videoBar");
var videoPlayerDiv = document.getElementById("videoPlayer")
var vboptions = {
largeResultSet : false,
horizontal : true
}
this.videoBar = new GSvideoBar(videoBarDiv, videoPlayerDiv, vboptions);
//同时设置视频搜索和播放框
// execute a starter search
this.searchForm.execute("Apple iPod");
}
// when the form fires a submit, grab its
// value and call the left and right control
//设置搜索按钮
//当从搜索输入框接收到搜索请求之后,同时调用搜索左右搜索框以及视频搜索框
cse.prototype.onSubmit = function(form) {
var q = form.input.value;
if (q && q!= "") {
this.leftControl.execute(q);
this.rightControl.execute(q);
this.videoBar.execute(q);
}
return false;
}
// when the form fires a clear, call the left and right control
//设置清除按钮
cse.prototype.onClear = function(form) {
this.leftControl.clearAllResults();
this.rightControl.clearAllResults();
this.videoBar.clearAllResults();
form.input.value = "";
return false;
}
function OnLoad() {
new cse();
}
google.setOnLoadCallback(OnLoad, true);
// the cse class encapsulates a left and right search control
// both controls are driven by a shared search form
function cse() {
//创建变量,分别对应搜索框和左右结果框
var sFormDiv = document.getElementById("searchForm");
var leftScDiv = document.getElementById("leftSearchControl");
var rightScDiv = document.getElementById("rightSearchControl");
// create a left, right search control
// create a custom search form
//创建搜索控件,分别对应左右搜索结果框,和搜索输入框
this.leftControl = new google.search.SearchControl();
this.rightControl = new google.search.SearchControl();
this.searchForm = new google.search.SearchForm(true, sFormDiv);
// bind clear and submit functions
//继续创建searchForm对象的后续两个步骤,提交按钮和清除按钮
this.searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit);
this.searchForm.setOnClearCallback(this, cse.prototype.onClear);
// set up for small result sets
//设置结果集大小
this.leftControl.setResultSetSize(google.search.Search.SMALL_RESULTSET);
this.rightControl.setResultSetSize(google.search.Search.SMALL_RESULTSET);
var searcher;
var options;
// configure left control
// Site Restrict to CSE ID for reviews
//配置左边的搜索引擎,使用定制的个性化搜索引擎作为限定站点
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction("000455696194071821846:reviews");
//该搜索引擎就是000455696194071821846:reviews,其中reviews不是搜索引擎内的标签
searcher.setUserDefinedLabel("Product Reviews");
options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);//设置结果展示模式
this.leftControl.addSearcher(searcher, options);
// configure right control for
// -- cse for comparisons
// -- cse for community
// -- cse for shopping
// -- blog search
// -- news search
//配置右边的搜索引擎,设置了六个搜索引擎
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction("000455696194071821846:comparisons");
searcher.setUserDefinedLabel("Prices");
this.rightControl.addSearcher(searcher, options);
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction("000455696194071821846:community");
searcher.setUserDefinedLabel("Forums");
this.rightControl.addSearcher(searcher, options);
searcher = new google.search.WebSearch();
options = new google.search.SearcherOptions();
searcher.setSiteRestriction("000455696194071821846:shopping");
searcher.setUserDefinedLabel("Shopping");
this.rightControl.addSearcher(searcher, options);
searcher = new google.search.BlogSearch();
this.rightControl.addSearcher(searcher);
searcher = new google.search.WebSearch();
this.rightControl.addSearcher(searcher);
searcher = new google.search.NewsSearch();
this.rightControl.addSearcher(searcher);
// draw the left and right controls
// the right control is drawn in tabbed mode
//绘制结果,使用标签模式排列
var drawOptions = new google.search.DrawOptions();
drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
this.leftControl.draw(leftScDiv);
this.rightControl.draw(rightScDiv, drawOptions);
// bind in a videobar
//绑定视频搜索结果显示框,和视频播放框
var videoBarDiv = document.getElementById("videoBar");
var videoPlayerDiv = document.getElementById("videoPlayer")
var vboptions = {
largeResultSet : false,
horizontal : true
}
this.videoBar = new GSvideoBar(videoBarDiv, videoPlayerDiv, vboptions);
//同时设置视频搜索和播放框
// execute a starter search
this.searchForm.execute("Apple iPod");
}
// when the form fires a submit, grab its
// value and call the left and right control
//设置搜索按钮
//当从搜索输入框接收到搜索请求之后,同时调用搜索左右搜索框以及视频搜索框
cse.prototype.onSubmit = function(form) {
var q = form.input.value;
if (q && q!= "") {
this.leftControl.execute(q);
this.rightControl.execute(q);
this.videoBar.execute(q);
}
return false;
}
// when the form fires a clear, call the left and right control
//设置清除按钮
cse.prototype.onClear = function(form) {
this.leftControl.clearAllResults();
this.rightControl.clearAllResults();
this.videoBar.clearAllResults();
form.input.value = "";
return false;
}
function OnLoad() {
new cse();
}
google.setOnLoadCallback(OnLoad, true);
源码注释:Site Restricted Search (部分)
//google.load(moduleName, moduleVersion, optionalSettings)该方法可以加载各个 AJAX API
//moduleName 是 API 的名称(例如 "maps" 或 "search")
//version 可以指定 API 模块的版本
//optionalSettings 可以为您作为 JavaScript 对象常量加载的 API 指定所有可选配置选项
google.load('search', '1');
function OnLoad() {
// Dynamically load CSS to override defaults
//配置呈现样式
var css = document.createElement('link');
css.href = '../../css/gsearch_green.css';
css.type = 'text/css';
css.rel = 'stylesheet';
document.getElementsByTagName('head')[0].appendChild(css);
// Create a search control
//创建一个搜索控件
var searchControl = new google.search.SearchControl();
// site restricted web search with custom label
// and class suffix
//限制站点搜索
var siteSearch = new google.search.WebSearch();
siteSearch.setUserDefinedLabel("Amazon.com");
siteSearch.setUserDefinedClassSuffix("siteSearch");
siteSearch.setSiteRestriction("amazon.com");
searchControl.addSearcher(siteSearch);
// site restricted web search using a custom search engine
//使用定制的搜索引擎搜索,下面提交自定义的搜索引擎的号码即可
siteSearch = new google.search.WebSearch();
siteSearch.setUserDefinedLabel("Product Reviews");
siteSearch.setSiteRestriction("000455696194071821846:reviews");
searchControl.addSearcher(siteSearch);
// standard, unrestricted web search
//调用没有限制的google搜索
searchControl.addSearcher(new google.search.WebSearch());
// site restricted blog search
//对限定博客进行博客搜索
var blogSearch = new google.search.BlogSearch();
blogSearch.setUserDefinedLabel("LJ Nintendo DS Blog");
blogSearch.setSiteRestriction("http://community.livejournal.com/nintendo_ds/");
searchControl.addSearcher(blogSearch);
// site restricted news search
//对限定新闻站点进行新闻搜索
var newsSearch = new google.search.NewsSearch();
newsSearch.setUserDefinedLabel("Seattle Times");
newsSearch.setSiteRestriction("Seattle Times");
searchControl.addSearcher(newsSearch);
// Establish a keep callback
//创建后退控件
searchControl.setOnKeepCallback(null, DummyClipSearchResult);
// tell the searcher to draw itself and tell it where to attach
//绘制呈现搜索结果
searchControl.draw(document.getElementById("searchcontrol"));
// execute an inital search
//预设搜索关键字
searchControl.execute("Nintendo DS");
}
function DummyClipSearchResult(result) {}
google.setOnLoadCallback(OnLoad, true);
//moduleName 是 API 的名称(例如 "maps" 或 "search")
//version 可以指定 API 模块的版本
//optionalSettings 可以为您作为 JavaScript 对象常量加载的 API 指定所有可选配置选项
google.load('search', '1');
function OnLoad() {
// Dynamically load CSS to override defaults
//配置呈现样式
var css = document.createElement('link');
css.href = '../../css/gsearch_green.css';
css.type = 'text/css';
css.rel = 'stylesheet';
document.getElementsByTagName('head')[0].appendChild(css);
// Create a search control
//创建一个搜索控件
var searchControl = new google.search.SearchControl();
// site restricted web search with custom label
// and class suffix
//限制站点搜索
var siteSearch = new google.search.WebSearch();
siteSearch.setUserDefinedLabel("Amazon.com");
siteSearch.setUserDefinedClassSuffix("siteSearch");
siteSearch.setSiteRestriction("amazon.com");
searchControl.addSearcher(siteSearch);
// site restricted web search using a custom search engine
//使用定制的搜索引擎搜索,下面提交自定义的搜索引擎的号码即可
siteSearch = new google.search.WebSearch();
siteSearch.setUserDefinedLabel("Product Reviews");
siteSearch.setSiteRestriction("000455696194071821846:reviews");
searchControl.addSearcher(siteSearch);
// standard, unrestricted web search
//调用没有限制的google搜索
searchControl.addSearcher(new google.search.WebSearch());
// site restricted blog search
//对限定博客进行博客搜索
var blogSearch = new google.search.BlogSearch();
blogSearch.setUserDefinedLabel("LJ Nintendo DS Blog");
blogSearch.setSiteRestriction("http://community.livejournal.com/nintendo_ds/");
searchControl.addSearcher(blogSearch);
// site restricted news search
//对限定新闻站点进行新闻搜索
var newsSearch = new google.search.NewsSearch();
newsSearch.setUserDefinedLabel("Seattle Times");
newsSearch.setSiteRestriction("Seattle Times");
searchControl.addSearcher(newsSearch);
// Establish a keep callback
//创建后退控件
searchControl.setOnKeepCallback(null, DummyClipSearchResult);
// tell the searcher to draw itself and tell it where to attach
//绘制呈现搜索结果
searchControl.draw(document.getElementById("searchcontrol"));
// execute an inital search
//预设搜索关键字
searchControl.execute("Nintendo DS");
}
function DummyClipSearchResult(result) {}
google.setOnLoadCallback(OnLoad, true);
阅读笔记 Google Example Code:Custom Search Engine Refinements
地址:http://www.google.com/uds/samples/cse/csearch.html
This sample builds on the sample above by introducing custom search engine refinements. You will note in the calls to
Curriculum Search Sample - powered by The Google AJAX Search API and Google Custom Search Engines
结论:主要针对一个个性化的搜索引擎进行搜索,包括左右两边两个搜索控件
左边的搜索控件针对整个个性化搜索引擎进行搜索,设置了more results 之后的页面样式
右边的搜索引擎包括六个搜索控件,前三个是对个性化搜索引擎的标签限定
存疑:无
可用代码:
google.search.WebSearch控件下的
.setSiteRestriction(site, opt_refinement, opt_moreResultsTemplate)
site:可以针对限定站点,个性化的搜索引擎
opt_refinement:针对个性化搜索引擎,可以进一步限定到一个标签子集
opt_moreResultsTemplate:可以指定按下more results链接后的页面样式模板
This sample builds on the sample above by introducing custom search engine refinements. You will note in the calls to
setSiteRestriction() for the right hand side searcher, the code is using the opt_refinement argument to further restrict the search results within the custom search engine.Curriculum Search Sample - powered by The Google AJAX Search API and Google Custom Search Engines
结论:主要针对一个个性化的搜索引擎进行搜索,包括左右两边两个搜索控件
左边的搜索控件针对整个个性化搜索引擎进行搜索,设置了more results 之后的页面样式
右边的搜索引擎包括六个搜索控件,前三个是对个性化搜索引擎的标签限定
存疑:无
可用代码:
google.search.WebSearch控件下的
.setSiteRestriction(site, opt_refinement, opt_moreResultsTemplate)
site:可以针对限定站点,个性化的搜索引擎
opt_refinement:针对个性化搜索引擎,可以进一步限定到一个标签子集
opt_moreResultsTemplate:可以指定按下more results链接后的页面样式模板
阅读笔记 Google Example Code:Custom Search Engines
地址:http://www.google.com/uds/samples/cse/index.html
This sample builds on the sample above by making heavy use of a product review custom search engine. Note the various calls to
结论:
通过cse类,同时设立了两个搜索结果框,以及最上边一个搜索输入框,和最下边一个视频搜索结果框
搜索输入框调用了searchForm控件
左右搜索结果框调用了searchControl控件,并预设了结果集大小,其中,右边同时设立了六个搜索引擎,采用标签的形式对结果分类
视频搜索结果框使用了GSvideoBar控件,可以同时实现视频搜索和选择结果播放的功能,需要在HTML页面中预设两个div用于分别显示搜索结果框和视频播放框
存疑:无
This sample builds on the sample above by making heavy use of a product review custom search engine. Note the various calls to
setSiteRestriction() all being made using a custom search engine id. The sample includes some other concepts that are not related to site restriction. These include the use of the GSearchForm object that is used to drive multiple search controls and the use of custom CSS directives that restyle portions of the search control and results.结论:
通过cse类,同时设立了两个搜索结果框,以及最上边一个搜索输入框,和最下边一个视频搜索结果框
搜索输入框调用了searchForm控件
左右搜索结果框调用了searchControl控件,并预设了结果集大小,其中,右边同时设立了六个搜索引擎,采用标签的形式对结果分类
视频搜索结果框使用了GSvideoBar控件,可以同时实现视频搜索和选择结果播放的功能,需要在HTML页面中预设两个div用于分别显示搜索结果框和视频播放框
存疑:无
阅读笔记 Google Example Code:Site Restricted Search
地址:http://www.google.com/uds/samples/apidocs/sitesearch.html
This sample demonstrates how to use the
结论:本例子在搜索中执行了限定站点搜索,并调用了定制的个性化搜索引擎,可以用这种方式在我们的搜索引擎中先搜索我们自己的站点,在通过调用我们定制的个性化搜索引擎实现我们想要的搜索功能。
存疑:为了什么每个搜索控件的结果都默认只返回一个搜索结果?虽然在搜索结果框中,每个搜索控件都对应了一个搜索结果框,并提供了选择按键,可以选择显示一个结果,多个结果和所有结果,但为什么默认只显示了一个结果?
可用注释:
google.load('search', '1');
//google.load(moduleName, moduleVersion, optionalSettings)该方法可以加载各个 AJAX API
//moduleName 是 API 的名称(例如 "maps" 或 "search")
//version 可以指定 API 模块的版本
//optionalSettings 可以为您作为 JavaScript 对象常量加载的 API 指定所有可选配置选项
Google AJAX Search API 可用参数
name: search
versions: 1
load request: google.load("search", "1");
supported options: callback, language, nocss
# callback: The function to call once the script has loaded. 后退控件
# language: The language in which to localize the API or API's UI controls. This is specified as a ISO639 language code. 语言设置
# nocss: A boolean that tells the API whether to load any style sheets typically associated with its controls. A developer might set this to false if he was completely overriding all of the loaded CSS and wanted to avoid the unnecessary load. 呈现样式
Eg.:google.load("maps", "2", {"language" : "ja_JP"});
Eg.:google.load("feeds", "1", {"nocss" : true});
This sample demonstrates how to use the
setSiteRestriction() method of the GwebSearch, GblogSearch, and GnewsSearch objects. When doing site restricted search, it is often a good idea to specify a customized label for the search result section header, and in some cases, perform some custom styling of the search results. Both of these functions are supported by using the setUserDefinedLabel() and setUserDefinedClassSuffix() methods. 结论:本例子在搜索中执行了限定站点搜索,并调用了定制的个性化搜索引擎,可以用这种方式在我们的搜索引擎中先搜索我们自己的站点,在通过调用我们定制的个性化搜索引擎实现我们想要的搜索功能。
存疑:为了什么每个搜索控件的结果都默认只返回一个搜索结果?虽然在搜索结果框中,每个搜索控件都对应了一个搜索结果框,并提供了选择按键,可以选择显示一个结果,多个结果和所有结果,但为什么默认只显示了一个结果?
可用注释:
google.load('search', '1');
//google.load(moduleName, moduleVersion, optionalSettings)该方法可以加载各个 AJAX API
//moduleName 是 API 的名称(例如 "maps" 或 "search")
//version 可以指定 API 模块的版本
//optionalSettings 可以为您作为 JavaScript 对象常量加载的 API 指定所有可选配置选项
Google AJAX Search API 可用参数
name: search
versions: 1
load request: google.load("search", "1");
supported options: callback, language, nocss
# callback: The function to call once the script has loaded. 后退控件
# language: The language in which to localize the API or API's UI controls. This is specified as a ISO639 language code. 语言设置
# nocss: A boolean that tells the API whether to load any style sheets typically associated with its controls. A developer might set this to false if he was completely overriding all of the loaded CSS and wanted to avoid the unnecessary load. 呈现样式
Eg.:google.load("maps", "2", {"language" : "ja_JP"});
Eg.:google.load("feeds", "1", {"nocss" : true});
订阅:
博文 (Atom)