test
Viewing 1 post (of 1 total)
  • Author
    Posts
  • Pankaj Sharma Moderator
    #195762

    solution:
    Stage 1: Add Relevance
    pluginssearchcontentcontent.php: Insert this between the if ($sContent && $limit > 0){ and before the from part of the query $query->from(‘#__content AS a’);
    [PHP]$sql_keyword = strtolower(trim($db->Quote($db->escape($text, true), false)));
    $query->select(‘
    (1000*((LENGTH(TRIM(a.title)) – LENGTH(REPLACE(LOWER(TRIM(a.title)), ‘.$sql_keyword.’,”))) / LENGTH(‘.$sql_keyword.’))) +
    (60*((LENGTH(TRIM(a.introtext)) – LENGTH(REPLACE(LOWER(TRIM(a.introtext)), ‘.$sql_keyword.’,”))) / LENGTH(‘.$sql_keyword.’))) +
    (40*((LENGTH(TRIM(a.`fulltext`)) – LENGTH(REPLACE(LOWER(TRIM(a.`fulltext`)), ‘.$sql_keyword.’,”))) / LENGTH(‘.$sql_keyword.’))) AS relevance
    ‘); [/PHP]

    pluginssearchcontentcontent.php: Insert this between the if ($sArchived && $limit > 0){ and before the from part of the query $query->from(‘#__content AS a’);
    [PHP] $sql_keyword = strtolower(trim($db->Quote($db->escape($text, true), false)));
    $query->select(‘
    (1000*((LENGTH(TRIM(a.title)) – LENGTH(REPLACE(LOWER(TRIM(a.title)), ‘.$sql_keyword.’,”))) / LENGTH(‘.$sql_keyword.’))) +
    (60*((LENGTH(TRIM(a.introtext)) – LENGTH(REPLACE(LOWER(TRIM(a.introtext)), ‘.$sql_keyword.’,”))) / LENGTH(‘.$sql_keyword.’))) +
    (40*((LENGTH(TRIM(a.`fulltext`)) – LENGTH(REPLACE(LOWER(TRIM(a.`fulltext`)), ‘.$sql_keyword.’,”))) / LENGTH(‘.$sql_keyword.’))) AS relevance
    ‘); [/PHP]

    pluginssearchcontentcontent.php: Add the option to select by relevance to the CASE order statement:
    [PHP] $morder = ”;
    switch ($ordering) {

    case ‘relevance’:
    $order = ‘relevance DESC’;
    break;

    case ‘oldest’:
    $order = ‘a.created ASC’;
    break;

    case ‘popular’:
    $order = ‘a.hits DESC’;
    break;

    case ‘alpha’:
    $order = ‘a.title ASC’;
    break;

    case ‘category’:
    $order = ‘c.title ASC, a.title ASC’;
    $morder = ‘a.title ASC’;
    break;

    case ‘newest’:
    default:
    $order = ‘a.created DESC’;
    break; [/PHP]

    To add it to the frontend as option in advanced search: OPTION FOR SITE VISITORS componentscom_searchviewssearchtmpldefault.xml:

    <field
    name="ordering"
    type="list"
    default="0"
    description="COM_SEARCH_ORDERING_DESC"
    label="COM_SEARCH_ORDERING_LABEL"
    >
    <option value="newest">COM_SEARCH_NEWEST_FIRST</option>
    <option value="oldest">COM_SEARCH_OLDEST_FIRST</option>
    <option value="popular">COM_SEARCH_MOST_POPULAR</option>
    <option value="alpha">COM_SEARCH_ALPHABETICAL</option>
    <option value="category">JCATEGORY</option>
    <option value="relevance">COM_SEARCH_MOST_RELEVANT</option>
    </field>

    To add it to the frontend as option in advanced search: FUNCTIONALITY componentscom_searchviewssearchview.html.php:
    [PHP]
    $orders = array();
    $orders[] = JHtml::_(‘select.option’, ‘newest’, JText::_(‘COM_SEARCH_NEWEST_FIRST’));
    $orders[] = JHtml::_(‘select.option’, ‘oldest’, JText::_(‘COM_SEARCH_OLDEST_FIRST’));
    $orders[] = JHtml::_(‘select.option’, ‘popular’, JText::_(‘COM_SEARCH_MOST_POPULAR’));
    $orders[] = JHtml::_(‘select.option’, ‘alpha’, JText::_(‘COM_SEARCH_ALPHABETICAL’));
    $orders[] = JHtml::_(‘select.option’, ‘category’, JText::_(‘JCATEGORY’));
    $orders[] = JHtml::_(‘select.option’, ‘relevance’, JText::_(‘COM_SEARCH_MOST_RELEVANT’)); [/PHP]

    To add it to the frontend as option in advanced search: LANGUAGE FILE languageen-GBen-GB.com_search.ini:


    COM_SEARCH_MOST_POPULAR="Most Popular"
    COM_SEARCH_MOST_RELEVANT="Most Relevant"
    COM_SEARCH_NEWEST_FIRST="Newest First"
    COM_SEARCH_OLDEST_FIRST="Oldest First"

    😀

Viewing 1 post (of 1 total)

This topic contains 1 reply, has 1 voice, and was last updated by  Pankaj Sharma 10 years, 9 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum