Noob question: create a link to google a parameter

Hi guys, can you spare a sec?
My question is: how can I create a link so that a customer, when
clicking an author;s name, can find the results of that name googled
already(like rails entering something in the search box, find web
results and take the user to that google page)

Pls expalin the problem, step by step, NOOB HERE :frowning:

thx a billion,
radu

radu puspana wrote:

Hi guys, can you spare a sec?
My question is: how can I create a link so that a customer, when
clicking an author;s name, can find the results of that name googled
already(like rails entering something in the search box, find web
results and take the user to that google page)

Pls expalin the problem, step by step, NOOB HERE :frowning:

Well, first, you have to find out what Google needs from you. Once
youā€™ve found that, itā€™s simply a question of building the proper URL
from Rails.

thx a billion,
radu

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

thx for your time Marnen.

Iā€™ve written a complete custom built gui search engine in C++, and Iā€™m
also in the process of building a new GUI search engine for ruby. In
order to understand googleā€™s references, you have to look at their API.

http://www.googleguide.com/advanced_operators.html

This will get you started.

In terms of answering your question the search would be:

http://www.google.com/search?hl=en&as_q=&as_epq=my+author

ā€¦ where search?hl=en (means english)
ā€¦ where &as_q= (means start a query output)
ā€¦ where &as_epq= (means find an author)
ā€¦ where my+author (would be first+last name)

It seems pretty simple but itā€™s not. You should make sure that you
enforce URI encoding standards when submitting your URLs.

I hope this helps you to get started.

On Jan 27, 9:16 am, radu puspana [email protected] wrote:

It seems pretty simple but itā€™s not. You should make sure that you
enforce URI encoding standards when submitting your URLs.

What does this mean " You should make sure that you enforce URI
encoding standards when submitting your URL." ??

It basically boils down to making sure you escape special characters.
If my memory is correct ruby has some functions for url encoding
parameters in the CGI module

Fred

On Jan 26, 10:05 pm, Alpha B. [email protected] wrote:

Iā€™ve written a complete custom built gui search engine in C++, and Iā€™m
also in the process of building a new GUI search engine for ruby. In
order to understand googleā€™s references, you have to look at their API.

Google Search Operators - Google Guide

This will get you started.

That is a great site Alpha, with the tutorial and all that, much
appreciate it.Howwver i;m in a big hurry hereā€¦

enforce URI encoding standards when submitting your URLs.
What does this mean " You should make sure that you enforce URI
encoding standards when submitting your URL." ??
Can you explain the problem in more detail or give me a link? Can I
find the answer, to the URI encoding question, in the tutorial on the
site u googleguides.com ?

I hope this helps you to get started.

Many many thx,
radu

On Jan 27, 11:16 am, radu puspana [email protected] wrote:

That is a great site Alpha, with the tutorial and all that, much
appreciate it.Howwver i;m in a big hurry hereā€¦

In terms of answering your question the search would be:

"my author" - Google Search

so how can i get the parameters my and author in there.
I;m using a link_to method, something like this <%= link_to ā€œgoogle
itā€, ā€œ"my author" - Google Searchā€ %>

any idea how to do this?

I also checked the CGI module on railsapi.com, and found something
like this

Module CGI::QueryExtension

* actionpack/lib/action_controller/cgi_ext/query_extension.rb

Methods

I

    * initialize_query

Instance Public methods
initialize_query()

Neuter CGI parameter parsing.

Source: show | on GitHub

This is it? And how do i use it?

and do you know a link on how to buid links using raisl, like the one
i need?

On Jan 27, 11:31 am, Frederick C. [email protected]

Test this out in IRB so you can see what happens:

irb
require ā€˜cgiā€™
puts CGI.escape( ā€œJ.R.R. Tolkienā€ )
puts CGI.escape( ā€œJack Danielsā€ )

You can create a simple helper file that does the formatting for you and
then use a simple link_tag method to submit the link to google with the
helper.

If you donā€™t understand what Iā€™m saying here then you are not ready to
do this type of event in rails. You should read up on the very basics
for using rails at http://guides.rubyonrails.org/.

Take care,

JD

thx again for your time JD.
I did dry the code snippets you gave me, and i also searched the web
for the methods of CGI, and couldnā€™t find it anywhere, including on
railsguides.com and at railsapi.com, which served me fine up till now.

where should i get the fucntions for CGI? Can ri show them to me?How
do i do that?

if i understand correctly, regarding the link business :
first

  1. the helper file for products:(the ONLY place where I wanna use it)
    requre 'cgi
    def format_string_for_google(query)
    CGI.escape(query)
    end

2)the show.html.erb
<%=link_to ā€œgoogle itā€, "ā€œhttp://www.google.com /search?
hl=en"as_q=&ā€œas_epq=ā€ + format_string_for_google(@product.author)ā€

Is this code here of any good to my problem?

a billion thx in advance,
radu

On Jan 26, 10:05 pm, Alpha B. [email protected] wrote:

"my author" - Google Search

ā€¦ where search?hl=en (means english)
ā€¦ where &as_q= (means start a query output)
ā€¦ where &as_epq= (means find an author)
ā€¦ where my+author (would be first+last name)

Just found the google api, at
Google for Developers - Software Development Guides, Tools & More,
and there is no trace of your as_q neither as_epq :frowning: Can you tell me
why ?

It seems pretty simple but itā€™s not. You should make sure that you
enforce URI encoding standards when submitting your URLs.

I hope this helps you to get started.

ā€“
Posted viahttp://www.ruby-forum.com/.

all my best,
radu

just tested my code in my last post and worket like a charm :slight_smile:

a zillion thx to JD >:D<

So i guess iā€™m kinda ready for this type of event huh? :slight_smile:

all my best,
radu

I was just providing an example of how queries are formed. Hereā€™s a
quick and dirty test for you for the author find:

def find_author(author)
require ā€˜cgiā€™
cgi_author = CGI.escape(author)
q_author = cgi_author.gsub(/+/, ā€˜+author:ā€™) + ā€™ ā€™
query = ā€œhttp://www.google.com/groups?q=author:ā€ + q_author
link_to(author, query)
end

then call that using <%= find_author(ā€œAuthor Nameā€) %> in your views.

Note that if you searched for author in the api youā€™ll see that it only
uses author in google groups and the format is generally
author:first+author:middle+author:last etcā€¦ in the query output.

In your example, since all you need is an author, you just need to make
sure that the string for author is escaped correctly, not the entire
URL.

But, this should get you started.

On Jan 27, 7:46 pm, Alpha B. [email protected] wrote:

I was just providing an example of how queries are formed. Hereā€™s a
quick and dirty test for you for the author find:

def find_author(author)
require ā€˜cgiā€™
cgi_author = CGI.escape(author)
q_author = cgi_author.gsub(/+/, ā€˜+author:ā€™) + ā€™ ā€™
what does this line do? I know gsub will replace the +author text with
something that comes out from /+/ (althought i donā€™t know what this
regwxp could generate)

query = ā€œhttp://www.google.com/groups?q=author:ā€ + q_author
whatā€™s with google groups? i only wanted to search websites. and while
testing it in irb, shouldnā€™t it be
query = ā€œhttp://www.google.com/groups?q=ā€ + q_author ??

link_to(author, query)
end

then call that using <%= find_author(ā€œAuthor Nameā€) %> in your views.

Note that if you searched for author in the api youā€™ll see that it only
uses author in google groups and the format is generally
author:first+author:middle+author:last etcā€¦ in the query output.

In your example, since all you need is an author, you just need to make
sure that the string for author is escaped correctly, not the entire
URL.

But, this should get you started.

much appreciate it!!
radu

On Jan 27, 7:46 pm, Alpha B. [email protected] wrote:

I was just providing an example of how queries are formed. Hereā€™s a
quick and dirty test for you for the author find:

def find_author(author)
require ā€˜cgiā€™
cgi_author = CGI.escape(author)
q_author = cgi_author.gsub(/+/, ā€˜+author:ā€™) + ā€™ ā€™
what does this line do? I know gsub will replace the +author text with
something that comes out from /+/ (althought i donā€™t know what this
regwxp could generate)

query = ā€œhttp://www.google.com/groups?q=author:ā€ + q_author
whatā€™s with google groups? i only wanted to search websites. and while
testing it in irb, shouldnā€™t it be
query = ā€œhttp://www.google.com/groups?q=ā€ + q_author ??

link_to(author, query)
end

then call that using <%= find_author(ā€œAuthor Nameā€) %> in your views.

Note that if you searched for author in the api youā€™ll see that it only
uses author in google groups and the format is generally
author:first+author:middle+author:last etcā€¦ in the query output.

