Possible Google Command Update

0 views
Skip to first unread message

Chris

unread,
Sep 2, 2008, 10:40:40 PM9/2/08
to ubiquity-firefox
One of the suggested commands was a site search in google (ie
site:slashdot.org apple), it seemed to me a little strange to have two
commands for this, and not quite in line with the whole natural
language thing. So I made this update to the google command, so that
you can do something like:

google slashdot.org for apple and it will do a google search like:
site:slashdot.org apple

Any suggestions would be welcome... The only thing I can think of to
make it better would be to detect if the first argument is a domain
name, so that it would cut down on "errors", where a person actually
was using the word for in a google search.

CmdUtils.CreateCommand({
name: "google",
icon: "http://www.google.com/favicon.ico",
searchURL: "http://www.google.com/search?hl=en&q=",
description: "Searches Google for your words.",
takes: {"site_or_keywords": noun_arb_text},
modifiers: {"for": noun_arb_text},

execute: function(site_or_keywords, modifiers)
{
var query = this.buildQuery(site_or_keywords,modifiers);
Utils.openUrlInBrowser( this.searchURL + query );
},

preview: function(pblock, site_or_keywords, modifiers) {
var query = this.buildQuery(site_or_keywords,modifiers);
var pTemplate = "Searches Google for <b>${query}</b>";
var pData = {query: query };
pblock.innerHTML = CmdUtils.renderTemplate(pTemplate, pData);

var url = "http://ajax.googleapis.com/ajax/services/search/web";
var params = { v: "1.0", q: query };

jQuery.get( url, params, function(data) {
var numToDisplay = 3;
var results = data.responseData.results.splice( 0, numToDisplay );

pblock.innerHTML = CmdUtils.renderTemplate( {file:"google-
search.html"},{results:results} ); }, "json");
},

buildQuery: function(site_or_keywords, modifiers)
{
if(modifiers.for.text) { return 'site:' + site_or_keywords.text + '
' + modifiers.for.text; }
else { return site_or_keywords.text; }
},
});

pvncad

unread,
Sep 3, 2008, 1:14:06 AM9/3/08
to ubiquity-firefox
Instead of using "google slashdot.org for apple", does "google apple
in slashdot.org" looks better ?
I feel this format will give more flexibility for search as I can
start with normal google search and if I am not satisfied with
search result in preview, then i can refine it to a particular site.

Does this looks fine to you ?

-pvncad

Julien Couvreur

unread,
Sep 3, 2008, 1:43:05 AM9/3/08
to ubiquity-firefox

In addition to pvncad's variant (good idea), would it be possible for
the command to make a suggestion based on the current page's domain?
This way if you are on slashdot and Ubiq "google apple", it would
offer "google apple (in <domain>)" and "google apple in slashdot.org".

Cheers,
Julien

msk...@gmail.com

unread,
Sep 3, 2008, 7:29:47 AM9/3/08
to ubiquity...@googlegroups.com
or how about

google apple here

where,

here is the present webite?

- Mayuresh
--
Mayuresh

Chris Pickett

unread,
Sep 3, 2008, 8:34:06 AM9/3/08
to ubiquity...@googlegroups.com
Wow, great ideas guys, I'll get to work on it and see what I can do.

Thanks!

Chris Pickett

unread,
Sep 3, 2008, 9:47:40 AM9/3/08
to ubiquity...@googlegroups.com
Now it takes "in", so you can do "google apple in slashdot.org". It also takes "here", so you can also do "google apple in here" and it will pick up the current domain.

I don't know how I would go about updating the suggestion list, nor make "here" a "magic word". Any pointers?


CmdUtils.CreateCommand({
    name: "google",
    icon: "http://www.google.com/favicon.ico",
    searchURL: "http://www.google.com/search?hl=en&q=",
    description: "Searches Google for your words.",
    takes: {"keywords": noun_arb_text},
    modifiers: {"in": noun_arb_text },
   
    execute: function(keywords, modifiers)
    {
      var query = this.buildQuery(keywords,modifiers);

        Utils.openUrlInBrowser( this.searchURL + query );
     },

    preview: function(pblock, keywords, modifiers) {
        var query = this.buildQuery(keywords,modifiers);
        var pTemplate = "Searches Google for <b>${query}</b>";
        var pData = {query: query };
        pblock.innerHTML = CmdUtils.renderTemplate(pTemplate, pData);

        var url = "http://ajax.googleapis.com/ajax/services/search/web";
        var params = { v: "1.0", q: query };

        jQuery.get( url, params, function(data) {
            var numToDisplay = 3;
            var results = data.responseData.results.splice( 0, numToDisplay );

            pblock.innerHTML = CmdUtils.renderTemplate( {file:"google-search.html"},{results:results} ); }, "json");
    },

    buildQuery: function(keywords, modifiers)
    {   
        var site = modifiers.in.text;
   
        if(modifiers.in.text)
        {
            if(modifiers.in.text == "here")
            {
                bw = CmdUtils.getWindowInsecure();
                var url = bw.location.href;
                var re = /(https?:\/\/\w+?\..+\.\w+\/).*/;
                url = url.replace(re,"$1");
               
                site = url;
            }

            return 'site:' + site + ' ' + keywords.text;
        }
      else { return keywords.text; }
    },
});

David Solomon

unread,
Sep 3, 2008, 10:36:20 AM9/3/08
to ubiquity-firefox
i love it. how many times have i had to...
1. highlight the domain portion of the address i was on
2. open up a new tab
3. move my focus up to the google search bar
4. type in site:
5. paste in the domain i copied.

Yeah Mayuresh + Chris Pickett!

Julien Couvreur

unread,
Sep 3, 2008, 12:21:10 PM9/3/08
to ubiquity-firefox

Looks really good.
For the suggestion list, it may be possible to use the history/places
API to autocomplete domain names.
I'm just starting to learn it but this seems a good entry point:
http://developer.mozilla.org/en/Querying_Places

Cheers,
Julien
Reply all
Reply to author
Forward
0 new messages