Where is the code that pulls results from google in your google search extension?

Please post any support questions here. Guest posting is allowed
robert
Posts: 5
Joined: Wed Mar 30, 2016 6:10 pm

Where is the code that pulls results from google in your google search extension?

Post by robert » Wed Mar 30, 2016 6:35 pm

Hi There,
I was hoping to learn by example from your google search extension in order to implement a custom amazon product search autosuggest box. However I looked through every file I could find in the google search extension package and could not find where a google search is actually performed. When I look at googlesearch.html I see the following code within a div for google search results:

Code: Select all

            <gcse:searchresults-only><h2>{L_GOOGLESEARCH_NOSCRIPT}</h2></gcse:searchresults-only>
The L_GOOGLESEARCH_NOSCRIPT tag is the warning message for people who don't have javascript enabled, so I'm guessing the gcse:searchresults-only tag gets populated with the search results shortly after page load. I reviewed the instructions at https://www.phpbb.com/extensions/writing/ and the wiki but I expected to see something in the controller but nothing referenced google.com. Can you point me in the right direction please?
Thanks,
Robert

Administrator
Site Admin
Posts: 253
Joined: Tue Nov 18, 2014 11:30 am

Re: Where is the code that pulls results from google in your google search extension?

Post by Administrator » Thu Mar 31, 2016 11:21 am

Yes, <gcse:searchresults-only><h2>{L_GOOGLESEARCH_NOSCRIPT}</h2></gcse:searchresults-only>

is only pulled if there is something blocking the script from running. (sometimes it will appear is the search takes a while to populate at Googles end)

The search is actually performed by Google using the results it has collated by indexing your forum. The starting point was Googles own search code, which I have taken it apart, hit it a little, and made into an extension format.

You need to look at

Code: Select all

'U_GOOGLE_SEARCH'      			=> $this->helper->route('hifikabin_googlesearch_controller'),


in event/listener.php and

Code: Select all

   public function base()
   {

      $s_action = $this->helper->route('hifikabin_googlesearch_controller');

      return $this->helper->render('googlesearch.html');
   }
}
in controller/main.php

That puts the results in the page using the code that google creates after you submit the search box using the js in overall_footer_after.html

Hope that helps you on your quest.

robert
Posts: 5
Joined: Wed Mar 30, 2016 6:10 pm

Re: Where is the code that pulls results from google in your google search extension?

Post by robert » Thu Mar 31, 2016 4:26 pm

Bingo! That is what I was looking for, thank you.
I hadn't checked the overall_footer_after.html file because I thought that was just html like the other html files in that directory and specific to a template/theme because of it's location.
:)

robert
Posts: 5
Joined: Wed Mar 30, 2016 6:10 pm

Re: Where is the code that pulls results from google in your google search extension?

Post by robert » Thu Mar 31, 2016 5:02 pm

I just noticed that this javascript code in overall_footer_after.html is only in the prosilver/template/event folder, not the we_universal/template/event folder. If I want to implement this in a different theme should I just use the prosilver version with a new name to start with?
Thanks again,
Robert

Administrator
Site Admin
Posts: 253
Joined: Tue Nov 18, 2014 11:30 am

Re: Where is the code that pulls results from google in your google search extension?

Post by Administrator » Thu Mar 31, 2016 5:27 pm

On a style that inherits from prosilver, you only need to create new style files if there are differences needed between prosilver and the other style (we_universal has several style differences which resulted in the search boxes not aligning properly)

In this case the JS file is universal to all styles, so we_universal does not need to include it.

So, create the ext in prosilver first as thats the base everything else starts from and see if it works in your style. It might look fine (in which case you are done) if not, then create a new style folder in the ext that only contains the files that need to be different to those in prosilver.

If a file is included in the new style, then the one with the same name in prosilver is ignored.

For reference use overall_header_head_append.html to link your css files and overall_footer_after.html to add other scripting (no doubt there are other ways, but thats how I started doing it, and have continued to do so)

robert
Posts: 5
Joined: Wed Mar 30, 2016 6:10 pm

Re: Where is the code that pulls results from google in your google search extension?

Post by robert » Thu Mar 31, 2016 5:31 pm

Thank you, but the style I'm using (Eles) does not inherit from prosilver. I assume I should start by changing the prosilver folder to eles and then adjust as needed to make things fit within that style, correct?

Administrator
Site Admin
Posts: 253
Joined: Tue Nov 18, 2014 11:30 am

Re: Where is the code that pulls results from google in your google search extension?

Post by Administrator » Thu Mar 31, 2016 7:17 pm

Thats how I would do it though it might be worth keeping subsilver as well, just in case you need to revert to it for debugging

robert
Posts: 5
Joined: Wed Mar 30, 2016 6:10 pm

Re: Where is the code that pulls results from google in your google search extension?

Post by robert » Thu Mar 31, 2016 7:24 pm

Sounds good, thanks again!

Administrator
Site Admin
Posts: 253
Joined: Tue Nov 18, 2014 11:30 am

Re: Where is the code that pulls results from google in your google search extension?

Post by Administrator » Fri Apr 01, 2016 8:42 am

Administrator wrote:Thats how I would do it though it might be worth keeping subsilver as well, just in case you need to revert to it for debugging
:oops: :oops: :oops: Of course I meant prosilver :oops: :oops:

Call it an early April Fool's :lol: