Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
SearchController.php
1 <?php
2  /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9 
10  */
11 
13 {
14  /**
15  * action for autosuggestion a search request
16  *
17  * @return bool
18  */
19  public function actionAutosuggest()
20  {
21  $phrase = Yii::app()->request->getQuery('searchTerm', '');
22  $secureAutosuggestUrl = Yii::app()->request->getQuery('autosuggestUrl');
23 
24  $result = array('data'=>array());
25 
26  $params = array(
27  'filter' => $phrase,
28  'type' => 'php',
29  );
30  $searchApi = new SearchApi();
31  if(!empty($secureAutosuggestUrl)){
32  $url = Yii::app()->securityManager->validateData($secureAutosuggestUrl);
33  if(!empty($url)){
34  $searchApi->autosuggestUrl = $url;
35  }
36  }
37 
38  $data = $searchApi->getRepositoryApi()->requestAutosuggest($params);
39 
40  if ($data = unserialize($data)) {
41  if ($data['status']=='ok') {
42  unset($data['status']);
43  $result['qty'] = count($data);
44  foreach ($data as $resultItem) {
45  $result['data'][$resultItem['attributes']['word']] = $resultItem['attributes']['word'];
46  }
47  }
48  }
49 
50  echo json_encode($result['data']);
51  }
52 
53  public function actionTestDriver()
54  {
55  $usePersonalization = true;
56  $term = 'content:(user)';
57  $params = array();
58 
59  $adaptor = new SearchAdaptor($term, $params, $usePersonalization);
60  $adaptor->pageNumber = 1;
61  $adaptor->pageSize = 10;
62  $results = $adaptor->fetchNext();
63  var_dump($results, $adaptor->existsMore());
64 
65  $results = $adaptor->fetchNext();
66  var_dump($results, $adaptor->existsMore());
67  $results = $adaptor->fetchNext();
68  var_dump($results, $adaptor->existsMore());
69  die;
70  $adaptor = new SearchAdaptor($term, $params, $usePersonalization);
71  $adaptor->pageNumber = 2;
72  $adaptor->pageSize = 10;
73  $results = $adaptor->fetchNext();
74  var_dump($results, $adaptor->existsMore());
75 
76  $adaptor = new SearchAdaptor($term, $params, $usePersonalization);
77  $adaptor->pageNumber = 1;
78  $adaptor->pageSize = 10;
79  $results = $adaptor->fetchNext();
80  $results = $adaptor->fetchNext();
81  var_dump($results, $adaptor->existsMore());
82  }
83 }
84 
85 ?>