Search function modifications
Posted: Wed Jan 21, 2009 6:24 pm
I have been working with CMSMS MLE for a client, and I wanted multi-lingual functionality in the search module. While I was at it, I enabled it to display a snippet of the page's content in the appropriate language. While I'm only using two languages (English and Spanish) this example may be useful to someone else. With the example, you will need to find the appropriate place in the code and enter the changes.
I'm using the Search module (version 1.5)
action.dosearch.php
------------------------------------------------------------------------------------------------------------------------
line 81
$content =& $node->GetContent();
if (isset($content))
{
if($_GET['hl']=="es_MX")
{
$pageContent = $content->GetPropertyValue("content_es");
}
else
{
$pageContent = $content->GetPropertyValue("content_en");
}
$col->AddItem($content->Name(), $content->GetURL(), $pageContent, $result->fields['total_weight']);
}
------------------------------------------------------------------------------------------------------------------------
line 231 (close enough)
foreach( $results as $result )
{
$title = $result->title;
$txt = $result->urltxt;
$txt = strip_tags($txt);
$txt = substr($txt, 0, 300);
foreach( $words as $word )
{
$title = preg_replace('/('.$word.')/i', '$1', $title);
$txt = preg_replace('/('.$word.')/i', '$1', $txt);
}
$result->title = $title;
$result->urltxt = $txt;
$newresults[] = $result;
}
------------------------------------------------------------------------------------------------------------------------
Result Template:
{if ($parent_lang=="en")}{$searchresultsfor}{else}Resultados de búsqueda para{/if} "{$phrase}"
{if $itemcount > 0}
{foreach from=$results item=entry}
url}">{$entry->title}
{$entry->urltxt}[...]
url}">{$entry->url}
Read more...
{/foreach}
{$timetaken}: {$timetook}-->
{else}
{$noresultsfound}
{/if}
------------------------------------------------------------------------------------------------------------------------
Tell me what you think!
I'm using the Search module (version 1.5)
action.dosearch.php
------------------------------------------------------------------------------------------------------------------------
line 81
$content =& $node->GetContent();
if (isset($content))
{
if($_GET['hl']=="es_MX")
{
$pageContent = $content->GetPropertyValue("content_es");
}
else
{
$pageContent = $content->GetPropertyValue("content_en");
}
$col->AddItem($content->Name(), $content->GetURL(), $pageContent, $result->fields['total_weight']);
}
------------------------------------------------------------------------------------------------------------------------
line 231 (close enough)
foreach( $results as $result )
{
$title = $result->title;
$txt = $result->urltxt;
$txt = strip_tags($txt);
$txt = substr($txt, 0, 300);
foreach( $words as $word )
{
$title = preg_replace('/('.$word.')/i', '$1', $title);
$txt = preg_replace('/('.$word.')/i', '$1', $txt);
}
$result->title = $title;
$result->urltxt = $txt;
$newresults[] = $result;
}
------------------------------------------------------------------------------------------------------------------------
Result Template:
{if ($parent_lang=="en")}{$searchresultsfor}{else}Resultados de búsqueda para{/if} "{$phrase}"
{if $itemcount > 0}
{foreach from=$results item=entry}
url}">{$entry->title}
{$entry->urltxt}[...]
url}">{$entry->url}
Read more...
{/foreach}
{$timetaken}: {$timetook}-->
{else}
{$noresultsfound}
{/if}
------------------------------------------------------------------------------------------------------------------------
Tell me what you think!