2015-09-11 58 views
1

我有一個小問題,解決讓SilverStripe 3.1 Fulltextsearchable運行良好,我的用法。我從成員數據對象中檢索一些信息,並創建鏈接和標題以在Page_search.ss模板上顯示它們。Silverstripe自定義搜索成員dataobject

有我的代碼工作,但...... 壞搜索過濾

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

    $query = htmlspecialchars($data['Search'], ENT_QUOTES,'UTF-8'); 
    $PageMembres = Member::get()->filter('NomOrganisme',$query); 

    $searchresults = new ArrayList(); 

    foreach($PageMembres as $membre) { 
     if ($membre->Type==1) { $dir="repertoire-culturel/organismes-entreprises/details/"; } 
     if ($membre->Type==2) { $dir="repertoire-culturel/individus-artistes/details/"; } 

     $searchresults->push(

       array( "Title" => $membre->NomOrganisme, 
          "link" => $membre->ID,  
          "Link" => Director::BaseURL().$dir.$membre->ID,  
          "URL" => $membre->ID,  

       ) 
     ); 

    } 



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

    $data['Title'] = 'Résultat(s) de recheche'; 

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

所以我這一點,我需要改變:

$PageMembres = Member::get()->filter('NomOrganisme',$query); 

對於更配合物的研究如:

$PageMembres = DataObject::get("Member","MATCH (NomOrganisme,FirstName,Surname,Description) AGAINST ('$query' IN BOOLEAN MODE)"); 

我錯過了複合查詢?爲什麼它不起作用? 感謝您的回覆!

回答

0

我認爲我們不能在DataObject成員上使用MATCH查詢。有我使用和運作的複雜工作代碼:

$PageMembres = Member::get()->where(" 
     FirstName LIKE '%$query%' OR 
     Surname LIKE '%$query%' OR 
     Description LIKE '%$query%' OR 
     NomOrganisme LIKE '%$query%'");