Thix extention is created thanks to this: http://tutorialzine.com/2010/09/google-powered-site-search-ajax-jquery/
With this widget you quickly add a searchfield to your site.
- User searches on either your site or on the entire web.
- Web,image,news,video search types
- Uses Google as search engine
- Hits are shown via ajax, "more" button to load more results
- Fully Customizable css
- Easy to install
Requirements ¶
Tested with Yii 1.10 in firefox, should work on all platforms though.
Usage ¶
- Unpack the files to protected/extentions/search.
Your dir-structure should now be:
- protected/extentions/search
- protected/extentions/search/assets
- protected/extentions/search/assets/img
- protected/extentions/search/assets/css
- protected/extentions/search/assets/js
- protected/extentions/search/views
- EDIT protected/extentions/search/assets/js/google_search.js Change line 3:
siteURL : 'YOUR_SITE_URL', // Change this to your site url
Optional: Style the widget in protected/extentions/search/assets/css/google_search.css You can change everything if you want to.
Place this code in a view:
<?php $this->widget('application.extensions.search.GoogleSearch'); ?>
DONT FORGET You have to clean your app/assets folder after making changes to the js or css files.
Thanks
I will give it a try this is what I have been looking for.
Brilliant
Awesome extension, thanks a lot mate!
something is missed
nice integrating with Yii, but it really would be better if you've mentioned the real source from which you take the code! ;)
and as it is mentioned on the original post's comments, this Google API is deprecated, if anyone knows how to use new API with this platform, let us know !
@hesam.khaki
I am so sorry, I wrote it in the readme.txt included in the download, I thought I wrote the same here.
Updated the text here now:)
I only found that tutorial, like it, made a yii widget wrapper around it,changed it some to spare people some time to do the same themselves:p
If you check my other contributions you would see I'm always giving the original author full credit:p
About the api, this script still works, so why is it a problem?:)
@Drini
thank you for updating this page :) I knew it was just missed and you forgot to mention it, not anything else !
about the API, the problem is that we are not sure about correct and reliable functionality, for example there may be a limit for amount of search requests per day.
actually i've used this search in one of my projects, but this project is not deployed yet, so i cant tell if it works well or not, I'll let everyone know when I find out.
results
You are limited to 8 pages of 8 results (64 in total), however if your website is well optimised, your user's shouldn't need any more than that.
A little addition for your JS file, should you need it:
~~~
[js]
var cursor = r.responseData.cursor;
var resultsNum = +cursor.estimatedResultCount; // Checking if there are more pages with results, // and deciding whether to show the More button: if( +cursor.estimatedResultCount > (settings.page+1)*settings.perPage){ $('<div>',{id:'more', text:'Next'}).appendTo(resultsDiv).click(function(){ googleSearch({append:false,page:settings.page+1}); $(this).fadeOut(); }); resultsCount.html($('<p>',{id:'numResults', text:resultsNum+' Results'})); } if(settings.page>0){ $('<div>',{id:'less',text:'Previous'}).appendTo(resultsDiv).click(function(){ googleSearch({append:false,page:settings.page-1}); $(this).fadeOut(); }); }
stick a div with id="resultsDiv" on your results page, this will show the total result count for your search (remember the shown results are limited to 64), the other two IF statements basically add a very primitive form of pagination (by primitive, I mean 'Next' and 'Previous' buttons.) If you want to load these results on another page, pinch the 'publishAssets() function from the main php file in the extension folder, stick it in your own searchController, render a results page with these assets registered and stick this in the .js file:
[js]
$(document).ready(function() {
googleSearch(); return false; });
This will load the function as soon as the page has loaded, to actually get the results, I suggest wrapping your search field inside a form and storing the terms once posted as: ```php Yii::app()->user->setState('searchTerms', $_POST['search']); ``` Just remember to reference your search field correcty in the .js file:
[js]
settings.term = settings.term || $('#search').val();
~~~
I also suggest putting the un-escaped URL in the results too, this is a small change at the bottom of the .js file:
[js] arr = [ '<div class="webResult">', '<h2><a href="',r.unescapedUrl,'" target="_blank">',r.title,'</a></h2>', '<p>',r.content,'</p>', '<a href="',r.unescapedUrl,'" target="_blank">',**r.unescapedUrl**,'</a>', '</div>' ];
sorry if this is a lengthy comment, just thought you guys could benefit being shown around the code a bit :)
Not enough information
Hi, I think this ext could be awesome. But the author did not give any detail for the extension, I just do like readme.txt and nothing happen! Moreover, the author did not answer in the extention' forum! Why?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.