Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Search Form, Results, Custom Fields

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3
Go to End
Author Topic: 3854 Views
  • stew
    Avatar
    Community Member
    30 Posts

    Re: Search Form, Results, Custom Fields Link to this post

    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
    /////////////////////////////////////////////////////////////

    3854 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.