[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 583
  • Last Modified:

How to customize google search

Hello,
I need help to customize google search. I've created serach form use Google search form builder, but and i want to change it significantly.
I have the following form:

<!-- Search Google -->
<center>
<FORM method=GET action=http://www.google.com/custom>
<TABLE bgcolor=#FFFFFF cellspacing=0 border=0>
<tr valign=top><td>
<A HREF=http://www.google.com/search>
<IMG SRC=http://www.google.com/logos/Logo_40wht.gif border=0 ALT=Google align=middle></A>
</td>
<td>
<INPUT TYPE=text name=q size=41 maxlength=255 value="">
<INPUT type=submit name=sa VALUE="Google Search">
<INPUT type=hidden name=cof VALUE="AH:center;AWFID:c1146e3ff40cb472;">
<input type=hidden name=domains value="www.google.com"><br><input type=radio name=sitesearch value=""> Search WWW <input type=radio name=sitesearch value="www.google.com" checked> Search www.google.com 
</td></tr></TABLE>
</FORM>
</center>
<!-- Search Google -->

I want to have form like this:

http://img136.imageshack.us/img136/2464/cusomgoogle6kw.gif

I want to add a special search operators for custom search(that do not write operators each time). This special operators can be inside a javascript, which will automatically add it to queries, depending of what radiobox is checked, jscript then redirect request to Google.  
I need 3 type of search: for mp3, ebooks and rapidshare.de. All these 3 types need be applied to two sort of searching: in the Net(WWW), and inside pages in specific language(russian).
Operators for mp3 search:

intitle:index.of + "mp3" + "band name" -htm -html -php -asp
Variable is  "band name", which I write in search field.

For ebooks:

-inurl:htm -inurl:html intitle:"index of" +("/ebooks"|"/book") +(chm|pdf|zip) +"Author"    
Variable is  "Author"

For rapidshare:

+inurl:rar|zip site:rapidshare.de +"File name"     [also I want to add "-deleted" to filter out some of the inactive files]
Variable is  "File name"

Google query samples:
in www:
http://www.google.com/search?hl=ru&q=ford&btnG=%D0%9F%D0%BE%D0%B8%D1%81%D0%BA+%D0%B2+Google&lr=
in pages in a specific language:
http://www.google.com/search?hl=ru&q=ford&btnG=%D0%9F%D0%BE%D0%B8%D1%81%D0%BA&lr=lang_ru

Thanks
0
Sirocco
Asked:
Sirocco
  • 14
  • 12
  • 7
1 Solution
 
Michel PlungjanIT ExpertCommented:
You will need to tweak the extra strings... But it is all there I believe

<!-- Search Google -->
<center>
<script>
mp3='-htm -html -php -asp intitle:index.of mp3 ';
ebooks = '-inurl:htm -inurl:html intitle:"index of" +("/ebooks"|"/book") +(chm|pdf|zip)'
rapidshare= '+inurl:rar|zip site:rapidshare.de -deleted'
extra = mp3; // default
</script>
<FORM method="GET" action="http://www.google.com/custom"
onSubmit="loc=this.action+
'?'+escape(this.sa.value)+
'&'+escape(this.cof.value)+
'&'+escape(this.domains.value)+
'&sitesearch='+((this.sitesearch[0].checked)?this.sitesearch[0].value:this.sitesearch[1].value)+
'&q='+escape(extra+' '+this.q.value);
location=loc;
return false">
<TABLE bgcolor=#FFFFFF cellspacing=0 border=0>
<tr valign=top><td>
<A HREF=http://www.google.com/search>
<IMG SRC=http://www.google.com/logos/Logo_40wht.gif border=0 ALT=Google align=middle></A>
</td>
<td>
<INPUT TYPE=text name=q size=41 maxlength=255 value="">
<INPUT type=submit name=sa VALUE="Google Search">
<INPUT type=hidden name=cof VALUE="AH:center;AWFID:c1146e3ff40cb472;">
<input type=hidden name=domains value="www.google.com"><br>
<input type=radio name=sitesearch value=""> Search WWW
<input type=radio name=sitesearch value="www.google.com" checked> Search www.google.com <br>
<input type="checkbox" name="hl" value="ru">In russian<br>
<input type="radio" name="x" checked onClick="extra=mp3"> mp3<br>
<input type="radio" name="x" onClick="extra=ebooks"> ebooks<br>
<input type="radio" name="x" onClick="extra=rapidshare"> rapid
</td></tr></TABLE>
</FORM>
</center>
<!-- Search Google -->
0
 
SiroccoAuthor Commented:
Still want tweaks a little: to make also general search(without a special syntax), default.
If I need special search, then I select one from them (mp3 is default)

No needs for special checkbox 'In russian', its preferable to have radiobox 'search pages in russian', and language and interface
preferences probably can be inside form.

'Search WWW' -search pages in all languages; browser http sample http://www.google.com/search?hl=ru&q=...&lr=
'search pages in russian'-in russian only; browser http sample http://www.google.com/search?hl=ru&q=...&lr=lang_ru

Can i cut out <INPUT type=hidden name=cof VALUE="AH:center;AWFID:c1146e3ff40cb472;">  -it not needs, same as use action="http://www.google.com/search" ?
0
 
Michel PlungjanIT ExpertCommented:
This one will use google default - radio to search in russian no cof:

<!-- Search Google -->
<center>
<script>
mp3='-htm -html -php -asp intitle:index.of mp3 ';
ebooks = '-inurl:htm -inurl:html intitle:"index of" +("/ebooks"|"/book") +(chm|pdf|zip)'
rapidshare= '+inurl:rar|zip site:rapidshare.de -deleted'
extra = ''// default
</script>
<FORM method="GET" action="http://www.google.com/custom"
onSubmit="loc=this.action+
'?'+escape(this.sa.value)+
'&'+escape(this.domains.value)+
'&sitesearch='+((this.sitesearch[0].checked)?this.sitesearch[0].value:this.sitesearch[1].value)+
'&q='+escape(extra+' '+this.q.value);
location=loc;
return false">
<TABLE bgcolor=#FFFFFF cellspacing=0 border=0>
<tr valign=top><td>
<A HREF=http://www.google.com/search>
<IMG SRC=http://www.google.com/logos/Logo_40wht.gif border=0 ALT=Google align=middle></A>
</td>
<td>
<INPUT TYPE=text name=q size=41 maxlength=255 value="">
<INPUT type=submit name=sa VALUE="Google Search">
<input type=hidden name=domains value="www.google.com"><br>
<input type=radio name=sitesearch value=""> Search WWW
<input type=radio name=sitesearch value="www.google.com" checked> Search www.google.com <br>
<input type="radio" name="hl" value="" onClick="this.lr.value=''">In any language<br>
<input type="radio" name="hl" value="ru" onClick="this.form.lr.value='lang_ru'">In russian<br>
<input type="hidden" name="lr" value="">
<input type="radio" name="x" checked onClick="extra=''"> Default google<br>
<input type="radio" name="x" onClick="extra=mp3"> mp3<br>
<input type="radio" name="x" onClick="extra=ebooks"> ebooks<br>
<input type="radio" name="x" onClick="extra=rapidshare"> rapid
</td></tr></TABLE>
</FORM>
</center>
<!-- Search Google -->
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mvan01Commented:
check this:

this.lr.value

should be:

this.form.lr.value

Maybe add <hr> there, also:

  ...
<input type="radio" name="hl" value="" onClick="this.form.lr.value=''">In any language<br>
<input type="radio" name="hl" value="ru" onClick="this.form.lr.value='lang_ru'">In russian<br>
<hr width="200" align="left">
<input type="hidden" name="lr" value="">
  ...

Peace and joy.  mvan
0
 
Michel PlungjanIT ExpertCommented:
yeah, thanks.
0
 
SiroccoAuthor Commented:
well, does it possible to have two options 'Search WWW'(which search www in any language) and 'Search pages in russian'(which search pages in russian), without adding two extra radioboxes below 'In any language' and 'In russian'? This implies already search in whole Net(first one), and search language specific pages(second one).
0
 
SiroccoAuthor Commented:
is there a way?
0
 
Michel PlungjanIT ExpertCommented:
Yes, with a checkbox.
0
 
SiroccoAuthor Commented:
google uses just 2 radiobox, config is inside code
 http://www.google.com/search?hl=ru&q=...&lr=
0
 
mvan01Commented:
Sirocco,

I think you need to clarify what you want the choice to do.  I believe there are two possibilities:
1)  Google query page should be displayed in Russian (as your link above, so your page would have to change its words to Russian as well)
2)  Google search results should only return links to pages which have Russian text

