Contact Details
Thursday, 19 May 2011 14:25

FLEXIcontent search: order by relevance

If you use the FLEXIcontent Joomla extension, and have enabled the FLEXIcontent search, you may want to be able to order your search results by relevance to the keyword search phrase. Unfortunately, this isn't currently possible.

As a workaround, I've written a hack for the FLEXIcontent search file which checks to see if the search phrase is in the title of the item. If it is, it simply swaps the item with the first in the search results. This isn't perfect, but it will mean that if someone types in the exact title of the article they want, that article will be first in the returned results!

The hack requires changing this file: /plugins/search/flexisearch.php

If you don't like digging around in code, you can download a version of the file containing the hack here (based on FLEXIcontent v1.5.4, but it this file is unlikely to change much between versions).

The code changes are as follows:

Add the following at the top of the plgSearchFlexisearch function

$originalText = $text;

Look for the following code at the bottom of that function:

foreach($list as $key => $row) {
  if($row->sectionid==FLEXI_SECTION)
    $list[$key]->href = JRoute::_(FlexicontentHelperRoute::getItemRoute($row->slug, $row->categoryslug));
  else
    $list[$key]->href = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug, $row->sectionid));
}

and replace it with this:

foreach($list as $key => $row) {
  if($row->sectionid==FLEXI_SECTION)
    $list[$key]->href = JRoute::_(FlexicontentHelperRoute::getItemRoute($row->slug, $row->categoryslug));
  else
    $list[$key]->href = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug, $row->sectionid));

  if(stripos ( $row->title , $originalText ) !== false){
    $firstObject = $list[0];
    $list[0] = $list[$key];
    $list[$key] = $firstObject;
  }
}

Leave a comment

Make sure you enter the (*) required information where indicated.
Basic HTML code is allowed.

All our websites include

  • Content Management System
  • Search Engine Optimized site
  • FREE .co.uk domain name
  • 1 Years Hosting FREE
  • FREE simple logo design
  • FREE stock images
  • Unlimited design revisions
  • Video integration
  • Contact/enquiry forms
  • Phone support
  • "Find us" using Google Maps
  • Paypal "Buy Now" buttons