If you get a "business" (paid) account on Google Custom Search, you are allowed to get search results via XML and display them in your site however you want, without ads, and without using JavaScript or iFrames.

I have successfully modified your google_cse module so that it can do this. Probably other sites would find this useful, so I thought I'd file a Feature Request with my changes.

I can attach a patch if you want, but there are so many changes I thought it might be simpler just to attach the rewritten module itself. Besides making this new display option, I also added a bunch of other options to the Settings page that allow you to customize more of the text in the output of the module. And since there were now a lot of options, I rearranged the options screen (added some more fieldsets and changed the order of some fields).

I will also attach a few lines to be added to the CSS file for the new display option.

I did this for a Drupal 5 site, so I have only done this for the Drupal 5 version of your module, but it would probably be good to do it for Drupal 6 as well. Feel free to use the code as you see fit, and let me know if you'd like the patches in a different format.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

msteudel’s picture

Any chance to get this integrated? This is a great third option.

samc’s picture

I was hoping the CSE module did this, and am very glad to find this patch. I'd love to see it integrated in as well.

mfb’s picture

A patch on drupal-6 would be preferred, otherwise I'll have to do a lot of work to integrate this.

samc’s picture

I've been playing with the XML feature and it works great.

In addition, I've further modified the code posted above to support the use of GCSE's labels and refinements. I.e. the "Refine your search for 'blah'" features.

I'm happy to share what I've got with anyone interested. I wasn't sure it made sense to post a patch against a patch, but once the base XML feature is integrated in I'd be happy to roll something.

mfb’s picture

Rather than posting a patch of a patch, just reroll the patch. But it also needs to be rerolled for d6.

jhodgdon’s picture

Sorry - my client's site was started a while back and was using D5, so that is why the patch is for D5.

redping’s picture

Is this change available for drupal 6 module? I only see that you can choose where you want the ads to be displayed and I don't see an option for using a business account

samc’s picture

Version: 5.x-1.6 » 6.x-1.x-dev
Status: Active » Needs review
FileSize
19.15 KB

I recently updated my site to 6.x and as result finally bit the bullet and updated the XML Results patch.

The attached patch contains the functionality of the original patch, along with my "refinements" feature and other fixes. Full themability of the results is provided as well.

I'd love to get some other testers/reviewers involved and eventually get this added to the module!

pottercreative’s picture

Really nice patch. Working very nicely with the exception of an error that I'm not quite understanding how to fix.

warning: Invalid argument supplied for foreach() in /nfs/c04/h05/mnt/84547/domains/centerspace.net/html/modules/google_cse/google_cse.theme.inc on line 110.

Quick fix?

samc’s picture

Thanks for posting! Yes, fortunately it's a quick fix. The original patch assumed that search refinement labels were present.

Updated patch attached.

pottercreative’s picture

Sam, thanks so much. Worked great. Had to uninstall, delete the google_cse directory, but I assumed that's what I needed to do before applying the patch.

Another question. I'm trying to display the search box block in the header region of my site so it's persistent across all pages. Not having much luck. Does this require the Drupal Core 'Search' module to be enable or am I having other issues?

Also, wondering if I can modify the code so that the search results resolve to /search instead of /search/google

Thanks for your help.
Cheers,
Ben

samc’s picture

The search form is built into our site's template, so I haven't run into that issue. You can see it on the site here: http://www.appistry.com.

You should be able to drop some HTML into a custom block to accomplish the same thing. Here is the HTML from our site:

<div id="search-form">
  <form action="/search/g" method="get" id="search-appistry">
    <div class="search">
      <input border="0" type="text" id="search" class="emptyonclick input-text" name="query" value="Search Appistry.com" />
    </div>
    <input type="submit" class="search-button" name="submit" id="search" value="Search" />
  </form>
</div><!-- /search-form -->

There is a preference that allows you to change /search/google to /search/something-else. I have mine set to "g" as it seemed less intrusive. I haven't looked into trying to override the default search so that this isn't necessary.

BenK’s picture

Subscribing and will test....

kim.pepper’s picture

Subscribing

scip’s picture

Thanks, this is working for me, with the following issues:

  • If the "google" module is included, to allow switching between Drupal site search and Google search then it alwayes uses the javascript version
  • I couldn't see the preference in #12 which suggested a change of arg(1). This may fix my issue I guess...
webdrips’s picture

This is a great module and a great patch, so first off, thank you all for both the module and patches!

However, as @scip pointed out, the patch in #10 doesn't work unless the optional google.module is disabled.

Unfortunately, I need this optional module to be working. I'm going to see if I can dig up the answer, but if someone can shine some light in the meantime, it would be most appreciated.

(I had the free Google version and made some mods to both .module files to use the site search box to display the Google results without all the extra tabs.)

Thanks in advanced,

Dan

samc’s picture

I looked into these issues this evening. It looks like:

1. The admin setting that allows you to change your search path (e.g. from 'search/google' to 'search/g') didn't survive the update to D6.
2. That setting is incompatible with the D6 core search system, and thus incompatible with the google.module that is included in CSE.
3. I have verified that after deleting the variable google_cse_results_path, or setting it to the default 'search/google', the patched CSE module seems to work fine with the google.module for me.

Because of #1, I wouldn't expect anyone who applies the patch to see #2, so I'm left wondering if either of you (@scip or @daneesia) manually set google_cse_results_path by any chance? Can you verify that the variable either isn't set or is set to the default?

Sam

webdrips’s picture

Thanks for your help samc!

Note: I'm using the patched version of 6.x-1.2 instead of the patched dev version if that makes a difference.

