HTML Logo by World Wide Web Consortium ( Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.

Search your website from your browser's search bar

Login / Search

 [ Join | More ]
#43342 (In Topic #9622)

Using OpenSearch

Firefox introduced the concept of web browser search plugins a few years ago, and IE7 came came with it too. It's become a feature I have come to rely on myself: in my search engine drop-down I have a number of websites including YouTube, Wikipedia, and the PHP manual.

We sneaked support for integrating with this into ocPortal 4 quite late without really announcing it. It's called OpenSearch, and you can use it to to add your own website to your search engine list with ease (or allow your users to).

It works like this:
  • Your website advertises it has a search engine (via OpenSearch).
  • The web browser provides the option to add your website's search engine, via a special add link beneath the list of search engines that are already installed.
  • The user can choose that link, and instantly your site is then added to their search dropdown.
  • The user can then run searches on your site directly from their browser (it has auto-complete too, based on past successful searches!).
  • The searches get fed through to your website's search engine (the search page).

A default ocPortal installation does not advertise via OpenSearch. But if you look in the HEADER template you'll see some code is in there:


      <link rel="search" type="application/opensearchdescription+xml" title="{$SITE_NAME*} {$ZONE*}" href="{$FIND_SCRIPT*,opensearch}?filter=:id=comcode_pages:search_under=docs" />
This code basically says "Advertise OpenSearch, but only in the 'docs' zone". The code also contains a special search filter that indicates that the search engine should be constrained to Comcode pages that exist underneath the 'docs' zone. A default ocPortal installation does not have a 'docs' zone, so the code never does anything (we just put this in there as a benign example, to demonstrate how it works).

If we add some more code underneath this (by editing the template), you'll see how we can set up additional customised search engines, advertised under different parts of the website:


      <link rel="search" type="application/opensearchdescription+xml" title="{$SITE_NAME*} (news)" href="{$FIND_SCRIPT*,opensearch}?filter=:id=news&amp;name= (news)" />
This search engine is only advertised from within the news module, is constrained to searching news, and puts " (news)" onto the end of the search engine title to distinguish it.
Alternatively, you could just skip the Tempcode directive there (i.e. only keep the <link .../> bit) which would make your search engine be advertised everywhere on your website: it's entirely up to you.

To see what other constraints you can use instead of 'news' or 'comcode_pages', look at the filenames of the various PHP files located under sources/hooks/modules/search.
You can actually go further and add in more complex constraints, like searching underneath specific categories, or limiting to specific authors, but that becomes a bit more advanced than I want to get into here.

Tip: It's a good idea to have a favicon set up for your site, otherwise it doesn't look good in the search dropdown list.

Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: