Jump to:

22992 Posts in 11842 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Searchcontext with multiple DataObjects

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 406 Views
  • CraftsMan
    Avatar
    Community Member
    35 Posts

    Searchcontext with multiple DataObjects Link to this post

    I am using the search context to search a DataObject within model admin. I have followed this:
    http://doc.silverstripe.org/framework/en/reference/searchcontext/ to get it working.

    How can I get this to work with multiple DataObjects?

  • Bereusei
    Avatar
    Community Member
    94 Posts

    Re: Searchcontext with multiple DataObjects Link to this post

    Add this to your Page_Controller (in the Page.php):

    public function results($data, $form){
    $data = $_REQUEST;

    $query = htmlspecialchars($data['Search'], ENT_QUOTES,'UTF-8');

    $obj1 = DataObject::get("Obj1","MATCH (Title, MetaKeywords) AGAINST ('$query' IN BOOLEAN MODE)");
    $obj2 = DataObject::get("Obj2","MATCH (Title, MetaKeywords) AGAINST ('$query' IN BOOLEAN MODE)");
    $obj3 = DataObject::get("Obj3","MATCH (Title, MetaKeywords) AGAINST ('$query' IN BOOLEAN MODE)");

    $searchresults = new DataObjectSet();
    $searchresults->merge($obj1);
    $searchresults->merge($obj2);
    $searchresults->merge($obj3);

    if($searchresults){
    $data['Results'] = $searchresults;
    } else {
    $data['Results'] = '';
    }

    $data['Title'] = 'Searchresults';

    return $this->customise($data)->renderWith(array('Page_results', 'Page'));
    }

    This works for the standard searchfield in Silverstripe.

    406 Views
Page: 1
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.