We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

New plugin: Google Search Results

Development and Programming

Derek Hogue's avatar
Derek Hogue
317 posts
16 years ago
Derek Hogue's avatar Derek Hogue

Despite some nice improvements on the area of search within EE as of late (hello Super Search), for most sites it’s still hard to beat search results based on a crawl of your actual site (as opposed to the contents of its database). Google’s Custom Search Engine is good, but it’s kind of fugly, and requires JavaScript to work.

So, I wrote a new plugin called (drumroll please) Google Search Results that leverages Google’s AJAX Web Search API to load search results for your domain (or your Custom Search Engine) natively in EE.

Simply create a search form with a text input named ‘q’ and submit it via POST or GET to a template on your site containing the Google Search Results tag pair.

NOTE: Currently the Google AJAX Search API limits queries to 8 results per page, with a total of 64 results for any given query.

The README in the download explains all the tag parameters and variables in detail, but here’s a quick example of what your search results template might look like:

{exp:google_search_results site="yoursite.com"}
    
    {if search_results}
        You searched for <strong>{keywords}</strong> and got 
        {total_search_results} {if total_search_results == "1"}result{if:else}results{/if}.
    {/if}
        
    {results}
    
        {if count == "1"}<ul>{/if}
        
        <li>
            <h3><a href="http://{url}">{title}</a></h3>
            {excerpt}
            <small>{url} <a href="http://{cached_url}">(cached)</a></small>
        </li>
        
        {if count == total_page_results}</ul>{/if}
        
    {/results}
        
    {if no_search_results}
        Sorry, no results for <strong>{keywords}</strong>.
    {/if}
    
    {if paginate}
        Page {page_number} of {total_pages} : {pagination}
    {/if}
    
    {if last_results_page && results_overflow}
        <a href="http://{google_results_url}">View all {total_google_search_results} results on Google</a>
    {/if}
    
{/exp:google_search_results}

This plugin has been tested with EE 1.6.8. An EE 2.0 version will come, I’m sure. If you’re running PHP < 5.2, you’ll need to upload the included JSON.php file to your /system/lib/ directory. Also, cURL support is required!

Download Google Search Results from GitHub (or view the repo)

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas
Currently the Google AJAX Search API limits queries to 8 results per page, with a total of 64 results for any given query.

That’s bad.

Yahoo BOSS Search plugin does not have such limitations.

       
Derek Hogue's avatar
Derek Hogue
317 posts
16 years ago
Derek Hogue's avatar Derek Hogue

Haha, well, it’s not suitable for all sites, but for many smaller sites it’s a good fit. And, the future of BOSS search has some uncertainties (like possible fees).

Just to clarify, the 64 result limit is not a limitation of the plugin, but of the official Google API.

       
trif3cta's avatar
trif3cta
148 posts
16 years ago
trif3cta's avatar trif3cta

Thanks D-Rock, I’ve been scratching my head with search issues on a couple sites. (Mainly with search results on multi-template Channels as well as some relevance issues).

I’m going to try this out on a project next week and will post any feedback.

       
Tyssen's avatar
Tyssen
756 posts
16 years ago
Tyssen's avatar Tyssen

Nice work Derek and I’m already using it on a site and it’s working out well except that it appears that it’s returning results from some pages and not others, i.e. there’s two pages where a specific terms exists but only one is being returned. I’ve added the filter=”0” parameter but it hasn’t changed anything.

       
Derek Hogue's avatar
Derek Hogue
317 posts
16 years ago
Derek Hogue's avatar Derek Hogue

Tyssen – are these pages coming up in a normal Google search? Basically, the API does all the work, so I can’t offer much assistance in what results appear.

       
Tyssen's avatar
Tyssen
756 posts
16 years ago
Tyssen's avatar Tyssen

Actually I didn’t check the results coming directly from Google properly and you’re right, the missing result isn’t coming up in Google either.

       
Ross1988's avatar
Ross1988
59 posts
about 16 years ago
Ross1988's avatar Ross1988

getting a

The following errors were encountered * No search terms were specified. Click here to go back to Return to Previous Page error message for some reason

this is on 2 completely blank templates

any ideas?

thanks..works great for the first 8 results!

       
Tyssen's avatar
Tyssen
756 posts
about 16 years ago
Tyssen's avatar Tyssen

Is your results page being passed a querystring? The URL for your results page should include something like ?q=searchterm

       
Ross1988's avatar
Ross1988
59 posts
about 16 years ago
Ross1988's avatar Ross1988

yup URL looks like:

http://www.site.com/template-group/blank-page/?q=hotels&p=2

and so on

then just errors. its peculiar.

I have removed index.php from my URLs if this might effect it?

       
Ross1988's avatar
Ross1988
59 posts
about 16 years ago
Ross1988's avatar Ross1988

confirmed, index.php is required for this to work properly..any idea?

probably should have fully read the readme first,

all fixed, great plugin thanks.

       
Derek Hogue's avatar
Derek Hogue
317 posts
about 16 years ago
Derek Hogue's avatar Derek Hogue

Glad you beat me to the answer. Using a POST action on the search form, and adding remove_query_indicator=”y” on the tag should do the trick in your case.

       
Jon M's avatar
Jon M
8 posts
15 years ago
Jon M's avatar Jon M

The plugin is working really well for the most part with index.php removed when I have the form post instead of get and add the remove_query_indicator=”y” to the tag but when I click on pagination links after each link the url gets longer and longer.

For example, on the first click I get

http://site.com/results/&q=query&p=2

but if I click another pagination link I get

http://site.com/results/&q=query&p=2/&q=query&p=4

where the numbers are the pagination links I clicked on. Is anyone else having this problem or is there a solution for this?

       
bitsculptor's avatar
bitsculptor
30 posts
15 years ago
bitsculptor's avatar bitsculptor

Easy to set up and get working, but I’m getting errors from the plugin file when the search returns no results. Here’s what I get:

Notice: Undefined index: HTTP_REFERER in /www/eh13088/public_html/gcsys/plugins/pi.google_search_results.php on line 94

Notice: Undefined property: stdClass::$estimatedResultCount in /www/eh13088/public_html/gcsys/plugins/pi.google_search_results.php on line 124

Notice: Undefined property: stdClass::$pages in /www/eh13088/public_html/gcsys/plugins/pi.google_search_results.php on line 133

Notice: Undefined variable: pagination in /www/eh13088/public_html/gcsys/plugins/pi.google_search_results.php on line 213

Here’s my code:



Any ideas?

       
Derek Hogue's avatar
Derek Hogue
317 posts
15 years ago
Derek Hogue's avatar Derek Hogue
The plugin is working really well for the most part with index.php removed when I have the form post instead of get and add the remove_query_indicator=“y” to the tag but when I click on pagination links after each link the url gets longer and longer.

Can you try removing the ‘remove_query_indicator’ argument and see if the same thing happens with your pagination URLs?

Easy to set up and get working, but I’m getting errors from the plugin file when the search returns no results.

Can you try the version posted here and see if that fixes these errors?

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.