Page 1 of 1

Search function modifications

Posted: Wed Jan 21, 2009 6:24 pm
by flyingbuttressman
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!

Re: Search function modifications

Posted: Wed Jan 21, 2009 6:34 pm
by Rolf
Hey, looks very good, flyingbuttressman!!  :D

But a changed file could be overwritten with an upgrade. You will lose the changes...
Perhaps you could suggest this as a future request at the Forge. [ http://dev.cmsmadesimple.org/ ]

Even though, very nice! Keep going  ;)

Rolf

Re: Search function modifications

Posted: Mon Jan 26, 2009 12:18 pm
by alby
flyingbuttressman wrote: I have been working with CMSMS MLE for a client, and I wanted multi-lingual functionality in the search module.
I had misunderstanding.
For changing labels use {..... lang=$lang} in your tag and/or use $mle_translation.key

Alby