Follow Us:
Tricked Out Mods: Forums

Best Hosting
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Adding custom AJAX search to the Search Module
 
 
Post new topic   Reply to topic   print    Tricked Out News Forum Index -> RavenNuke
View previous topic :: View next topic  
Author Message
spasticdonkey
Super Dev Donkey
Super Dev Donkey


Joined: May 08, 2009
Posts: 76


PostPosted: Thu Oct 29, 2009 4:22 pm 
Post subject: Adding custom AJAX search to the Search Module
Reply with quote

You'll need a google api key, if I remember right they are universal so if you have a key for maps you can use that, or once you have a key you can use it for any of their stuff..
Arrow http://code.google.com/apis/base/signup.html

and you'll need a custom search engine
Arrow http://www.google.com/cse/

once you have that not too hard to get going. open modules/Search/index.php
find:
Code:
$pagetitle = '- '._SEARCH;

after add (replace YOUR_API_KEY and YOUR_CUSTOM_SEARCH_ENGINE with your info)

Code:
addJSToHead('http://www.google.com/jsapi?key=YOUR_API_KEY', 'file');

   $inlineJS = '<script type="text/javascript">'."\n";
   $inlineJS .= 'google.load(\'search\', \'1\');'."\n";
   $inlineJS .= 'function OnLoad() {'."\n";
   $inlineJS .= 'var customSearchControl = new google.search.CustomSearchControl(\'YOUR_CUSTOM_SEARCH_ENGINE\');'."\n";
   $inlineJS .= 'customSearchControl.draw(\'customsearchresults\');'."\n";
   $inlineJS .= 'customSearchControl.execute(\''.$query.'\');'."\n";
   $inlineJS .= '}'."\n";
   $inlineJS .= "google.setOnLoadCallback(OnLoad);\n";
   $inlineJS .= '</script>'."\n\n";
   addJSToHead($inlineJS, 'inline');

find

Code:
                    .'<li> <a href="http://www.google.com/search?q='.$query.'" target="new">Google</a></li>'

                    .'<li> <a href="http://groups.google.com/groups?q='.$query.'" target="new">Google Groups</a></li>'
                    .'</ul>';
                CloseTable();

after add
Code:
                OpenTable();

                echo '<div id="customsearchresults">Loading...</div>';
                CloseTable();


DONE! Smile
unless you want to style the results to match your theme... which was actually harder than adding the code... Sad
google gives the ability to stylize the results, but there about 1000 different classes. I figured out how to stylize everything except the ads that appear sometimes, which load in an iframe so that's a whole different beast.. This ajax search is a beta so they may still be tinkering over at google.

here's the style info i came up with, only seemed to work if you associated it with the div id of your results.. change YOUR_STYLE_HERE to suit your theme:

Code:
#customsearchresults .gs-title * {YOUR_STYLE_HERE}

#customsearchresults .gsc-trailing-more-results * {YOUR_STYLE_HERE}
#customsearchresults .gs-visibleUrl-short {YOUR_STYLE_HERE}
#customsearchresults .gsc-branding-text {YOUR_STYLE_HERE}
#customsearchresults .gsc-tabHeader.gsc-tabhActive {YOUR_STYLE_HERE}
#customsearchresults .gsc-resultsHeader {YOUR_STYLE_HERE}
#customsearchresults input.gsc-input {YOUR_STYLE_HERE}


to see it live in action checkout
http://www.axis-and-allies.com/search.html

and try a search for something like tank or armor which will return alot of results... also works from the nukeNAV modal search window! Smile

think thats it ..... I'll check back later if anyone wants to give this a spin.. btw my custom search engine (CSE) searches a network of related sites, so not all links lead to my site, but you can certainly setup however you please... thats all in the CSE setup
  
Back to top
View user's profile Send private message Visit poster's website
Guardian
Blingaholic
Blingaholic


Joined: Nov 03, 2009
Posts: 25


PostPosted: Sun Nov 15, 2009 7:20 am 
Post subject:
Reply with quote

To take advantage of Googles own search templates
Before
Code:
addJSToHead('http://www.google.com/jsapi?key=YOUR_API_KEY', 'file');

ADD
Code:
addCSSToHead('http://www.google.com/cse/style/look/YOUR_TEMPLATE.css','file');

Where YOUR_TEMPLATE is the name of the css file that google provides.

Change the two instances in the previous post of 'yoursutomsearchresults' to 'cse' and your done.[/code]
  
Back to top
View user's profile Send private message
spasticdonkey
Super Dev Donkey
Super Dev Donkey


Joined: May 08, 2009
Posts: 76


PostPosted: Mon Nov 16, 2009 8:31 am 
Post subject:
Reply with quote

very cool, thx Smile
there's a "Look and feel" setting in google cse that wasn't there when I did this demo.. Smile
  
Back to top
View user's profile Send private message Visit poster's website
Guardian
Blingaholic
Blingaholic


Joined: Nov 03, 2009
Posts: 25


PostPosted: Thu Nov 19, 2009 6:29 pm 
Post subject:
Reply with quote

Yup! Smile
I decided after writing my post to download their CSS file and include it locally within the Search module after modifying it a little.
  
Back to top
View user's profile Send private message
spasticdonkey
Super Dev Donkey
Super Dev Donkey


Joined: May 08, 2009
Posts: 76


PostPosted: Thu Nov 19, 2009 7:21 pm 
Post subject:
Reply with quote

very nice styling Smile
  
Back to top
View user's profile Send private message Visit poster's website
bestbuildpc
I might as well work here
I might as well work here


Joined: Nov 16, 2009
Posts: 100


PostPosted: Sun Jul 08, 2012 9:07 am 
Post subject:
Reply with quote

Can we do this in RavenNuke 2.5? I guess it won't be a problem right?

Edit: yes it is possible but Google changed the API key but it is working again.
  
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic   print    Tricked Out News Forum Index -> RavenNuke All times are GMT - 5 Hours
 
 Page 1 of 1
 
 

Jump to:   
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Powered by phpBB © 2001-2008 phpBB Group
Forums ©