Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== DokuWiki and Google CSE with a stand-alone search result page ====== {{:wiki:dokuwiki-128.png?nolink&32 |}} Integrate the Google CSE (Custom Search Engine) in your DokuWiki installation with a stand-alone search result page (adapted from [[https://developers.google.com/custom-search/docs/tutorial/implementingsearchbox|Google CSE - Implementing search box]]). ===== Add a CSE script ===== Copy and paste this code in your ''meta.html'' hook present in your template directory (''<dokuwiki>/tpl/<template>/meta.html''): <code javascript> <script> (function() { var cx = 'YOUR_ENGINE_ID'; var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true; gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//cse.google.com/cse.js?cx=' + cx; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s); })(); </script> </code> ===== Configure the CSE ===== Select and save the **two-page** layout in the Google CSE Control Panel. On one page, implement a stand-alone search box, changing the ''resultsUrl'' attribute to point to the url where you want to display the results (eg. http://example.org/dokuwiki/search). ===== Edit your sidebar page ===== Copy and paste this code in the sidebar (or in one of many hooks or in your preferred location): <code html> <gcse:searchbox-only resultsUrl="YOUR_RESULTS_PAGE_URL"></gcse:searchbox-only> </code> ===== Create a stand-alone search result page ===== To implement a stand-alone search results page, create a new DokuWiki page (eg. search) and paste the results code snippet into your results page: <code html> <gcse:searchresults-only></gcse:searchresults-only> </code> Now you can trigger search results on this page by passing a ''q'' argument in the url: http://example.org/dokuwiki/search?q=myQuery <callout type="tip" icon="true"> If you use the ''<html>'' tag, enable the [[doku>config:htmlok]] option. </callout> {{tag>dokuwiki tips google cse}} tips/google-cse.txt Last modified: 8 years agoby Giuseppe Di Terlizzi Log In