Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS /

Search Form, Results, Custom Fields


Reply


17 Posts   4262 Views

Avatar
stew

Community Member, 30 Posts

27 July 2010 at 2:25am

Been banging my head on the desk for a few hours now trying to get the multiple search terms thing to work, it's really not playing ball.

Any ideas on what I am doing wrong? The code I'm using at the moment in Page.php is below:

/////////////////////////////////////////////////////////////
// Start Custom

$arrSearchQuery = explode(' ',$form->getSearchQuery());
$strSearchQuery = '%'.implode('%',$arrSearchQuery).'%';

   $dos = DataObject::get('Organisation',"(Name LIKE '".$strSearchQuery."'"."OR Address1 LIKE '".$strSearchQuery."'"."OR Address2 LIKE '".$strSearchQuery."'"."OR Address3 LIKE '".$strSearchQuery."'"."OR Phone LIKE '".$strSearchQuery."'"."OR SearchTerm LIKE '".$strSearchQuery."') AND Public=1" );   

//make our our result set
$dosNewRestults = new DataObjectSet();

if ($dos)
{
   $arr = $dos->toArray();
   foreach ($arr as $do)
   {
      $p = new Page();
      $p->Title = $do->Name;
      $p->URLSegment = '/organisations/retrieve_org/'.$do->ID.'/';;
      $p->Content = $do->Description;;
      $p->HouseNameNumber = $do->HouseNameNumber;;
      $p->Address1 = $do->Address1;;
      $p->Address2 = $do->Address2;;
      $p->Address3 = $do->Address3;;
      $p->PostCode = $do->PostCode;;
      $p->Latitude = $do->Latitude;;
      $p->Longitude = $do->Longitude;;
      $p->Phone = $do->Phone;;
      $p->Web = $do->Web;;
      $p->Email = $do->Email;;
      $p->MapCategory = $do->MapCategory;;
      $p->SearchTerm = $do->SearchTerm;;
      $p->LegalStatus = $do->LegalStatus;;
      $p->LegalStatusNumber = $do->LegalStatusNumber;;
      $p->ID = $do->ID;;
      $p->Relevance = 1;
      $p->CanViewType = 'Anyone';

      $dosNewRestults->push($p);
   }
   }
   foreach ($arrSearchQuery as $strSearchQuery)
   {
    $strSearchQuery = '%'.$strSearchQuery.'%';

    //repeat code to do DataOBject::get
    //add to $dosNewResults
   }
   
//strip out the html from the results and append them to the results
//above - so that the ones with things to buy are first
if ($data['Results']->Count() > 0)
{
$arr = $data['Results']->toArray();
foreach ($arr as $do)
{
$do->Content = strip_tags($do->Content);
$dosNewRestults->push($do);
      $dosNewRestults->removeDuplicates('URLSegment');
}
}

$data['Results'] = $dosNewRestults;
// End Custom
/////////////////////////////////////////////////////////////