In your example, since all you need is an author, you just need to make
sure that the string for author is escaped correctly, not the entire
URL.

But, this should get you started.

much appreciate it!!
radu

ĆÆĀæĀ½ q_author = cgi_author.gsub(/+/, ā€˜+author:ā€™) + ā€™ ā€™
what does this line do? I know gsub will replace the +author text with
something that comes out from /+/ (althought i donā€™t know what this
regwxp could generate)

gsub is used for substitution. Unlike sub which only substitutes the
first regexp match found, gsub substitutes any number of matches found.

The /+/ is looking for anything that has a + symbol. So, My+Name+Is
etc. When you use the cgi method above on the author name, it will
correctly escape the html, which is necessary because an authorā€™s name
could be anything from First Middle Last to First M. Last etc.

Once the cgi method correctly formats the authorā€™s name, you are just
providing a bit of substitution for Googleā€™s query engine. Itā€™s going
to replace the + between the authorā€™s name with ā€˜+author:ā€™ and then add
a space after the entire string so that if you had a name like John+Doe,
it would appear as:

John+author:Doe

The query then appends this string:

query = ā€œhttp://www.google.com/groups?q=author:ā€ + q_author

ā€¦ to this ā€¦

to formā€¦

http://www.google.com/groups?q=author:John+author:Doe

And if you click the link for this above, youā€™ll see what happens when
you get to google.

Like I mentioned, you can tidy it up a bit if you want or keep it as
needed. It will work. Just replace any authorā€™s name in your view with
the helper method like I showed above and then test out your view by
clicking on the author links and youā€™ll see what happens.

You can add a lot more to this helper method or build yourself an entire
class for handling google queries and use methods from the class in your
helpers, which is what I do. I thought about handing out a plugin that
does all of this, but because google changes things often, I donā€™t want
to have to manage a project at this time. Maybe in the future
sometimeā€¦

i donā€™t know where to begin in thanking you for all the time and skill
that you put into my problem, and for explaining the problem step by
step, just like someone should for a noob.
I;ll keep in mind every tip u gave me and try tsome day to undestand
the thing with the classes and the helpers for queries and become a
query search googel exper.
Until then there is a lot of work for me, but i know i can rely on my
friends here, on RoR Talk.

all my best,
radu

p.s i know a lot of programmers and us noob programmers love a gooed
rock song, so care for Mark Knopfler? :slight_smile:
i know i do
so this is a small gift for helping a fellowpRoR programmer still in
noob form :slight_smile:

Alpha B. wrote:

No problem Radu, glad to help. Definitely start with the basics and work
your way up. One thing I would definitely suggest is learning how to
create
tests for your code and to also read a few books. I own a Kindle so I
have
a small library of roughly 12 rails books and 4 ruby books.

And for those with iPhones, you can now do likewise with the Kindle app.

If you
donā€™t
like Kindle, you can go to http://my.safaribooksonline.com/ which is
another
fantastic site that has a small monthly subscription - around 9 dollars
or
so a month. What I like about safaribooksonline is that you can select
and
rotate up to 4 books a month. So, I keep 4 books for one month, read
through them and then the following month I swap them out for new books.

Personally, I donā€™t like the idea of learning Rails from books. It
changes too fast. (Iā€™m also a cheapskateā€¦ :slight_smile: )

If
one is really good for reference, I add it to my Kindle.

Books = food

Yeah.

Sincerely,

Joel D.
Website Bio: http://jdezenzio.com/
Rails Production Sites: http://ncaastatpages.com

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

No problem Radu, glad to help. Definitely start with the basics and work
your way up. One thing I would definitely suggest is learning how to
create
tests for your code and to also read a few books. I own a Kindle so I
have
a small library of roughly 12 rails books and 4 ruby books. If you
donā€™t
like Kindle, you can go to http://my.safaribooksonline.com/ which is
another
fantastic site that has a small monthly subscription - around 9 dollars
or
so a month. What I like about safaribooksonline is that you can select
and
rotate up to 4 books a month. So, I keep 4 books for one month, read
through them and then the following month I swap them out for new books.
If
one is really good for reference, I add it to my Kindle.

Books = food

Sincerely,

Joel D.
Website Bio: http://jdezenzio.com/
Rails Production Sites: http://ncaastatpages.com