CakePHP/Croogo: How to search in translated nodes too -


in croogo's search-view nodes-controller results include nodes, searched term found on node's model fields, skip translated content nodes.

i'm trying override functionality , add support translated content well, having hard time override search-view without having override whole node-controller.

does has done before , give me advice, approach take?

for interested, ended doing following:

  • add new searchcontroller on plugin show-view, adapted version of search-view on nodescontroller.
  • override search/* route new view.

in order search in translated fields, came 2 possible approaches:

1) if using paginate this, there necessary join node , i18n tables, first , string additionally on joined fields.

2) or, first find distinct nodes matching content on i18n table through query. , use list of nodes add condition of "or node.id in (list_of_nodes)"

i ended alternative 2, , how show-view looks like:

public function show() {     if (!isset($this->request->params['named']['q'])) {         $this->redirect('/');     }      app::uses('sanitize', 'utility');     $q = sanitize::clean($this->request->params['named']['q']);     $results = $this->node->query(         "select distinct(foreign_key) `i18n` " .         "where content '%" . $q . "%';");     $node_ids = array();     foreach($results $res) {         $node_ids[] = $res['i18n']['foreign_key'];     }     $this->paginate['node']['order'] = 'node.created desc';     $this->paginate['node']['limit'] = configure::read('reading.nodes_per_page');     $this->paginate['node']['conditions'] = array(         'node.status' => 1,         'and' => array(             array(                 'or' => array(                     'node.title like' => '%' . $q . '%',                     'node.excerpt like' => '%' . $q . '%',                     'node.body like' => '%' . $q . '%',                     'node.id' => $node_ids,                 ),             ),             array(                 'or' => array(                     'node.visibility_roles' => '',                     'node.visibility_roles like' => '%"' . $this->croogo->roleid . '"%',                 ),             ),         ),     );     // more stuff ... } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -