Abzetdin Adamov's IT Blog

IT is about doing more with less!

Posts Tagged ‘Search Engines’

Fully Customized Search Engine by Google Search Ajax API

Posted by Abzetdin Adamov on March 13, 2011

The information is most valuable wealth of humanity today. According to IDC Report we all are getting to be richer rapidly in this meaning. So that, according to this report (The Digital Universe Decade – Are You Rady? ) the amount of digital data worldwide (Digital Universe) will grow this year to 1.2 million petabytes or 1.2 zettabytes. Annual growth makes up more than 60%. By 2020 our Digital Universe will be 44 times as big as it was in 2009.
So, the ability to find appropriate piece of information within this tremendous amount structured and unstructured data getting to be more and more important. It’s why we all love Google so much! But Google is not self-centred (selfish), but rather Google makes his own technology opened for others to develop customized Search Engines, in particular (to be рonest this opennes is restricted, unfortunately).

I’m going to share with you my Fully Customized Search Engine developed by using Google Search Ajax API. If you have an idea how to improve it or you may want to share your mind, feel free to drop a comment.

HTML Code of Customized Search String Input within Container. Don’t forget to get your own Google Ajax API Key at http://code.google.com/apis/loader/signup.html
Download all in one: GSearchEngine.zip

Primary JavaScript Code based on Google Search Ajax API

//////////////////////////////////////////////////////////
// Abzetdin Adamov
// Fully Customized Search Engine by Google Search Ajax API
// JavaScript Code based on Google AJAX API
// Last modified 03/13/2011
//////////////////////////////////////////////////////////

var searchControl;
window.onload = onLoad;

function onLoad() {
searchControl = new GSearchControl();
//SMALL_RESULTSET, LARGE_RESULTSET
searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);

//EXPAND_MODE_PARTIAL, EXPAND_MODE_OPEN, EXPAND_MODE_CLOSED
searchOptions = new google.search.SearcherOptions();
searchOptions.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);

var webSrearch = new GwebSearch();
webSrearch.setUserDefinedLabel("myWeb");
searchControl.addSearcher(webSrearch, searchOptions);

var siteSearch = new GwebSearch();
siteSearch.setUserDefinedLabel("Adamov.net.ru");
siteSearch.setSiteRestriction("adamov.net.ru");
searchControl.addSearcher(siteSearch);

var blogsSrearch = new GblogSearch();
blogsSrearch.setUserDefinedLabel("myBlogs");
searchControl.addSearcher(blogsSrearch);

var imgSrearch = new GimageSearch();
imgSrearch.setUserDefinedLabel("myImages");
searchControl.addSearcher(imgSrearch);

var drawOptions = new GdrawOptions();
// DRAW_MODE_TABBED, DRAW_MODE_LINEAR
drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
drawOptions.setInput(document.getElementById('queryInput'));
searchControl.draw(document.getElementById("searchcontrol"), drawOptions);

inputBlur();
}
var query = null;
document.onkeydown = function(event) { kd(event); };

document.getElementById('queryInput').onfocus = function(event) { inputFocus(event); };
document.getElementById('queryInput').onblur = function(event) { inputBlur(event); };

var searched = false;
function kd(e) {
if (!e) e = event;
if (query == null)
query = document.getElementById('queryInput');
if (e.keyCode == 27) {
query.value = '';
searchControl.clearAllResults();
}
query.focus();
}

function inputFocus() {
var queryInput = document.getElementById('queryInput');
queryInput.style.color = "#555";
if (queryInput.value && queryInput.value == "Введите строку для поиска в Adamov.net.ru") {
queryInput.value = "";
}
}

function inputBlur() {
var queryInput = document.getElementById('queryInput');
queryInput.style.color = "#bbb";
if (!queryInput.value) {
queryInput.value = "Введите строку для поиска в Adamov.net.ru";
}
}

Fully Customized Search Engine: DEMO
Download all in one: GSearchEngine.zip

Advertisements

Posted in Programming and Development, Web Programming and Design | Tagged: , , | Leave a Comment »