~tsep-dev/tsep/tsep2

« back to all changes in this revision

Viewing changes to src/TSEP/Bundle/SearchBundle/Controller/PageController.php

  • Committer: xaav
  • Date: 2011-10-01 18:10:50 UTC
  • Revision ID: git-v1:e1357bf55d2d528a58efeead2a02193370e17823
CS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
     * @Template()
16
16
     * @Route("/", name="search")
17
17
     */
18
 
        public function searchAction () {
 
18
    public function searchAction () {
19
19
 
20
 
            $search = new Search();
 
20
        $search = new Search();
21
21
        $form = $this->createForm(new SearchFormType(), $search);
22
22
 
23
23
        $request = $this->getRequest();
36
36
            }
37
37
        }
38
38
 
39
 
                return array(
40
 
                    'results' => $results,
41
 
                    'form' => $form->createView(),
42
 
                );
43
 
        }
 
39
        return array(
 
40
            'results' => $results,
 
41
            'form' => $form->createView(),
 
42
        );
 
43
    }
44
44
}
45
45
 
46
46
/*
47
47
 *
48
48
 * <?php
49
 
        /**
50
 
        * The heart of TSEP: manages indexes, stopwords, ect.
51
 
        *
52
 
        * @author Xaav
53
 
        *
54
 
        * The following will be filled automatically by SubVersion!
55
 
        * Do not change by hand!
56
 
        *  $LastChangedDate$
57
 
        *  $LastChangedBy$
58
 
        *  $LastChangedRevision$
59
 
        *
60
 
        *
61
 
 
62
 
        class IndicesController extends AppController {
63
 
 
64
 
                var $name = 'Indices';
65
 
 
66
 
                var $uses = array('Index');
67
 
 
68
 
                var $components = array('Indexer');
69
 
 
70
 
 
71
 
                /**
72
 
                 * @var IndexerComponent
73
 
                 *
74
 
                var $Indexer;
75
 
 
76
 
                /**
77
 
                 * @var Index
78
 
                 *
79
 
                var $Index;
80
 
 
81
 
                function _start($auth_key) {
82
 
 
83
 
                        App::import('Vendor', 'start_script');
84
 
 
85
 
                        start_script(
86
 
                                Router::url(
87
 
                                        array(
88
 
                                                'controller' => 'indices',
89
 
                                                'action' => 'run',
90
 
                                                'admin' => false,
91
 
                                                '?' => array(
92
 
                                                        'auth' => $auth_key
93
 
                                                )
94
 
                                        ),
95
 
                                        true
96
 
                                )
97
 
                        );
98
 
                }
99
 
 
100
 
                function search ($profile = null, $page = null) {
101
 
 
102
 
                        $this->set('title_for_layout', 'Search Results');
103
 
 
104
 
                        //Don't care if the query is empty
105
 
                        $query = @$this->params['url']['q'];
106
 
 
107
 
                        if(!empty($query)) {
108
 
 
109
 
                                $this->Index->Profile->Search->add($query);
110
 
 
111
 
                                $this->paginate = array(
112
 
                                        'conditions' => array(
113
 
                                                'MATCH(Index.text) AGAINST(? IN BOOLEAN MODE)' => array($query)
114
 
                                        ),
115
 
                                        'limit' => 10,
116
 
                                );
117
 
 
118
 
                                $matches = $this->paginate('Index');
119
 
 
120
 
                                unset($this->params['url']['url']);
121
 
 
122
 
                                //Truncate the results
123
 
 
124
 
                                foreach ($matches as $key => $match) {
125
 
 
126
 
                                        $matches[$key]['Index']['text'] = substr($match['Index']['text'], 0, 255);
127
 
                                }
128
 
 
129
 
                                $this->set('matches', $matches);
130
 
                        }
131
 
                        else {
132
 
                                $this->set('matches', array());
133
 
                        }
134
 
                }
135
 
 
136
 
                /**
137
 
                 * Processes the indexing queue
138
 
                 *
139
 
                function run () {
140
 
 
141
 
                        $this->log('Run action called.');
142
 
 
143
 
                        ob_start();
144
 
 
145
 
 
146
 
                        $auth = $this->Indexer->processRequest($this->params['url']['auth']);
147
 
 
148
 
                        if($auth) {
149
 
 
150
 
                                $this->_start($auth);
151
 
                        }
152
 
 
153
 
                        die();
154
 
                }
155
 
 
156
 
                function admin_start ($id = null) {
157
 
 
158
 
                        if (!empty($id)){
159
 
 
160
 
                                $auth = $this->Indexer->submitRequest($id);
161
 
 
162
 
                                $this->_start($auth);
163
 
                        }
164
 
 
165
 
                        $this->redirect(array('controller'=>'profiles', 'action' => 'index'), null, true);
166
 
 
167
 
                }
168
 
 
169
 
                /**
170
 
                 * List all of the indices
171
 
                 *
172
 
                function admin_index() {
173
 
 
174
 
                        $this->paginate = array(
175
 
                                'limit' => 10
176
 
                        );
177
 
 
178
 
                        $this->set('indices', $this->paginate('Index'));
179
 
 
180
 
                }
181
 
 
182
 
                /**
183
 
                 * View an index
184
 
                 *
185
 
                function admin_view () {
186
 
 
187
 
                }
188
 
        }
189
 
 */
 
 