These two choices may be independent choices, and I 'think' google can do either / both.  mplungjan will need to know which you desire, to help you adjust the code.

Peace and joy.  mvan
0
 
SiroccoAuthor Commented:
Yes, I meant this, Google query page (user interface) displayed in Russian. But this not really very important, query page can be in english.
The difference is that 'Search the Web' return results in any lanuage, and 'Search Russian pages' should return results to pages which have Russian text.
-examples:
in russian:

http://www.google.com/search?hl=ru&q=...&lr=
http://www.google.com/search?hl=ru&q=...&lr=lang_ru

in english:

http://www.google.com/search?hl=en&q=...&lr=
http://www.google.com/search?hl=en&q=...&lr=lang_ru

Checked need be 'Search the Web'  http://www.google.com/search?hl=en&q=...&lr=lang_ru

0
 
mvan01Commented:
So (by your example above) ...
hl= sets the language of the query page
lr= limits the results pages to come from a specific language

and mplungjan's code sort of mixed references to the two together, tying:
radio name="hl"
to the lr.value ...

Maybe, if the query page presented in english language is OK, leave "hl" out of the html & code, and include only a checkbox named "lr":

<input type="checkbox" name="lr" value="lang_ru">Find only Russian language pages<br>

And, when building onSubmit="loc=...", add this:

'&lr='+((this.form.lr.checked)?this.form.lr.value:'')+

Peace and joy.  mvan
0
 
mvan01Commented:
Sorry, maybe include
hl=en
at the beginning of every search action (instead of leaving it out altogether).  But apparently we don't need it to be selectable.

Peace and joy.  mvan
0
 
SiroccoAuthor Commented:
what I mean:

http://img232.imageshack.us/img232/5876/google27ay.jpg
('Default google' is search without special syntax)

or, even more simple(this is better):

http://img101.imageshack.us/img101/4596/google31um.jpg
when we need search for mp3/ebook/rapid we will check required box. Default is not use special searches.
0
 
Michel PlungjanIT ExpertCommented:
However a radio is a set where one is selected.
Perhaps use a dropdown instead
0
 
SiroccoAuthor Commented:
Yes, right. Dropdown or checkbox is the way. But dont know how to implement this correctly.
0
 
Michel PlungjanIT ExpertCommented:
<!-- Search Google -->
<center>
<script>
extra = ''// default
extras = new Array('',
'-htm -html -php -asp intitle:index.of mp3 ',
'-inurl:htm -inurl:html intitle:"index of" +("/ebooks"|"/book")+("chm"|"pdf"|"zip") ',
'+inurl:rar|zip site:rapidshare.de -deleted '
);
</script>
<form method="GET" action="http://www.google.com/custom"
onSubmit="loc=this.action+
'?'+escape(this.sa.value)+
'&'+escape(this.domains.value)+
'&lr='+((this.lr[0].checked)?this.lr[0].value:this.lr[1].value)+
'&q='+escape(extra+' '+this.q.value);
location=loc;
return false">
<table bgcolor=#FFFFFF cellspacing=0 border=0>
<tr valign=top><td>
<a href="http://www.google.com/search"><img src="http://www.google.com/logos/Logo_40wht.gif" border="0" ALT="Google" align="middle"></a>
</td>
<td>
<INPUT TYPE=text name=q size=41 maxlength=255 value="">
<INPUT type=submit name=sa VALUE="Google Search">
<input type=hidden name=domains value="www.google.com"><br>
<input type=radio name="lr" value="" checked> Search WWW
<input type=radio name="lr" value="lang_ru"> Search russian pages
<select onChange="extra=extras[this.selectedIndex]">
<option>Default google</option>
<option>mp3</option>
<option>ebooks</option>
<option>rapidshare</option>
</td></tr></table>
</form>
</center>
<!-- Search Google -->
0
 
SiroccoAuthor Commented:
I tested and find that code often not remember the special selection: when we use 'Search the Web' +'mp3', it return result without a special syntax, though selection was 'mp3':
 http://www.google.com/custom?Google%20Search&www.google.com&lr=&q=%20benassi

To make selection take effect with spec syntax, we need first make search use 'Default google' option, then swith to 'mp3'. Same for other(ebooks, etc)
0
 
SiroccoAuthor Commented:
P.S. how to make the search form always stay on top of the page(on returned search results pages)? Use some frames?
0
 
