Using Version 2 of the Custom Search Element Control API, which appears to now be the default for Google CSE, makes for easy tuning of the settings without having to change the module code (as you did for #1099294: Using Custom Search Element instead of the iframe).

This seems incompatible with this module as it current stands. This patch should integrate the V2 code, as well as add an 'Advanced' field for adding a custom stylesheet to override the CSE settings.

One may have to tailor the patch depending on how you want to show your results, since the CSE settings will change the code depending on which of these you use:

<gcse:search>
<gcse:searchbox>
<gcse:searchresults>
<gcse:searchbox-only>
<gcse:searchresults-only>

Given the code base similarities between 7.x-2.x-dev and 7.x-1.x-dev, I imagine the patch would work for both, though I have not tested on 7.x-1.x-dev. Likewise, I am not sure how well it plays with "Google CSE Advanced" setting for 7.x-2.x-dev.

Comments

mxwright’s picture

Status: Needs work » Needs review
StatusFileSize
new2.7 KB

And the patch

mxwright’s picture

Category: Task » Feature request
mxwright’s picture

Category: Feature request » Bug report
mxwright’s picture

Category: Bug report » Feature request
StatusFileSize
new2.7 KB

Submitting patch again for testing.

mxwright’s picture

Category: Feature request » Bug report
Priority: Normal » Major
vinmassaro’s picture

@mxwright: Thanks for your work on this. I'm having trouble testing your patch. Is it working for you or is it a work in progress?

I configured GSE as the default search and enter my GSE ID, but when I make a search the page refreshes with no results, and the browser console logs this error:

GET http://www.google.com/uds/?file=ads&v=3&packages=search&async=2 net::ERR_BLOCKED_BY_CLIENT

Any ideas?

mxwright’s picture

@vinmassaro: This may have to do with an ad-blocking plugin on your browser? See this related page on "ERR_BLOCKED_BY_CLIENT"

vinmassaro’s picture

Ok, I was able to get your patch working. I had to configure the custom search at Google to use 'results only' and then also change the default query parameter in the Google settings to query instead of the default q. Does this sound right? Would it make sense to change the query parameter to Google's default of q instead so additional configuration isn't necessary or am I missing something? Thanks!

mxwright’s picture

There's no way to choose, within the module, how to display your results. I used "searchresults-only" but as I wrote in the summary, you may have to tweak the results template to suit your needs. One of the following:

<gcse:search>
<gcse:searchbox>
<gcse:searchresults>
<gcse:searchbox-only>
<gcse:searchresults-only>

It would be great if you could select it both in the module and in CSE settings, and have it automatically reflected in the code, but it doesn't right now - I'll try to look at it further.

As to using query instead of q, I think that's built into the module - my patch doesn't address that. It's most likely done to avoid confusion between Drupal's use of q and Google's.

vinmassaro’s picture

Issue summary: View changes
StatusFileSize
new116.31 KB

Ok, I guess the confusing part for me was needing to change the default query parameter on the Google CSE settings from q to query in order to make the module even work. I didn't find this documented anywhere. Is this required or am I missing something? Here is a screenshot:
google_cse

chegor’s picture

I had the same problem. On my site module works with f.e. old google cse created 4 years ago but not with new cse.
Patch from #4 helped me.

osopolar’s picture

Issue summary: View changes

Showing the screen shot only once int the issue summary.

osopolar’s picture

Seems that the project is currently developed on GitHub. I ported the patch for the current GitHub 7.x-2.x-dev version. I'll also crate a pull request there.

So far it's working for me (I didn't change the code from #4), although not looking beautiful. I'll try to split the block into two blocks, one for the search form and one for the results (to integrate it better into panels).

osopolar’s picture

StatusFileSize
new5.15 KB

There was some more stuff added by alex-moreno on GitHub which caused the notice:

Notice: Undefined index: page in google_cse_search_page() (line 62 of /sites/all/modules/contrib/google_cse/google_cse.module).

I guess for google cse advanced which caused an error. I fixed that but didn't test, as I am not using the google cse advanced.

ronigal’s picture

osopolar You missed a closure on .module file on google_cse_search_page function (line 65)

osopolar’s picture

StatusFileSize
new5.41 KB
new413 bytes

@ronigal: You mean $output['suffix']['#markup'] = '</ol>' . theme('pager');?

New patch attached.

alexmoreno’s picture

Hi osopolar,

I am more focused in the paid version, so it's great that you can have one eye on the free one. Let me test it and get it merged.

Thank you.

osopolar’s picture

Isn't the paid version covered by the module Google Site Search, or is that for an other google product. Anyway, currently we are working with the free version.

mxwright’s picture

Version: 7.x-2.x-dev » 7.x-2.0-alpha1
StatusFileSize
new4.93 KB

Thanks osopolar for keeping this issue up to date.

I was reviewing today to try and incorporate this patch into the latest dev version, but I see the dev version here on Drupal is way out of date. The current version 2.1 actually seems to be behind the so called 2.0-alpha1 version (all this is outlined here: #2529404: Rename version 7.x-2.0-alpha1 to 7.x-2.2).

I've updated the patch in #16 to reflect the changes in version 7.x-2.0-alpha1 (which may also be the true latest version, 7.x-2.2).

I have a second patch coming with a few more changes.

mxwright’s picture

OK, so here is a patch that also adds some layout options, as discussed in the above comments 8, 9, 13.

I added an 'advanced' option to select a layout, just like in the Custom Search settings in Google. That selection gets sent to the results template. It should probably be split up somewhere there to account for separate search and results boxes, etc. As this is just a first pass, it should be enough to allow for some tweaking.

Potentially this should be a separate issue?

osopolar’s picture

Actually I am confused which version is the actual dev version. As I wrote in #13 i think the most actual version is the one on GitHub: https://github.com/Capgemini/google_cse (see also google_cse module page). At least that is the version I am currently using.

@mxwright: One more thing: you might use spaces to indent code, not tabs, and avoid trailing spaces, see for example (and other places):

+  );
+  ¶
+  $form['google_cse']['advanced']['google_cse_custom_results_display'] = array(
+    '#title' => t('Layout of Search Engine'),
+    '#type' => 'radios',
+    '#default_value' => variable_get('google_cse_custom_results_display', '<gcse:search></gcse:search>'),
+    '#options' => array(
+      '<gcse:search></gcse:search>' => t('Overlay'),
+      '<gcse:searchbox-only></gcse:searchbox-only><gcse:searchresults-only></gcse:searchresults-only>' => t('Two page'),
+	  '<gcse:search></gcse:search> ' => t('Full width'),
+++ b/google_cse.module
@@ -65,37 +69,35 @@ function google_cse_search_page($results) {
+  ¶
+  if (!$results) {
+    // No results found.
+    $output['search_results'] = array('#markup' => theme('google_cse_search_noresults'));
+   ¶
+    return $output;
+  }
mxwright’s picture

StatusFileSize
new6.21 KB

Sorry, a bad paste-job by me. Hopefully this patch is a little better. As for the trailing spaces, do you mean this:

'<gcse:search></gcse:search> '

If so, the point was to differentiate similar code, since they are basically identical in the CSE settings. I put in some non-breaking spaces instead...

mxwright’s picture

StatusFileSize
new6.06 KB

Well shoot. Let's try one more time.

alexmoreno’s picture

Yes, osopolar, last one is the one in github. And your previous question, this module is the result of integrating another module which covered the paid version, into this one to avoid duplication. Why there is a third module I can't tell you atm, we are just using that one since 3 or 4 years ago and we are trying to contribute it back as often as we can.

We are reviewing / testing this in the next days and get it merged, thank you all for your contributions.

osopolar’s picture

@mxwright: I didn't mean the '<gcse:search></gcse:search> '. If you use the Dreditor Browser Script you will easily see in the patch review what I mean (the little red rectangles inside green code). Anyway, these are just minor coding standard issues.

@urwen: Yes, thanks for your contribution. I don't use Google Site Search because its for the payed version only and my customer wants just the free version of CSE. Anyway, maybe it's worth joining forces, or maybe gss is something different, I don't know. It seems that its there for a while, since late 2011.

flaviovs’s picture

I tried the patch in #23 and got lots of failed hunks. Tried against the current "7.x-2.x" branch in the GitHub repo.

Also tried against "7.x-2.x" from Drupal.org to no avail.

No success also against the non-standard "develop" branch in GitHub. I could not find the "7.x-2.x-dev" mentioned elsewhere in this issue.

(BTW, I noticed that the GitHub repo have a completely disconnected commit history from the one in D.o. Wtf?! This will make updating the D.o repo more difficult and error-prone in the future.)

Folks, we have to move forward with this issue. Many of you may not have noticed (or be affected by) it yet, but Google entirely removed IFRAME support from new CSEs, which means that the current release still works for old CSEs, but for new ones it does not work anymore.

I am more than willing to help this issue move forward, so as a start I will be glad if someone could clarify which repo is more active, and which branch 7.x development is actually taking place.

osopolar’s picture

I haven't tested the patches from mxwright. I am still using the one from #16 and waiting for news from urwen's review (see #24).

flaviovs’s picture

@osopolar, mxwright says that the latest dev is in GitHub, but I failed to apply the patch to any 7.x branch there.

In fact, first of all it would be important that the developers clean up this branch hell in favour of the Release naming conventions, as this will help everyone. It should be immediate to tell where the current development is being carried on, just by looking at branches and the commit log, which cannot be done now.

This is a somewhat important module, IMHO, and this issue deserve more attention. As I said, the current release is broken for most new users.

mcunningham’s picture

I applied the patch successfully against 7.x-2.x-dev found here:

https://www.drupal.org/node/131984/release

I do agree this module should either live on d.o. or github...not great having outdated/broken version here.

alexmoreno’s picture

I have to do some cleaning next days that I think I'll have some time, I'll try to solve this mess asap. Any volunteers welcome though.

Thank you guys.

mxwright’s picture

@flaviovs the patch in #23 is against something called "7.x-2.0-alpha1" which can be found here: https://www.drupal.org/node/2468805

7.x-2.0-alpha1 would appear to be the latest available version (and functionally equivalent to 7.x-2.2 which can be found here: https://www.drupal.org/project/google_cse/git-instructions)

I have not used any of the versions on GitHub and I wanted to make the patch work for the latest dev version, but unfortunately that's not available on drupal.org.

mxwright’s picture

StatusFileSize
new6.2 KB

Here's a cleaner version of the patch in #23. Thanks @osopolar for the Dreditor cleanup tip.

flaviovs’s picture

@mcunningham, I have no problem in using GitHub and D.o infrastructure and same time (I mean staying in D.o only is preferable, but going GH is also ok). By using git, is easy to coordinate commits between the two repos, and handle development in both fronts. The problem arises when we have two disconnected repos as we have now. You'll have to resort to manual patching and cherry-picked commits to bring everything in sync. This is not an easy task.

@urwen, I volunteer to help in any task that is going to help us move forward. Just let me know what you need!

@mxwright, thanks for the update.

osopolar’s picture

Status: Needs review » Needs work

@mxwright Thanks for pushing this forward. I was looking again at your patch.

1. The new variables need to be added to google_cse_uninstall() (would be the same for my patch in #13).
2. I wouldn't use markup as keys for the settings in Layout of Search Engine, as logic and presentation should be separated.

flaviovs’s picture

Just for information of everyone, the patch in #33 applies cleanly to the commit tagged "7.x-2.0-alpha1" in D.o repository.

2. I wouldn't use markup as keys for the settings in Layout of Search Engine, as logic and presentation should be separated.

I second that. This is the first thing that grabbed my attention when reviewing the patch.

flaviovs’s picture

BTW, see #2540256: Make git repositories standard compliant and in sync for an in-depth analysis of the D.o/GH repo differences -- and what should be done to bring them in sync. I hope the maintainers sort out this branch hell ASAP, as the current situation makes contribution difficult.

alexmoreno’s picture

ok, first of all, thanks for the feedback. I am doing some house keeping. I have to say that when you clone the code it clearly says that current branch is 2.2, but agree on doing some cleaning.

Code is now merged in branch 2.3, which I'll create as default and will merge any other improvements that we have left, if that's ok with everyone. I don't want to add more confusion, but is something is wrong we can go back easily to 2.2 and start again.

Github... Let's forget about that. It probably made sense some time ago, when the development of this module was quite active from our side, but not anymore as we don't commit as many improvements as we use to do. I don't mind to create patches and respect D.o workflow.

Let's progress from here. Thanks again.

  • mxwright authored 54348e9 on 7.x-2.x
    Issue #2422979 by mxwright, osopolar: Integrate V2 code
    
alexmoreno’s picture

Sorry, I meant 7.x-2.x. That is the default branch and the one to commit against, just merged it.

alexmoreno’s picture

Status: Needs work » Fixed
alexmoreno’s picture

Status: Fixed » Needs work
pianomansam’s picture

The new implementation of GSE V2 API seems to have broken the search box block. This is because there is no way to inform the search engine what the query param is. If you look at the API spec (https://developers.google.com/custom-search/docs/element), you'll see it is now set with a queryParameterName value on the component. So for <gcse:search> it should be <gcse:search queryParameterName="query">.

The update also seems to remove passing the query param as a GET param, and I cannot find any way that the search page is supposed to receive it instead. In 7.x-2.1, there was a 301 redirect in google_cse_search_execute() that would take the POST params and convert them to GET params.

alexmoreno’s picture

Hi @pianomansam ,

could you confirm if the previous tag (7.x-2.1) works ok? That way I'll roll back to that one as the default for the 7.x and leave the development branch pending to fix this.

pianomansam’s picture

@urwen, I wish I could successfully test 7.x-2.1, but it looks like the V1 API is starting to be phased out. I'm getting this error from Chrome:

Refused to display 'http://www.google.com/cse?cx=XXXXXXXXXXXXXX&cof=FORID%…0%26cof%3DFORID%253A11%26sitesearch%3D&siteurl=XXXXXXX' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

flaviovs’s picture

@urwen, thank for your promptly reply! As of using GitHub, as I said, I think that it is a great tool, but you have to reserve energy to bridge the differences in workflow. The most important thing to remember is: if you decide to go GH again, it will be OK, just remember to clone here and push there so that both repos have the same history!

@pianomansam,

The new implementation of GSE V2 API seems to have broken the search box block. This is because there is no way to inform the search engine what the query param is. If you look at the API spec (https://developers.google.com/custom-search/docs/element), you'll see it is now set with a queryParameterName value on the component. So for it should be .

The update also seems to remove passing the query param as a GET param, and I cannot find any way that the search page is supposed to receive it instead. In 7.x-2.1, there was a 301 redirect in google_cse_search_execute() that would take the POST params and convert them to GET params.

Patch is now committed do 2.3, so please open new issues to track this, because these problems are unrelated to (even though may be introduced by) this patch. Thanks.

@urwen, I wish I could successfully test 7.x-2.1, but it looks like the V1 API is starting to be phased out. I'm getting this error from Chrome:

IFRAME CSEs are not supported anymore by Google. Old CSEs still work, but in newly created CSEs you are not given an option to use IFRAMEs. I have mentioned a few comments above that the module is not working for new CSEs anymore -- and that's what makes this issue so urgent.

alexmoreno’s picture

@flaviovs let's keep it simple, one year ago made sense for us. Now we are not contributing that often, so we can focus on drupal workflow for this module

I'll be closing the issue as suggested, given that it's a different problem. There are a couple of coding issues in the comments so if anyone wants to create a new patch on top of the 2.x version please. I though it was more urgent to have things rolling.

Thank you

alexmoreno’s picture

Status: Needs work » Closed (fixed)
flaviovs’s picture

Ok, thanks for the feedback. I am working on the issues right now, and will keep you informed in the issue queue.

ywarnier’s picture

StatusFileSize
new36.15 KB

Just a note regarding changing the Query Parameter Name: it seems to have moved inside Google CSE's interface from the "Get the code" page to the "Search features > Websearch Settings > Query Parameter Name" (last field).
The interface is a bit extensive, so it took me a while to find it. I hope this helps others.

Google CSE interface for query parameter name change