b'\\ No newline at end of file'
 
49
    /**
 
50
    * The heart of TSEP: manages indexes, stopwords, ect.
 
51
    *
 
52
    * @author Xaav
 
53
    *
 
54
    * The following will be filled automatically by SubVersion!
 
55
    * Do not change by hand!
 
56
    *  $LastChangedDate$
 
57
    *  $LastChangedBy$
 
58
    *  $LastChangedRevision$
 
59
    *
 
60
    *
 
61
 
 
62
    class IndicesController extends AppController {
 
63
 
 
64
        var $name = 'Indices';
 
65
 
 
66
        var $uses = array('Index');
 
67
 
 
68
        var $components = array('Indexer');
 
69
 
 
70
 
 
71
        /**
 
72
         * @var IndexerComponent
 
73
         *
 
74
        var $Indexer;
 
75
 
 
76
        /**
 
77
         * @var Index
 
78
         *
 
79
        var $Index;
 
80
 
 
81
        function _start($auth_key) {
 
82
 
 
83
            App::import('Vendor', 'start_script');
 
84
 
 
85
            start_script(
 
86
                Router::url(
 
87
                    array(
 
88
                        'controller' => 'indices',
 
89
                        'action' => 'run',
 
90
                        'admin' => false,
 
91
                        '?' => array(
 
92
                            'auth' => $auth_key
 
93
                        )
 
94
                    ),
 
95
                    true
 
96
                )
 
97
            );
 
98
        }
 
99
 
 
100
        function search ($profile = null, $page = null) {
 
101
 
 
102
            $this->set('title_for_layout', 'Search Results');
 
103
 
 
104
            //Don't care if the query is empty
 
105
            $query = @$this->params['url']['q'];
 
106
 
 
107
            if(!empty($query)) {
 
108
 
 
109
                $this->Index->Profile->Search->add($query);
 
110
 
 
111
                $this->paginate = array(
 
112
                    'conditions' => array(
 
113
                        'MATCH(Index.text) AGAINST(? IN BOOLEAN MODE)' => array($query)
 
114
                    ),
 
115
                    'limit' => 10,
 
116
                );
 
117
 
 
118
                $matches = $this->paginate('Index');
 
119
 
 
120
                unset($this->params['url']['url']);
 
121
 
 
122
                //Truncate the results
 
123
 
 
124
                foreach ($matches as $key => $match) {
 
125
 
 
126
                    $matches[$key]['Index']['text'] = substr($match['Index']['text'], 0, 255);
 
127
                }
 
128
 
 
129
                $this->set('matches', $matches);
 
130
            }
 
131
            else {
 
132
                $this->set('matches', array());
 
133
            }
 
134
        }
 
135
 
 
136
        /**
 
137
         * Processes the indexing queue
 
138
         *
 
139
        function run () {
 
140
 
 
141
            $this->log('Run action called.');
 
142
 
 
143
            ob_start();
 
144
 
 
145
 
 
146
            $auth = $this->Indexer->processRequest($this->params['url']['auth']);
 
147
 
 
148
            if($auth) {
 
149
 
 
150
                $this->_start($auth);
 
151
            }
 
152
 
 
153
            die();
 
154
        }
 
155
 
 
156
        function admin_start ($id = null) {
 
157
 
 
158
            if (!empty($id)){
 
159
 
 
160
                $auth = $this->Indexer->submitRequest($id);
 
161
 
 
162
                $this->_start($auth);
 
163
            }
 
164
 
 
165
            $this->redirect(array('controller'=>'profiles', 'action' => 'index'), null, true);
 
166
 
 
167
        }
 
168
 
 
169
        /**
 
170
         * List all of the indices
 
171
         *
 
172
        function admin_index() {
 
173
 
 
174
            $this->paginate = array(
 
175
                'limit' => 10
 
176
            );
 
177
 
 
178
            $this->set('indices', $this->paginate('Index'));
 
179
 
 
180
        }
 
181
 
 
182
        /**
 
183
         * View an index
 
184
         *
 
185
        function admin_view () {
 
186
 
 
187
        }
 
188
    }
 
189
 */