Author Topic: "Did you mean" module for VM search  (Read 3527 times)

MIBJE

  • Beginner
  • *
  • Posts: 23
    • mibook.dk Denmarks biggest e-bookstore 160000 titler both english and Danish
"Did you mean" module for VM search
« on: January 24, 2012, 19:46:40 pm »
Hey Guys!

I found this article about how to implemented "did you mean" in the search modul for joomlas standart search module. But has enyone tryed to use it with Virtuemart 1.1.8 in their VM search module(mod_alc_vm_search)? 

How to add "Google - Did you mean?" suggestion to Joomla search by http://joomla-r-u s.com/home/37-joomlatutorials/48-how-to-add-qdid-you-meanq-suggestion-to-joomla-search

Open {Joomla}/components/com_search/views/search/view.html.php

Locate this line (around 160) :

 $this->result   = JText::sprintf( 'TOTALRESULTSFOUND', $total );
Insert the following lines after it :


$didyoumean='';
if ( $total == 0 ) {
   // Ping Google to get spelling suggestion
   $ask="http://www.google.com/search?q=" . str_replace(' ', '+', $searchword);
   $ask=str_replace('..','.',$ask);

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL,$ask);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,3);
   curl_setopt($ch, CURLOPT_TIMEOUT,3);
   $get= curl_exec($ch);
   $get=utf8_encode($get);

   $get=explode("spell=1",$get);
   if ( sizeof($get) > 1 ) {
      $get=explode("</a>",$get[1]);
      $get=explode("class=spell>",$get[0]);
      if ( sizeof($get) > 1 ) {
         $res=$get[1];
         if ( strlen($res)>2) {
            $didyoumean = '<font class="p" color="#cc0000">Did you mean :
              </font><a href="/index.php?option=com_search&searchword=' .
              urlencode(strip_tags($res)) . '">' . $res . '</a>';
         }
      }
  }
}
$this->assignRef('didyoumean',    $didyoumean); 


Open {Joomla}/components/com_search/views/search/tmpl/default_error.php

Change the content, from:

<table class="searchintro<?php echo $this->params->get( 'pageclass_sfx' ); ?>"> 
        <tr> 
                <td colspan="3" > 
                        <font class="p" color="#cc0000"> 
                        <?php echo $this->escape($this->error); ?> 
                        </font> 
                </td> 
        </tr> 
</table> 
to:

 <table class="searchintro<?php echo $this->params->get( 'pageclass_sfx' ); ?>"> 
        <tr> 
                <td colspan="3" > 
                        <font class="p" color="#cc0000"> 
                        <?php echo $this->escape($this->error); ?> 
                        </font> 
                </td> 
        </tr> 
<?php 
   if ( $this->didyoumean != '' ) { 
      print '<tr>'; 
      print '<td colspan="3">'; 
      print $this->didyoumean; 
      print '</td>'; 
      print '</tr>'; 
   } 
?> 
</table>


Done!
Best regards
Jesper

mibook.dk is Denmark largest ebookstore, with more then 160.000 ebook titlers ind Danish and English http://mibook.dk/Danske-e-boger.html and http://mibook.dk/engelske-e-boger.html. Do you enjoy audiobooks we have that ass well check out http://mibook.dk/lydboger.html