LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   How do a make a custom Google search? (http://www.linuxquestions.org/questions/programming-9/how-do-a-make-a-custom-google-search-808802/)

phodopus 05-19-2010 05:52 AM

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

paulsm4 05-20-2010 12:11 AM

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

phodopus 05-20-2010 10:37 AM

Quote:

Originally Posted by paulsm4 (Post 3974974)
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.

phodopus 05-20-2010 03:08 PM

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?


All times are GMT -5. The time now is 10:16 AM.