0

わかりました、ケースは次のとおりです。

いくつかのドロップダウンと複数の選択フィールドを持つフォームがあります。

プロパティの種類による検索を実行する必要があることを除いて、これまでのところすべて問題ありません。and/or and だけでなく、フォームの残りの部分についても (または、少なくとも残りの部分については or であると信じています)。

つまり、プロパティ タイプ 1 && プロパティ タイプ 2 && (サブタイプ 1 || sybtype 2 || sybtype 3)

もう 1 つのことは、すべてのサブタイプを選択すると、何も選択されていない場合と同じ結果が表示されることです。

「and」検索に関して、このプラグインによって提供される検索機能に関するより詳細なチュートリアルをどこで読んだり見たりすればよいか、私には本当にわかりません。

私がモデルに持っているものは次のとおりです。

    public $filterArgs = array(
        //array('name' => 'price', 'type' => 'query', 'method' => 'filterTitle'),
        array('name' => 'province_id', 'type' => 'value'),
        array('name' => 'city_id', 'type' => 'value'),
        array('name' => 'quarter_id', 'type' => 'value'),
        array('name' => 'refid', 'type' => 'value'),
        array('name' => 'to', 'type' => 'value'),
        array('name' => 'price1', 'name2' => 'price2', 'type' => 'expression', 'method' => 'priceRange', 'field' => 'Offer.price BETWEEN ? AND ?'),
        array('name' => 'area1', 'name2' => 'area2', 'type' => 'expression', 'method' => 'areaRange', 'field' => 'Offer.area BETWEEN ? AND ?'),
        array('name' => 'type_id', 'type' => 'query', 'method' => 'ManyOrConditions'),
        array('name' => 'subtype_id', 'type' => 'query', 'method' => 'ManyOrConditions'),
        array('name' => 'feature_id', 'type' => 'subquery', 'method' => 'findByTags1', 'field' => 'Offer.id'),
    );

   public function ManyOrConditions($data = array()) {
        //debug($data);
        $filter = $data['type_id'];
        //not sure if this works
        //$subtype = $data['subtype_id'];

        $cond = array(
            'OR' => array(
                $this->alias . '.type_id ' => $filter,
                //not sure if the below will work?
                //$this->alias . '.subtype_id ' => $subtype
        ));
        //debug($cond);
        return $cond;
    }

    public function orConditions($data = array()) {
        //debug($data);
        $filter = $data['type_id'];
        $cond = array(
            'OR' => array(
                $this->alias . '.type_id LIKE' => '%' . $filter . '%',
            //$this->alias . '.body LIKE' => '%' . $filter . '%',
        ));
        return $cond;
    }

私が理解しているところは、type_idの「または」検索のみを作成していることです...申し訳ありませんが、これで本当に迷っています。

私は Cakephp を初めて使用し、これまでに数千行のコードを読み、このシステムに多くの変更を加えることができましたが、ここでは、このプラグインに関するドキュメントが不足しているため、何をすべきかわかりません :(

このhttps://github.com/CakeDC/searchではなく、チュートリアルや適切なドキュメントへのガイダンスをいただければ幸いです。

これが正しい場合は、何が欠けているか教えてください。

PSここで他のコードが必要な場合は、お知らせください。提供します。

4

3 に答える 3

0

これが、より複雑な検索のために私がやったことです。CakeDC 検索プラグインを使用する...これは「LIKE AND」の代わりに「LIKE OR」を使用しますが、検索プラグインを使用してより複雑な検索を行う方法に光を当てることを願っています。

User.search は、送信フォームの入力要素名です。

class User extends AppModel {
    public $filterArgs = array(
        'search' => array('type' => 'like', 'field' => array('User.name', 'User.email'))
    }
}

class UsersController extends AppController {
    public $components = array('Search.Prg');

    public function index() {
        $this->Prg->commonProcess();

        $this->User->data['User'] = $this->passedArgs;

        if ($this->User->Behaviors->loaded('Searchable')) {
           $query = $this->passedArgs;
           $parsedConditions = $this->User->parseCriteria($query);
       } else {
           $parsedConditions = array();
       }

       $this->Paginator->settings['User']['conditions'] = $parsedConditions;

       $this->set('users', $this->Paginator->paginate());
    }
}
于 2014-09-24T22:31:39.527 に答える