FLEXIcontent search: order by relevance

Written by

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

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;
  }
}
Alex

Alex is the founder / owner of Freshpage Web Design and has a wealth of experience across all levels of web development, including Java, SQL, HTML, CSS, PHP as well as content management systems such as Wordpress, Joomla and Magento.