LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-19-2010, 06:52 AM   #1
phodopus
Member
 
Registered: Aug 2006
Location: Belgium
Distribution: Slackware 13.0
Posts: 62

Rep: Reputation: 15
Question How do a make a custom Google search?


Hello all,


I would like to make a (html) form which enables me to do a custom Google search query. If I enter for example 10 keywords in a text area (every line contains a word), I should see how much "Estimated results" there are for every keyword.

I think I should use the Google AJAX Searcg API, but I don't really understand how to use it exactly.

http://code.google.com/apis/ajaxsear..._class_GSearch

I read this:
google.search.Search - Properties

.estimatedResultCount - supplies the estimated number of results that match the current query. Note that this value will not necessarily match the similar value thats visible on the Google.com search properties.

So I need to use the method mentioned above. But how? I don't expect to to get the full working thing as a reply. I know enough JS to read the words for example. But how to work with the Google API, let alone the method for Estimated search results isn't yet my cup of tea :-).

Thanks in advance,

Hendrik
 
Old 05-20-2010, 01:11 AM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

1. I assume you know basic HTML and basic Javascript

2. You'll need to get a special API key:
http://code.google.com/apis/ajaxsearch/signup.html

3. Write a simple, test HTML page that:
http://code.google.com/apis/ajax/documentation/
a) loads the Google Ajax API:
Code:
<script type="text/javascript"
        src="http://www.google.com/jsapi?key=ABCDEFG"></script>
b) loads the Google search API:
[code]<script type="text/javascript">
google.load("search", "1");
</script>[code]

4. Create an HTML form with a text field, and use Javascript to wire it to the Google search API

Here's a complete example, with all of the above steps:

http://code.google.com/edu/ajax/tuto...earch-api.html

5. Finally, once you're getting the basic results you want, add new elements to your HTML page ("<div>" elements are a good choice, but you've got lots of options) and use Javascript to access the .EstimatedResultCount properties and display them as dynamic HTML.

Here's another (complete) example that:
a) loads the Google API
b) registers a callback for "search complete"
c) invokes the search
d) uses the callback to update some dynamic HTML
http://www.webmonkey.com/2010/02/get...and_ajax_apis/

'Hope that helps .. PSM

Last edited by paulsm4; 05-20-2010 at 01:12 AM.
 
Old 05-20-2010, 11:37 AM   #3
phodopus
Member
 
Registered: Aug 2006
Location: Belgium
Distribution: Slackware 13.0
Posts: 62

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by paulsm4 View Post
Here's a complete example, with all of the above steps:

http://code.google.com/edu/ajax/tuto...earch-api.html

5. Finally, once you're getting the basic results you want, add new elements to your HTML page ("<div>" elements are a good choice, but you've got lots of options) and use Javascript to access the .EstimatedResultCount properties and display them as dynamic HTML.

Here's another (complete) example that:
a) loads the Google API
b) registers a callback for "search complete"
c) invokes the search
d) uses the callback to update some dynamic HTML
http://www.webmonkey.com/2010/02/get...and_ajax_apis/

'Hope that helps .. PSM
Thanks for the advice. It was helpful.

So I started with the first link you gave. I added this (in a nutshell):

var cursor = gSearch.cursor;
var estCount = cursor.estimatedResultCount;


1) Using my app, when I enter a word, the app gives me the estimatedResultCount. But the result count is nothing near to what www.google.com gives me. I know that it's normal that there is a slight difference between the catch and the real think, but take a look at this:

using my app (http://deblanger.be/estResults/:

myQuery : 96,200 estimated results.

using www.Google.com:

About 716,000 results (0.25 seconds)

So what causes this huge difference?

2) If I enter 20 words in the textarea, the app should look for every word individualy, and not see the 20 words as one string. Do you (someone) know how to do this?

If someone knows the answer to my first question I'd be already more than happy. The second one I'll find myself, just have to dig a bit in the javascript world..

Thanks in advance.

Last edited by phodopus; 05-20-2010 at 12:10 PM.
 
Old 05-20-2010, 04:08 PM   #4
phodopus
Member
 
Registered: Aug 2006
Location: Belgium
Distribution: Slackware 13.0
Posts: 62

Original Poster
Rep: Reputation: 15
Take a look at this:

http://deblanger.be/estResults/

The application works, although the results are totally different from those that you find if you google.com them. As I mentioned before: it's normal that the 2 results (http://deblanger.be/estResults/ & www.google.com) aren't perfectly the same. But the differences between the results that I get are to big to be 'normal'.

Any suggestions?
 
  


Reply

Tags
ajax, api, google, html, javascript, search


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you make search ...search a string in a link....a url...a web address aus9 LQ Suggestions & Feedback 4 04-16-2008 10:37 AM
Apple Spotlight, MS Desktop Search and Google Desktop Search. What do you think? Mega Man X General 16 07-10-2007 01:50 PM
Google search on CD Zuggy General 1 12-17-2004 10:55 AM
I want to make search engine like google balanagireddy Programming 4 07-15-2004 08:25 AM
i want to make a search engine like google , but limited to some urls varzosu Programming 3 06-27-2004 05:40 PM


All times are GMT -5. The time now is 11:47 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration