/[drupal]/contributions/modules/sphinxsearch/sphinxsearch.admin.inc
ViewVC logotype

Contents of /contributions/modules/sphinxsearch/sphinxsearch.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Fri Sep 12 02:44:22 2008 UTC (14 months, 2 weeks ago) by markuspetrux
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.3: +58 -10 lines
File MIME type: text/x-php
- Ported module from D5 to D6.
- Bugfix: undefined class method in sphinxsearch_check_connection_page().
- Bugfix: added criterion class to taxonomy elements in advanced search form.
- Bugfix: added support for mysqli and pgsql to _sphinxsearch_db_reconnect().
1 <?php
2 // $Id: sphinxsearch.admin.inc,v 1.1.2.12 2008/09/03 01:38:55 markuspetrux Exp $
3
4 /**
5 * @file
6 * Administration interface for the sphinxsearch module.
7 */
8
9 /**
10 * Module settings form.
11 */
12 function sphinxsearch_settings() {
13 $form = array();
14
15 if (sphinxsearch_get_memory_limit() < 0) {
16 drupal_set_message(t('Function <em>memory_get_usage</em> not found. Please, make sure your PHP installation is compiled with --enable-memory-limit option.'), 'error');
17 }
18
19 $form['server'] = array(
20 '#type' => 'fieldset',
21 '#title' => t('Sphinx server settings'),
22 '#collapsible' => FALSE,
23 '#description' => t('Use this section to setup options related to your Sphinx server installation.'),
24 );
25 $form['server']['searchd'] = array(
26 '#type' => 'fieldset',
27 '#collapsible' => FALSE,
28 );
29 $form['server']['searchd']['sphinxsearch_searchd_host'] = array(
30 '#type' => 'textfield',
31 '#title' => t('Sphinx searchd host name'),
32 '#default_value' => variable_get('sphinxsearch_searchd_host', 'localhost'),
33 '#description' => t('Host name where your <strong>Sphinx searchd daemon</strong> is running, i.e. <code>localhost</code>, <code>sphinx.example.com</code> or <code>192.168.0.1</code>.'),
34 '#required' => TRUE,
35 );
36 $form['server']['searchd']['sphinxsearch_searchd_port'] = array(
37 '#type' => 'textfield',
38 '#title' => t('Sphinx searchd port'),
39 '#default_value' => variable_get('sphinxsearch_searchd_port', '3312'),
40 '#description' => t('Port on which your <strong>Sphinx searchd daemon</strong> listens. Default Sphinx port is 3312.'),
41 '#required' => TRUE,
42 );
43 $form['server']['searchd']['sphinxsearch_searchd_timeout'] = array(
44 '#type' => 'select',
45 '#title' => t('Sphinx searchd connection timeout'),
46 '#default_value' => variable_get('sphinxsearch_searchd_timeout', 0),
47 '#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)),
48 '#description' => t('Timeout in seconds used for connections to your <strong>Sphinx searchd daemon</strong>. Leave 0 for PHP defaults for <a href="@fsockopen" target="_blank">fsockopen()</a>.', array('@fsockopen' => 'http://www.php.net/fsockopen')),
49 );
50 $form['server']['searchd']['sphinxsearch_indexer_ips'] = array(
51 '#type' => 'textfield',
52 '#title' => t('Sphinx indexer IP addresses'),
53 '#default_value' => variable_get('sphinxsearch_indexer_ips', $_SERVER['SERVER_ADDR']),
54 '#description' => t('Enter a comma separated list of IP addresses used by your <strong>Sphinx indexer</strong>. This is necessary to protect access to the XMLPipe generator. Only connections from these IP addresses will be allowed to run this process. You can also specify IP ranges using <a href="http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing" target="_blank">CIDR notation</a>. IPv6 addresses are not supported.'),
55 '#required' => TRUE,
56 );
57 $form['server']['query'] = array(
58 '#type' => 'fieldset',
59 '#title' => t('Query connection settings'),
60 '#collapsible' => TRUE, '#collapsed' => TRUE,
61 );
62 $form['server']['query']['limits'] = array(
63 '#type' => 'fieldset',
64 '#collapsible' => FALSE,
65 );
66 $form['server']['query']['limits']['sphinxsearch_searchd_maxquerytime'] = array(
67 '#type' => 'select',
68 '#title' => t('Maximum query time'),
69 '#default_value' => variable_get('sphinxsearch_searchd_maxquerytime', 0),
70 '#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)),
71 '#description' => t('Sets the maximum search query time in seconds. Use 0 for no limits. Note that if you\'re using several indexes behind a distributed index, then this limit applies to each local index separately.'),
72 );
73 $form['server']['query']['retries'] = array(
74 '#type' => 'fieldset',
75 '#title' => t('Distributed retry count and delay'),
76 '#collapsible' => FALSE,
77 '#description' => t('These options set the retry count and delay in seconds used by <strong>Sphinx searchd daemon</strong> on temporary failures that may happen when sending queries to distributed indexes. Retries are disabled by default.'),
78 );
79 $form['server']['query']['retries']['inline'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
80 $form['server']['query']['retries']['inline']['sphinxsearch_retries_count'] = array(
81 '#type' => 'select',
82 '#title' => t('Number of retries'),
83 '#default_value' => variable_get('sphinxsearch_retries_count', 0),
84 '#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)),
85 );
86 $form['server']['query']['retries']['inline']['separator'] = array('#value' => '&nbsp;&nbsp;&nbsp;&nbsp;');
87 $form['server']['query']['retries']['inline']['sphinxsearch_retries_delay'] = array(
88 '#type' => 'select',
89 '#title' => t('Delay in seconds'),
90 '#default_value' => variable_get('sphinxsearch_retries_delay', 0),
91 '#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)),
92 );
93
94 $form['index'] = array(
95 '#type' => 'fieldset',
96 '#title' => t('Sphinx index settings'),
97 '#collapsible' => FALSE,
98 '#description' => t('Use this section to setup options related to your Sphinx indexes. Note that there a few options that will require you to rebuild your Sphinx indexes if you change them.'),
99 );
100 $form['index']['indexnames'] = array(
101 '#type' => 'fieldset',
102 '#collapsible' => FALSE,
103 );
104 $form['index']['indexnames']['sphinxsearch_query_index'] = array(
105 '#type' => 'textfield',
106 '#title' => t('Index name for queries'),
107 '#default_value' => variable_get('sphinxsearch_query_index', ''),
108 '#description' => t('Name of the Sphinx index used for queries. If you have more than one index (ie. main+delta), you may configure Sphinx with a distributed index that joins all of them (local and/or remote) to provide a single interface to resolve queries.'),
109 );
110 $form['index']['indexnames']['sphinxsearch_excerpts_index'] = array(
111 '#type' => 'textfield',
112 '#title' => t('Index name for building excerpts'),
113 '#default_value' => variable_get('sphinxsearch_excerpts_index', ''),
114 '#description' => t('Regardless of the index used for queries, Sphinx needs an index with tokenizing settings defined to build excerpts. Sphinx may be unable to build excertps from distributed indexes. It is recommended to use the name of your first main index for this purpose.'),
115 );
116 $form['index']['indexer'] = array(
117 '#type' => 'fieldset',
118 '#title' => t('Indexer settings'),
119 '#collapsible' => TRUE, '#collapsed' => TRUE,
120 );
121 $form['index']['indexer']['xmlpipe'] = array(
122 '#type' => 'fieldset',
123 '#title' => t('XMLPipe generation settings'),
124 '#collapsible' => FALSE,
125 '#description' => t('If your indexes take a long time to generate, or your site manages a huge number of nodes, you may need to adjust PHP settings provided in the <strong>.htaccess</strong> file located in the <strong>sphinxsearch_scripts</strong> subdirectory of this module. Additionally, you can use the following options to tell XMLPipe generator to process nodes in chunks to avoid table locks and/or to prevent DB server connection timeouts.'),
126 );
127 $nodes_per_chunk_options = array(0 => t('All')) + drupal_map_assoc(array(
128 250, 500, 700, 750, 1000, 1250, 1500, 1750, 2000, 2250, 2500, 2750, 3000, 3250, 3500, 3750, 4000, 4250, 4500, 4750, 5000,
129 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000,
130 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000,
131 25000, 30000, 35000, 40000, 45000, 50000, 60000, 70000, 80000, 90000, 100000,
132 ));
133 $form['index']['indexer']['xmlpipe']['sphinxsearch_nodes_per_chunk'] = array(
134 '#type' => 'select',
135 '#title' => t('Nodes per chunk'),
136 '#default_value' => variable_get('sphinxsearch_nodes_per_chunk', 0),
137 '#options' => $nodes_per_chunk_options,
138 '#description' => t('Use this option to tell XMLPipe generator to process node in chunks. A new and different SELECT statement against the nodes table will be executed for each chunk. Use 0 to process all nodes at once.'),
139 );
140 $form['index']['indexer']['xmlpipe']['sphinxsearch_chunks_before_restart'] = array(
141 '#type' => 'select',
142 '#title' => t('Chunks before DB restart'),
143 '#default_value' => variable_get('sphinxsearch_chunks_before_restart', 0),
144 '#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100)),
145 '#description' => t('Use this option to tell XMLPipe generator to restart DB server conecction after this specified number of chunks. Use 0 to process all nodes in one single connection.'),
146 );
147 $enabled_node_types = sphinxsearch_get_enabled_node_types();
148 $form['index']['nodetypes'] = array(
149 '#type' => 'fieldset',
150 '#title' => t('Content type settings'),
151 '#collapsible' => TRUE, '#collapsed' => !empty($enabled_node_types),
152 '#description' => t('Use these options to select content types that you wish to be included in your Sphinx indexes. By default, if no content type is selected here, nodes of all content types will be indexed. <strong>Note that you will have to rebuild your indexes if you change these options.</strong>'),
153 );
154 foreach (node_get_types() as $node_type) {
155 $form['index']['nodetypes']['sphinxsearch_include_node_type_'. $node_type->type] = array(
156 '#type' => 'checkbox',
157 '#title' => $node_type->name,
158 '#return_value' => 1,
159 '#default_value' => variable_get('sphinxsearch_include_node_type_'. $node_type->type, 0),
160 );
161 }
162 $enabled_vocabularies = sphinxsearch_get_enabled_vocabularies();
163 $form['index']['taxonomy'] = array(
164 '#type' => 'fieldset',
165 '#title' => t('Taxonomy settings'),
166 '#collapsible' => TRUE, '#collapsed' => !empty($enabled_vocabularies),
167 '#description' => t('Use these options to select vocabularies that you wish to index. By default, if no vocabulary is selected here, all vocabularies in use for enabled content types will be indexed. <strong>Note that you will have to rebuild your indexes if you change these options and/or if you create new vocabularies.</strong>'),
168 );
169 if (module_exists('taxonomy')) {
170 foreach(taxonomy_get_vocabularies() as $vocabulary) {
171 $form['index']['taxonomy']['sphinxsearch_include_vocabulary_'. $vocabulary->vid] = array(
172 '#type' => 'checkbox',
173 '#title' => $vocabulary->name,
174 '#return_value' => 1,
175 '#default_value' => variable_get('sphinxsearch_include_vocabulary_'. $vocabulary->vid, 0),
176 );
177 }
178 }
179 else {
180 $form['index']['taxonomy']['not_available'] = array(
181 '#value' => '<div class="error">'. t('This feature is not available. Taxonomy module is not installed. Note that if you ever enable the taxonomy module and wish to provide additional filtering options for your vocabularies you will have to review these options and rebuild your Sphinx indexes.') .'</div>',
182 );
183 }
184
185 $form['search'] = array(
186 '#type' => 'fieldset',
187 '#title' => t('Search page settings'),
188 '#collapsible' => FALSE,
189 '#description' => t('Use these options to customize the behaviour of your search page.'),
190 );
191 $form['search']['results'] = array(
192 '#type' => 'fieldset',
193 '#collapsible' => FALSE,
194 );
195 $search_path_description = t('Use this option to setup the path for the main search page.');
196 if (module_exists('search')) {
197 $search_path_description .= ' '. t("Note that Drupal search module is installed. You cannot take over the 'search' path.");
198 }
199 else {
200 $search_path_description .= ' '. t("Note that Drupal search module is not installed. You can take over the 'search' path.");
201 }
202 $form['search']['results']['sphinxsearch_search_path'] = array(
203 '#type' => 'textfield',
204 '#title' => t('Search path'),
205 '#default_value' => variable_get('sphinxsearch_search_path', 'search-content'),
206 '#description' => $search_path_description,
207 '#required' => TRUE,
208 );
209 $form['search']['results']['sphinxsearch_results_per_page'] = array(
210 '#type' => 'select',
211 '#title' => t('Results per page'),
212 '#default_value' => variable_get('sphinxsearch_results_per_page', 10),
213 '#options' => drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100)),
214 '#description' => t('How many items will be shown on search results page.'),
215 );
216 $form['search']['results']['sphinxsearch_log_search_keys'] = array(
217 '#type' => 'radios',
218 '#title' => t('Log search keys'),
219 '#default_value' => variable_get('sphinxsearch_log_search_keys', 'always'),
220 '#options' => array(
221 'always' => t('Always'),
222 'keys-only' => t('Only when keywords have been specified'),
223 'never' => t('Never'),
224 ),
225 '#description' => t('Information about search requests can be logged to watchdog for later review. Use this option to disable this feature or to only enable logging for requests where search keywords have been specified. Note that you can also setup Sphinx to log all search queries (see parameter <code>query_log</code> in your sphinx.conf), in which case you may wish to disable this feature here.'),
226 );
227 $form['search']['flood'] = array(
228 '#type' => 'fieldset',
229 '#title' => t('Flood control settings'),
230 '#collapsible' => TRUE, '#collapsed' => TRUE,
231 '#description' => t('Use these options to set the maximum number of search queries a user can perform per hour. Users with %admin permission are not affected by these restrictions.', array('%admin' => t('administer sphinxsearch'))),
232 );
233 $user_roles = array(DRUPAL_ANONYMOUS_RID => t('anonymous user'), DRUPAL_AUTHENTICATED_RID => t('authenticated user'));
234 foreach ($user_roles as $rid => $role) {
235 $form['search']['flood']['sphinxsearch_search_flood_per_role_'. $rid] = array(
236 '#type' => 'select',
237 '#title' => t('Hourly threshold per %role', array('%role' => $role)),
238 '#options' => (
239 array(0 => t('Unlimited')) +
240 drupal_map_assoc(array(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 350, 400, 450, 500))
241 ),
242 '#default_value' => variable_get('sphinxsearch_search_flood_per_role_'. $rid, 0),
243 );
244 }
245 $form['search']['excerpts'] = array(
246 '#type' => 'fieldset',
247 '#title' => t('Excerpts builder settings'),
248 '#collapsible' => TRUE, '#collapsed' => TRUE,
249 '#description' => t('Use these options to customize how to build excerpts for search results.'),
250 );
251 $form['search']['excerpts']['sphinxsearch_excerpts_limit'] = array(
252 '#type' => 'select',
253 '#title' => t('Excerpts size limit'),
254 '#default_value' => variable_get('sphinxsearch_excerpts_limit', 256),
255 '#options' => drupal_map_assoc(array(128, 192, 256, 320, 384, 448, 512, 640, 768, 896, 1024)),
256 '#description' => t('Maximum snippet size (in Sphinx symbols) used to build content excerpts for search results.'),
257 );
258 $form['search']['excerpts']['sphinxsearch_excerpts_around'] = array(
259 '#type' => 'select',
260 '#title' => t('Words around matches'),
261 '#default_value' => variable_get('sphinxsearch_excerpts_around', 5),
262 '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
263 '#description' => t('How much words to pick around each matching keywords block when building excerpts. Note that the actual number of words around matches also depends on Sphinx index configuration options such as <code>min_word_len</code>, <code>charset_table</code>, etc.'),
264 );
265 $form['search']['excerpts']['sphinxsearch_excerpts_single_passage'] = array(
266 '#type' => 'radios',
267 '#title' => t('Single passage'),
268 '#default_value' => variable_get('sphinxsearch_excerpts_single_passage', 0),
269 '#options' => array(1 => t('Enabled'), 0 => t('Disabled')),
270 '#description' => t('Whether to extract single best passage only. When this option is enabled, <em>Words around matches</em> setting is ignored and excerpts are build with a single passage up to <em>Excerpts size limit</em> long.'),
271 );
272 if (module_exists('taxonomy') && !module_exists('tagadelic')) {
273 $form['search']['tagadelic'] = array(
274 '#type' => 'fieldset',
275 '#title' => t('Tagadelic settings'),
276 '#collapsible' => TRUE, '#collapsed' => TRUE,
277 '#description' => t('Use these options to customize the behaviour of <a href="@tagadelic">tagadelic pages</a>.', array('@tagadelic' => url('tagadelic'))),
278 );
279 $form['search']['tagadelic']['sphinxsearch_page_tagadelic_sortmode'] = array(
280 '#type' => 'radios',
281 '#title' => t('Tagadelic sort order'),
282 '#options' => array(
283 'weight,asc' => t('by weight, ascending'),
284 'weight,desc' => t('by weight, descending'),
285 'title,asc' => t('by title, ascending'),
286 'title,desc' => t('by title, descending'),
287 'random,none' => t('random')
288 ),
289 '#default_value' => variable_get('sphinxsearch_page_tagadelic_sortmode', 'title,asc'),
290 '#description' => t('Determines the sort order of the tags in the cloud.'),
291 );
292 $form['search']['tagadelic']['sphinxsearch_page_tagadelic_tags'] = array(
293 '#type' => 'select',
294 '#title' => t('Tags to show'),
295 '#options' => drupal_map_assoc(array(40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300)),
296 '#default_value' => variable_get('sphinxsearch_page_tagadelic_tags', 100),
297 '#description' => t('The number of tags to show in this block.'),
298 );
299 $form['search']['tagadelic']['sphinxsearch_page_tagadelic_levels'] = array(
300 '#type' => 'select',
301 '#title' => t('Number of levels'),
302 '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)),
303 '#default_value' => variable_get('sphinxsearch_page_tagadelic_levels', 10),
304 '#description' => t('The number of levels between the least popular tags and the most popular ones. Different levels will be assigned a different class to be themed (see <code>sphinxsearch.css</code>).'),
305 );
306 $form['search']['tagadelic']['sphinxsearch_page_tagadelic_linkto'] = array(
307 '#type' => 'radios',
308 '#title' => t('Terms in the cloud link to'),
309 '#options' => array(
310 'taxonomy' => t('Taxonomy managed links.'),
311 'search' => t('Start search with predefined filters.'),
312 ),
313 '#default_value' => variable_get('sphinxsearch_page_tagadelic_linkto', 'taxonomy'),
314 '#description' => t('Determines where the links of terms in the tag cloud should point to.'),
315 );
316 }
317 return system_settings_form($form);
318 }
319
320 /**
321 * Validate module settings form.
322 */
323 function sphinxsearch_settings_validate($form, &$form_state) {
324 if (!is_numeric($form_state['values']['sphinxsearch_searchd_port']) || (int)$form_state['values']['sphinxsearch_searchd_port'] < 0) {
325 form_set_error('sphinxsearch_searchd_port', t('Sphinx port must be a numeric positive value.'));
326 }
327 if (strpos($form_state['values']['sphinxsearch_search_path'], ' ') !== FALSE) {
328 form_set_error('sphinxsearch_search_path', t('Search path cannot contain whitespaces.'));
329 }
330 else if ($form_state['values']['sphinxsearch_search_path'] == 'search' && module_exists('search')) {
331 form_set_error('sphinxsearch_search_path', t("You should first uninstall the Drupal search module to be able to take over the <code>'search'</code> path."));
332 }
333 }
334
335 /**
336 * Submit handler for module settings form.
337 */
338 function sphinxsearch_settings_submit($form, &$form_state) {
339 // Rebuild menus when search page path has been changed.
340 if ($form_state['values']['sphinxsearch_search_path'] != variable_get('sphinxsearch_search_path', 'search-content')) {
341 menu_rebuild();
342 }
343 }
344
345 /**
346 * Menu callback; Diagnose Sphinx searchd daemon connection.
347 */
348 function sphinxsearch_check_connection_page() {
349 $steps = array();
350
351 $sphinxsearch = &sphinxsearch_get_client();
352 $sphinxsearch_query_index = variable_get('sphinxsearch_query_index', '');
353 $sphinxsearch_excerpts_index = variable_get('sphinxsearch_excerpts_index', '');
354
355 // Check connection.
356 $steps['connection'] = array(
357 'title' => t('Testing Sphinx searchd daemon connection.'),
358 'messages' => array(),
359 );
360 if (sphinxsearch_check_connection()) {
361 $steps['connection']['messages'][] = t('OK') .' - '. t('Your Sphinx searchd daemon is up and running.');
362 }
363 else {
364 $steps['connection']['messages'][] = t('ERROR') .' - '. t('Unable to connect to your Sphinx searchd daemon.') . theme('item_list', array(
365 t('searchd host: %host', array('%host' => variable_get('sphinxsearch_searchd_host', 'localhost'))),
366 t('searchd port: %port', array('%port' => (int)variable_get('sphinxsearch_searchd_port', '3312'))),
367 t('Sphinx message: %message', array('%message' => $sphinxsearch->GetLastError())),
368 ));
369 }
370
371 // Check distributed index.
372 $steps['query'] = array(
373 'title' => t('Testing search query using index %index.', array('%index' => $sphinxsearch_query_index)),
374 'messages' => array(
375 t('Query asks for a list of all indexed documents to retrieve the last indexed node.'),
376 t('MySQL equivalent would look something like:<br /><code>SELECT nid FROM {node} ORDER BY nid DESC LIMIT 1;</code>'),
377 ),
378 );
379 if (empty($sphinxsearch_query_index)) {
380 $steps['query']['messages'][] = t('ERROR') .' - '. t('Sphinx query index not specified. Please, check module settings to match your Sphinx server configuration.');
381 }
382 else {
383 $sphinxsearch->SetLimits(0, 1);
384 $sphinxsearch->SetSortMode(SPH_SORT_EXTENDED, 'nid DESC');
385 $sphinxsearch->SetFilter('is_deleted', array(0));
386 $sphinx_results = $sphinxsearch->Query('', $sphinxsearch_query_index);
387 if (!$sphinx_results) {
388 $steps['query']['messages'][] = t('ERROR') .' - '. t('Search query failed.') . theme('item_list', array(
389 t('Sphinx message: %message', array('%message' => $sphinxsearch->GetLastError())),
390 ));
391 }
392 else {
393 if (!empty($sphinx_results['matches'])) {
394 $sphinx_match = array_shift($sphinx_results['matches']);
395 $nid = $sphinx_match['attrs']['nid'];
396 $updated = '('. format_date($sphinx_match['attrs']['last_updated'], 'custom', 'Y-m-d H:i:s') .')';
397 }
398 else {
399 $nid = t('N/A - Oops! It apears that your Sphinx indexes are empty.');
400 $updated = '';
401 }
402 $steps['query']['messages'][] = t('OK') .' - '. t('Test passed successfully. Sphinx results summary follow:') . theme('item_list', array(
403 t('Query execution time: @time seconds', array('@time' => $sphinx_results['time'])),
404 t('Total results found: @total', array('@total' => $sphinx_results['total_found'])),
405 t('Total results available: @total', array('@total' => $sphinx_results['total'])),
406 t('Last indexed node: @nid @updated', array('@nid' => $nid, '@updated' => $updated)),
407 ));
408 }
409 $warning = $sphinxsearch->GetLastWarning();
410 if (!empty($warning)) {
411 $steps['query']['messages'][] = t('WARNING') .' - '. t('There was a problem while trying to resolve the query.') . theme('item_list', array(
412 t('Sphinx message: %message', array('%message' => $warning)),
413 ));
414 }
415 }
416
417 // Check excerpts index.
418 $steps['excerpts'] = array(
419 'title' => t('Testing excerpts builder using index %index.', array('%index' => $sphinxsearch_excerpts_index)),
420 'messages' => array(),
421 );
422 if (empty($sphinxsearch_excerpts_index)) {
423 $steps['excerpts']['messages'][] = t('ERROR') .' - '. t('Sphinx excerpts index not specified. Please, check module settings to match your Sphinx server configuration.');
424 }
425 else {
426 $excerpt_samples = array(t('The quick brown fox jumps over a lazy dog.'));
427 $excerpt_keywords = t('brown lazy');
428 $excerpt_results = $sphinxsearch->BuildExcerpts($excerpt_samples, $sphinxsearch_excerpts_index, $excerpt_keywords);
429 if (!$excerpt_results) {
430 $steps['excerpts']['messages'][] = t('ERROR') .' - '. t('Unable to build excerpts.') . theme('item_list', array(
431 t('Sphinx message: %message', array('%message' => $sphinxsearch->GetLastError())),
432 ));
433 }
434 else {
435 $steps['excerpts']['messages'][] = t('OK') .' - '. t('Test passed successfully. Sphinx results summary follow:') . theme('item_list', array(
436 t('Sample text: <code>@sample</code>', array('@sample' => $excerpt_samples[0])),
437 t('Keywords: <code>@keywords</code>', array('@keywords' => $excerpt_keywords)),
438 t('Result: <code>@result</code>', array('@result' => $excerpt_results[0])),
439 ));
440 }
441 }
442
443 // Format HTML report.
444 $items = array();
445 foreach ($steps as $step) {
446 $items[] = theme('item_list', $step['messages'], $step['title']);
447 }
448
449 return theme('item_list', $items);
450 }

  ViewVC Help
Powered by ViewVC 1.1.2