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);
订阅:
博文评论 (Atom)
0 评论:
发表评论