The Joomla! Community Portal ™

  • Print
  • Email

August 2008

2008-08 Joomla! Community Magazine

Joomla! Community Magazine - Learning

Site Integrator: Search in Joomla! 1.5

Statistics, additional options, and customizing the layout

Written by Andrew Eddie

One of the many things you may notice about Version 1.5 is that Search now has it's own Administrator Component. You can access this by selecting Components -> Search from the menu. This replaces the previous location under Site -> Statistics -> Search Text in Version 1.0.

For a new install there's not much to see and if you had tried searching for something, nothing would be recorded. Let's fix that first.

Click the Parameters icon in the Toolbar.

A dialog window will overlay the screen (you'll see this effect a lot in the Administrator) and will present you will a couple of Global Configuration parameters to set. At this stage we are only interested in the first one, so set Gather Search Statistics to Yes and then click Cancel or round X button at the top-right corner of the dialog box.

The Search Logging indicator will still show Disabled until you refresh the screen after which it should change to a nice, green Enable value.

The New Search Areas

Jump over to the frontend of your site and type something in the search box followed by clicking the Go button, or pressing Enter/Return (will vary depending on what template you have installed and how the search module is configured).

With luck you've selected a word that has some results (if you've installed the Sample Data "joomla" is a good guess). Most of this screen should be familiar to you except for one new line - the Search Areas. This set of checkboxes gives you the option of searching only within certain components. If you check the box next to Web Links, only results from the Web Links data will be returned in subsequent searches. If you leave all the boxes uncheck, Joomla! will assume that you just want to search everywhere.

Choose a few more words and try one or two a couple of times

Search Statistics

Now jump back to the Search Component in the Administrator.

What you should see are all the words that you searched for and the number of times they have been requested. There is a link above the table which probably reads Show Search Results. If you click this links it toggles an extra column in the table. This column will give you a count of the number of search hits that you get for a given word or term. This is useful to look at from time to time because if you find that a word is being frequently searched, but the results are near zero then it may tell you something about what your visitors are looking for on your site.

Notes for Web Masters

It's a good idea to have a menu item for Search in one of your menus. It doesn't matter whether you tuck it away in a footer menu or let it be in a prominent position. If you don't include one, then the Search Component will only ever use the default parameters that are set internally. By including a menu item, and allowing Joomla! to find that (using the new Router) you will be able to override those settings if that is what you desire.

To add the Search Component to your menu, select Menus -> Main Menu (or any other menu you'd like).

Click New in the Toolbar.

On the next page, find and click Search under the Internal Links item in the tree that is displayed. You'll see Search / Search / Search in a tree. The first one is the Component name; the second one is the View name and the third one, which is a link, is the Layout name. Click on that last Search which is the link.

The next page is the edit form for the menu item. Enter a Title and Save.

If you now refresh your site you should see your new menu item displayed on your site.

Notes for Template Designers

The Search Component only has one View and only one Layout so it's very simple to customise.

To create a Layout Override for the Search Component, first look at your template folder. If you don't already have one, create a directory called html in your template directory. To create an override for a Component, the directory structure follow the format component_name / view_name / layout_file.php where the component _name and view_name must exactly match the directory names of the Component and the View, and the layout_file must also match the name of the layout file.

With that said, copy the file:

/components/com_search/views/search/tmpl/default.php

to

/templates/my_template/html/com_search/search/default.php 

Now make a few changes in that file and refresh your site.

In a similar fashion, you can also override the Search Module layout file. Copy the file:

/modules/mod_search/tmpl/default.php

to

/templates/my_template/html/mod_search/default.php

Modules don't support views so our directory structure is not as deep as for a Component.

For more examples of Layout Overrides, have a look at the html directory in the Beez template that ships with Joomla! 1.5.


11 Comments

Feed
  1. Nice. Thank you. This helped.
  2. This is a very cool feature that I will have to blog about. Thanks for the changes and keep up the great work. I love being able to check the search stats now.
  3. My eyes must be bad, but where is the search box or link in the main Joomla site?
  4. I hacked the core search module to provide a link to advanced search immediately under the form. Perhaps this could become a module parameter in future versions? Open /modules/mod_search/tmpl/default.php After the last line, which is , add Advanced search Regards Brendon
  5. I would be nice to have an admin feature to enable/disable which checkboxes are presented on the search results page. Especially for those who don't use weblinks, or feeds or whatnot.
  6. I am using Joomla! 1.5.6 and it doesn't enable the "Search Logging" until I press "OK" rather than "Cancel". Are you sure you are right?
  7. In 1.5.6, when I click on "Show Search Results", I get: Fatal error: Class 'searchHelper' not found in /home/content/p/j/s/pjshane16/html/joomla/plugins/search/content.php on line 253 This occurs in my sandbox with 1.5.6 and also in my 1.5.5 version on preproduction server.
  8. hi kamal
  9. Articles search in Joomla only seems to search article text. We updated the source code to make Joomla search and highlight in results authors as well (actually, author aliases). Would it be possible to make this a feature in Joomla proper?
  10. Nice tutorial ! helped me out just fine! only one question how do i disable the "Search in" function?
  11. I just downloaded joomla 1.5 and this looks really nice. thanks!