Michel PlungjanIT ExpertCommented:
Yes
<!-- Search Google -->
<center>
<script>
extra = ''// default
extras = new Array('',
'-htm -html -php -asp intitle:index.of mp3 ',
'-inurl:htm -inurl:html intitle:"index of" +("/ebooks"|"/book")+("chm"|"pdf"|"zip") ',
'+inurl:rar|zip site:rapidshare.de -deleted '
);
</script>
<form method="GET" action="http://www.google.com/custom"
onSubmit="loc=this.action+
'?'+escape(this.sa.value)+
'&'+escape(this.domains.value)+
'&lr='+((this.lr[0].checked)?this.lr[0].value:this.lr[1].value)+
'&q='+escape(extra+' '+this.q.value);
document.getElementById('qloc').innerHTML='['+loc+']';
window.frames['results'].location=loc;
return false">
<table bgcolor=#FFFFFF cellspacing=0 border=0>
<tr valign=top><td>
<a href="http://www.google.com/search"><img src="http://www.google.com/logos/Logo_40wht.gif" border="0" ALT="Google" align="middle"></a>
</td>
<td>
<INPUT TYPE=text name=q size=41 maxlength=255 value="">
<INPUT type=submit name=sa VALUE="GO"><br><span id="qloc">[search string will appear here]</span>
<input type=hidden name=domains value="www.google.com"><br>
<input type=radio name="lr" value="" checked> Search WWW
<input type=radio name="lr" value="lang_ru"> Search russian pages
<select onChange="extra=extras[this.selectedIndex]">
<option>Default google</option>
<option>mp3</option>
<option>ebooks</option>
<option>rapidshare</option>
</td></tr></table>
</form>
</center>
<!-- Search Google -->
<iframe name="results" width="100%" height="90%"></iframe>
0
 
Michel PlungjanIT ExpertCommented:
You may raise the points ;)
0
 
SiroccoAuthor Commented:
Certainly, I'll increase points to 175  :)
I am entirely satisfied, it works as required now.

If we will not display search string inside our form, then we can no retain our form on a search result page?

<span id="qloc">[search string will appear here]</span>
0
 
Michel PlungjanIT ExpertCommented:
I put that there for you to see the search string was what you wanted while testing

Remove the lines
document.getElementById('qloc').innerHTML='['+loc+']';
and
<span id="qloc">[search string will appear here]</span>

to get rid of it.

Michel
0
 
SiroccoAuthor Commented:
Done. But something goes wrong -not work:

http://mariner.atspace.com/googletest.html
0
 
Michel PlungjanIT ExpertCommented:
Paste error

Load the page in Firefox tells you the error and points you at it:

Error: unterminated string literal
Source File: http://mariner.atspace.com/googletest.html
Line: 10, Column: 8
Source Code:
extra = "// default

---------------

You need to change the single double quote to two single quotes
extra = "// default
to
extra = ''/ default
0
 
mvan01Commented:
ah ... that should be:

extra = ''  // default
(two single quotes & two slashes for comment)

or:

extra = ""  // default
(two double quotes & two slashes for comment)

Either could optionally be terminated with semi-colon:

extra = '';  // default

or

extra = "";  //default

Peace and joy.  mvan
0
 
SiroccoAuthor Commented:
Opps - this was my error: when I copied a code I thought, that its a copying error and there need be double quote instead and I changed it.

extras = new Array(' ', <-- does this also required two single quotes?

'-htm -html -php -asp intitle:index.of mp3 ', <-- there is a space between mp3 and quote, right?
0
 
mvan01Commented:
Yes, on both.  However on the first, mplungjan had no space between the two single quotes.  I don't know if the extra space matters in that one.

Just a note, which may help you -- in windows, I click and highlight the code in the browser, then Edit -> Copy (or usually just press [Ctrl]+[C]) to copy it into the clipboard, then paste it into notepad or whatever I'm using to edit the code.  It save mis-understanding what the expert meant.  :-)

Peace and joy.  mvan
0
 
Michel PlungjanIT ExpertCommented:
Yes there is a space. It is not needed really since I also have a space here
extra+' '+this.q.value)

so you can remove EITHER but not both.

There is no space needed in the

extras = new Array('',
It is used to empty the extra when you select a normal search

Michel
0
 
SiroccoAuthor Commented:
I corrected, but my IE6.0 show error in status bar:

Line: 11
Char: 22
Error: Unterminated string constant
code: 0
0
 
Michel PlungjanIT ExpertCommented:
No you did not

Error: unterminated string literal
Source File: http://mariner.atspace.com/googletest.html
Line: 11, Column: 19
Source Code:
extras = new Array(",

is STILL using a double quote
it must be

extras = new Array('',

just cut and paste the above
0
 
SiroccoAuthor Commented:
Michel and mvan01,

thank you for the help! :)

Sirocco
0
 
mvan01Commented:
Sirocco,

You are welcome.  I've also learned something from you, regarding useful google query strings.

Peace and joy.  mvan
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 14
  • 12
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now