Here's what I find strange now that you brought it up: with a quick search across all files for "google_cse_results_path", all the results I get are: variable_get('google_cse_results_path', 'search/google').

Yet when I insert the following into the theme file: <?php print 'path: ' . variable_get('google_cse_results_path'); ?>, I get "path: ", so it seems that somehow the variable is getting nulled out.

Not sure what's going on, but when I add <?php variable_set('google_cse_results_path', 'search/google'); ?>, followed by the print statement, I get "path: search/google"....maybe a bug with variable_get()? Isn't it supposed to set it to the second argument if the variable is null?

samc’s picture

@daneesia:

Nothing strange about what you're seeing. variable_get returns the value of the variable name passed as the first arg, or the second argument if the variable isn't set. It does not ever set the variable, just returns a default value. Remember to issue variable_del to delete the value you set.

You mentioned modifications to google.module and google_cse.module. Are you experiencing problems with the modified version, or with 6.x-1.2 and the applied patch #10?

When you say "I had the free Google version...," are you now using a paid Google Custom Search account? I think that's the only way you can get XML results.

When you say the "patch doesn't work," what exactly are you seeing? Is the site available publicly?

webdrips’s picture

@samc ahh that makes more sense reg. variable_get().

I put the original files back in place and then applied the patch again (to ver 6.x-1.2) and I was back to another issue I was seeing originally seeing: the search uses the javascript/iFrame solution (and yes with the "On this site (without JavaScript or frames, requires current Google Business account)" selected).

In any case, that did not help as I had to disable the optional module to get it to display the XML-based results. So out of the box, there is an issue with 6.x-1.2 and the applied patch.

Yes I am now using the paid account (and it works so long as the optional module is disabled).

I can send you a private message with the site name if needed.

Thanks again,

Dan

webdrips’s picture

Update:

So I decided that maybe I don't really need google.module, so I disabled it along with the Drupal search module, but there are a few more things that don't appear to be working (but that did work with the google.module and search.module enabled).

The most important is the sitesearch parameter is being ignored.

There are other issues, but right now, that is the most important.

As always, any help is most appreciated.

Thanks,

Dan

webdrips’s picture

Found the issue: seems _google_cse_get_search_results() was not designed to handle the sitesearch variable (and other variables I'm guessing but will report back on that tomorrow).

Here's my basic hack of the $query array (with the sitesearch key added):

$query = array(
    'q' => $_GET['refinement'] == '' ? $_GET['query'] : $_GET['query'] . ' more:' . $_GET['refinement'],
    'start' => $_GET['start'],
    'num' => variable_get('google_cse_results_num', 10),
    'client' => 'google-csbe',
    'output' => 'xml_no_dtd',
    'cx' => variable_get('google_cse_cx', ''),
    'sitesearch' => $_GET['sitesearch'],
    ) + google_cse_advanced_settings();

Note: results only applied to first page, so Next page link is not carrying the entire query string...will research that as well.

dkinzer’s picture

I was just about to start coding this feature when I found this patch. Thanks! So, does anyone know if it's ever going to be committed or at least made into it's own separate module?

rp7’s picture

samc, great work on the patch, thanks a lot for the effort.

Unfortunately I'm still experiencing the error message patch #2 was supposed to fix.

"# warning: Invalid argument supplied for foreach() in ...\sites\all\modules\google_cse\google_cse.theme.inc on line 124."

Note however, this message appears pretty random, let's say after every few searches. I can tell when this message will pop up before the page is loaded because it takes a bit longer - looks like there is some sort of time-out and no search results are getting returned by Google.

Any idea what the cause might be?

mfb’s picture

if someone could provide me with (temporary) access to business custom search, I could work on support for this feature in the drupal 7 branch. I'm guessing it wouldn't take me long at all given that I've already got the Bing search API working over here.

enrique.delgado’s picture

If you still need access to a business account, I can help you with that. I'd love to see this being an option for D7.

joshmmo’s picture

I am having this same issue:

warning: Invalid argument supplied for foreach() in /mnt/stor3-wc2-dfw1/500657/help.xxxxxx.com/web/content/modules/google_cse/google_cse.theme.inc on line 124.

It has been working for 8 months just fine and now today I notice the error. It happens on every search I try. I am using drupal 6, with google cse paid version:
"On this site (without JavaScript or frames, requires current Google Business account)".

Anyone have any ideas on where to look to fix this issue?
Thanks

UPDATE: Looks like it was an issue with our host, rackspace. They had an outage yesterday that caused outbound traffic to timeout.

rooby’s picture

The Google CSE Advanced module allows you to use the paid version.

There should be a D7 version soon (there is already one in the issue queue).

jhodgdon’s picture

That's annoying that there are two separate modules. If possible, they should be combined. :(

rooby’s picture

I agree, it would be much better if there was only one module. Much less confusing and easier to switch between free & paid.

Plus the usual defragmentation benefits.

I was planning to spend a bit of time getting the CSE advanced port up to scratch for drupal 7 but I might make some time to try this out and get a drupal 7 version of the patch going.

This route will take me more time though so I will have to see how I go for time.

joshmmo’s picture

Issue summary: View changes
FileSize
9.3 KB

This patch gave issues with promotions enabled. I did a fix. Just need to make changes in google_cse.module

joshmmo’s picture

If that patch fails for you, you can see my new google_cse.module file here:

http://snipt.org/IIgj4

You will notice I switched to SimpleXML parser. This solved a few issues with promotions due to title not being wrapped in CDATA.

malcomio’s picture

Status: Needs review » Closed (won't fix)

See the google_cse_adv module, which has been integrated with this in the D7 version.

rooby’s picture

Also check out the https://www.drupal.org/project/gss module.