Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
benchmark_search.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Retrieve and store file in Vault
9  *
10  * @author Anakeen 2010
11  * @version $Id: $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  */
15 /**
16  */
17 include_once ('WHAT/Lib.Common.php');
18 include_once ('FDL/freedom_util.php');
19 include_once ('FDL/Class.SearchDoc.php');
20 
21 ini_set('memory_limit', '1G');
22 
23 $dbaccess_freedom = $action->getParam('FREEDOM_DB');
24 if ($dbaccess_freedom == "") {
25  error_log(__FILE__ . " " . sprintf("Error: empty FREEDOM_DB"));
26  exit(1);
27 }
28 
29 $dbaccess_core = $action->getParam('CORE_DB');
30 if ($dbaccess_core == "") {
31  error_log(__FILE__ . " " . sprintf("Error: empty CORE_DB"));
32  exit(1);
33 }
34 
36 $default_word = 'test';
39 
40 $parms = array();
41 $parms['famid'] = getHttpVars('famid', $default_famid);
42 if (!is_numeric($parms['famid'])) {
44  if ($id === 0) {
45  error_log(__FILE__ . " " . sprintf("Error: unknown family with name '%s'", $parms['famid']));
46  exit(1);
47  }
48 }
49 
50 $parms['word'] = getHttpVars('word', $default_word);
51 if ($parms['word'] == "") {
52  $parms['word'] = $default_word;
53 }
54 
55 $parms['limit'] = getHttpVars('limit', $default_limit);
56 if (!is_numeric($parms['limit']) || $parms['limit'] <= 0) {
57  error_log(__FILE__ . " " . sprintf("Error: limit should be numeric and >= 1"));
58  exit(1);
59 }
60 
61 $parms['resetcperm'] = getHttpVars('resetcperm', 'no');
62 if ($parms['resetcperm'] != 'yes' && $parms['resetcperm'] != 'no') {
63  error_log(__FILE__ . " " . sprintf("Error: resetcperm '%s' should be 'yes' or 'no'", $parms['resetcperm']));
64  exit(1);
65 }
66 
67 if ($parms['resetcperm'] == 'yes') {
68  $ret = resetcperm();
69  if ($ret === false) {
70  error_log(__FILE__ . " " . sprintf("Error resetting docperm.\n"));
71  exit(1);
72  }
73 }
74 
75 $stat = array();
77 if ($ret === false) {
78  exit(1);
79 }
80 
82 
83 exit(0);
84 
85 function resetcperm()
86 {
87  global $dbaccess_core;
88  global $dbaccess_freedom;
89  global $action;
90  global $parms;
91 
92  $delete = "";
93  $delete.= "delete from docperm where upacl=0 and unacl=0;";
94  $delete.= "update docperm set cacl=0 where cacl != 0;";
95 
96  $vacuum = "vacuum full docperm;";
97 
98  $q = pg_query(getDbId($dbaccess_freedom) , $delete);
99  if ($q === false) {
100  return false;
101  }
102 
103  $q = pg_query(getDbId($dbaccess_freedom) , $vacuum);
104  if ($q === false) {
105  return false;
106  }
107 
108  return true;
109 }
110 
111 function print_stat(&$stat)
112 {
119 }
120 /**
121  * Print Search stat
122  */
123 
125 {
126  $table = array(
127  'lineformat' => " %32s | %6s | %6s | %7s | %8s | %8s | %8s | %8s\n"
128  );
129 
130  echo "\n\n\n=== Search ===\n\n\n";
131 
132  echo sprintf($table['lineformat'], "Name", "Id", "Count", "Profile", "^O", "O(title)", "O(cdate)", "O(id)");
133  echo sprintf($table['lineformat'], "---", "---", "---", "---", "---", "---", "---", "---");
134 
135  foreach ($stat['search'] as $fam) {
137  }
138 }
139 
140 function print_stat_search_fam(&$stat, &$fam, &$table)
141 {
142  echo sprintf($table['lineformat'],
143  // sprintf("%s%s", $fam['name'], (strlen($fam['inherit'])==0)?'':sprintf(" (%s)", $fam['inherit'])),
144  sprintf("%s%s", $fam['name'], (strlen($fam['inherit']) == 0) ? '' : ' *') , $fam['id'], $stat['search'][$fam['id']]['count'], $stat['search'][$fam['id']]['profile'], $stat['search'][$fam['id']]['no_order']['time'], $stat['search'][$fam['id']]['order_by_title']['time'], $stat['search'][$fam['id']]['order_by_cdate']['time'], $stat['search'][$fam['id']]['order_by_id']['time']);
145 
146  if ($fam['fromid'] != 0) {
147  echo sprintf($table['lineformat'], $fam['name'] . " <>", $fam['id'], $stat['search'][$fam['id']]['only']['count'], $stat['search'][$fam['id']]['profile'], $stat['search'][$fam['id']]['only']['no_order']['time'], $stat['search'][$fam['id']]['only']['order_by_title']['time'], $stat['search'][$fam['id']]['only']['order_by_cdate']['time'], $stat['search'][$fam['id']]['only']['order_by_id']['time']);
148  }
149 }
150 
152 {
153  $table = array(
154  'lineformat' => " %32s | %6s | %6s | %7s | %8s | %8s | %8s | %8s\n"
155  );
156 
157  echo "\n\n\n=== Search DISTINCT ===\n\n\n";
158 
159  echo sprintf($table['lineformat'], "Name", "Id", "Count", "Profile", "^O", "O(title)", "O(cdate)", "O(id)");
160  echo sprintf($table['lineformat'], "---", "---", "---", "---", "---", "---", "---", "---");
161 
162  foreach ($stat['search'] as $fam) {
164  }
165 }
166 
168 {
169  echo sprintf($table['lineformat'],
170  // sprintf("%s%s", $fam['name'], (strlen($fam['inherit'])==0)?'':sprintf(" (%s)", $fam['inherit'])),
171  sprintf("%s%s", $fam['name'], (strlen($fam['inherit']) == 0) ? '' : ' *') , $fam['id'], $stat['search'][$fam['id']]['count'], $stat['search'][$fam['id']]['profile'], $stat['search'][$fam['id']]['no_order']['distinct']['time'], $stat['search'][$fam['id']]['order_by_title']['distinct']['time'], $stat['search'][$fam['id']]['order_by_cdate']['distinct']['time'], $stat['search'][$fam['id']]['order_by_id']['distinct']['time']);
172 
173  if ($fam['fromid'] != 0) {
174  echo sprintf($table['lineformat'], $fam['name'] . " <>", $fam['id'], $stat['search'][$fam['id']]['only']['count'], $stat['search'][$fam['id']]['profile'], $stat['search'][$fam['id']]['only']['no_order']['distinct']['time'], $stat['search'][$fam['id']]['only']['order_by_title']['distinct']['time'], $stat['search'][$fam['id']]['only']['order_by_cdate']['distinct']['time'], $stat['search'][$fam['id']]['only']['order_by_id']['distinct']['time']);
175  }
176 }
177 /**
178  * Print Regex stat
179  */
180 
182 {
183  $table = array(
184  'lineformat' => " %32s | %6s | %6s | %7s | %8s | %8s | %8s | %8s\n"
185  );
186 
187  echo "\n\n\n=== Regex ===\n\n\n";
188 
189  echo sprintf($table['lineformat'], "Name", "Id", "Count", "Profile", "^O", "O(title)", "O(cdate)", "O(id)");
190  echo sprintf($table['lineformat'], "---", "---", "---", "---", "---", "---", "---", "---");
191 
192  foreach ($stat['search'] as $fam) {
194  }
195 }
196 
197 function print_stat_regex_fam(&$stat, &$fam, &$table)
198 {
199  echo sprintf($table['lineformat'],
200  // sprintf("%s%s", $fam['name'], (strlen($fam['inherit'])==0)?'':sprintf(" (%s)", $fam['inherit'])),
201  sprintf("%s%s", $fam['name'], (strlen($fam['inherit']) == 0) ? '' : ' *') , $fam['id'], $stat['search'][$fam['id']]['count'], $stat['search'][$fam['id']]['profile'], $stat['regex'][$fam['id']]['no_order']['time'], $stat['regex'][$fam['id']]['order_by_title']['time'], $stat['regex'][$fam['id']]['order_by_cdate']['time'], $stat['regex'][$fam['id']]['order_by_id']['time']);
202 }
203 
205 {
206  $table = array(
207  'lineformat' => " %32s | %6s | %6s | %7s | %8s | %8s | %8s | %8s\n"
208  );
209 
210  echo "\n\n\n=== Regex DISTINCT ===\n\n\n";
211 
212  echo sprintf($table['lineformat'], "Name", "Id", "Count", "Profile", "^O", "O(title)", "O(cdate)", "O(id)");
213  echo sprintf($table['lineformat'], "---", "---", "---", "---", "---", "---", "---", "---");
214 
215  foreach ($stat['search'] as $fam) {
217  }
218 }
219 
221 {
222  echo sprintf($table['lineformat'],
223  // sprintf("%s%s", $fam['name'], (strlen($fam['inherit'])==0)?'':sprintf(" (%s)", $fam['inherit'])),
224  sprintf("%s%s", $fam['name'], (strlen($fam['inherit']) == 0) ? '' : ' *') , $fam['id'], $stat['search'][$fam['id']]['count'], $stat['search'][$fam['id']]['profile'], $stat['regex'][$fam['id']]['no_order']['distinct']['time'], $stat['regex'][$fam['id']]['order_by_title']['distinct']['time'], $stat['regex'][$fam['id']]['order_by_cdate']['distinct']['time'], $stat['regex'][$fam['id']]['order_by_id']['distinct']['time']);
225 }
226 /**
227  * Print fulltext stat
228  */
229 
231 {
232  $table = array(
233  'lineformat' => " %32s | %6s | %6s | %7s | %8s | %8s | %8s | %8s | %8s\n"
234  );
235 
236  echo "\n\n\n=== Fulltext ===\n\n\n";
237 
238  echo sprintf($table['lineformat'], "Name", "Id", "Count", "Profile", "^O", "O(title)", "O(cdate)", "O(id)", "O(rank)");
239  echo sprintf($table['lineformat'], "---", "---", "---", "---", "---", "---", "---", "---", "---");
240 
241  foreach ($stat['search'] as $fam) {
243  }
244 }
245 
247 {
248  echo sprintf($table['lineformat'],
249  // sprintf("%s%s", $fam['name'], (strlen($fam['inherit'])==0)?'':sprintf(" (%s)", $fam['inherit'])),
250  sprintf("%s%s", $fam['name'], (strlen($fam['inherit']) == 0) ? '' : ' *') , $fam['id'], $stat['search'][$fam['id']]['count'], $stat['search'][$fam['id']]['profile'], $stat['fulltext'][$fam['id']]['no_order']['time'], $stat['fulltext'][$fam['id']]['order_by_title']['time'], $stat['fulltext'][$fam['id']]['order_by_cdate']['time'], $stat['fulltext'][$fam['id']]['order_by_id']['time'], $stat['fulltext'][$fam['id']]['order_by_rank']['time']);
251 }
252 
254 {
255  $table = array(
256  'lineformat' => " %32s | %6s | %6s | %7s | %8s | %8s | %8s | %8s | %8s\n"
257  );
258 
259  echo "\n\n\n=== Fulltext DISTINCT ===\n\n\n";
260 
261  echo sprintf($table['lineformat'], "Name", "Id", "Count", "Profile", "^O", "O(title)", "O(cdate)", "O(id)", "O(rank)");
262  echo sprintf($table['lineformat'], "---", "---", "---", "---", "---", "---", "---", "---", "---");
263 
264  foreach ($stat['search'] as $fam) {
266  }
267 }
268 
270 {
271  echo sprintf($table['lineformat'],
272  // sprintf("%s%s", $fam['name'], (strlen($fam['inherit'])==0)?'':sprintf(" (%s)", $fam['inherit'])),
273  sprintf("%s%s", $fam['name'], (strlen($fam['inherit']) == 0) ? '' : ' *') , $fam['id'], $stat['search'][$fam['id']]['count'], $stat['search'][$fam['id']]['profile'], $stat['fulltext'][$fam['id']]['no_order']['distinct']['time'], $stat['fulltext'][$fam['id']]['order_by_title']['distinct']['time'], $stat['fulltext'][$fam['id']]['order_by_cdate']['distinct']['time'], $stat['fulltext'][$fam['id']]['order_by_id']['distinct']['time'], $stat['fulltext'][$fam['id']]['order_by_rank']['distinct']['time']);
274 }
275 /**
276  * Bench functions
277  */
278 
279 function bench(&$stat)
280 {
281  bench_info($stat);
283 }
284 
286 {
287  global $dbaccess_freedom;
288  global $action;
289  global $parms;
290 
291  $stat['search'] = array();
292 
293  $s = new SearchDoc($dbaccess_freedom, -1);
294  $s->setObjectReturn();
295  $s->noViewControl();
296  $s->addFilter("usefor != 'W'");
297  $s->addFilter("usefor != 'S'");
298  $s->search();
299 
300  $famList = array();
301  while ($fam = $s->nextDoc()) {
302  $fam->childs = array();
303  $childFam = $fam->getChildFam($fam->id, false);
304  $inherit = join(',', array_map(create_function('$v', 'global $dbaccess_freedom; return getNameFromId($dbaccess_freedom, $v);') , array_keys($childFam)));
305  array_push($famList, array(
306  'id' => $fam->id,
307  'name' => $fam->name,
308  'fromid' => $fam->fromid,
309  'profid' => $fam->profid,
310  'dprofid' => $fam->dprofid,
311  'cprofid' => $fam->cprofid,
312  'inherit' => $inherit
313  ));
314 
315  if ($inherit != '') {
316  echo sprintf("Childs of '%s' = [%s]\n", $fam->name, $inherit);
317  }
318  }
319  /*
320  $famList = array();
321  $q = pg_query(getDbId($dbaccess_freedom), "SELECT id, name, title, fromid, profid, dprofid, cprofid FROM docfam WHERE usefor != 'W' AND usefor != 'S' ORDER BY id");
322  if( $q === false ) {
323  error_log(__FILE__." ".sprintf("Error: docfam id list query failed"));
324  return false;
325  }
326  $famList = pg_fetch_all($q);
327  */
328 
329  array_push($famList, array(
330  'id' => 0,
331  'name' => 'global',
332  'fromid' => 0,
333  'profid' => 'N/A',
334  'dprofid' => 'N/A',
335  'cprofid' => 'N/A'
336  ));
337  /*
338  $fam_inherit = array();
339  foreach( $famList as $fam ) {
340  $fam_inherit[$fam['id']] = $fam['fromid'];
341  }
342 
343  $inheritance = array();
344  for( $idx_famList = 0; $idx_famList < count($famList); $idx_famList++ ) {
345  $fam = $famList[$idx_famList];
346  // echo sprintf("Processing family %s\n", $fam['id']);
347  $inheritance[$fam['id']] = array();
348  if( $fam['fromid'] != 0 ) {
349  // echo sprintf(" Found a parent family %s\n", $fam['fromid']);
350  array_push($inheritance[$fam['id']], $fam['fromid']);
351  for( $i = 0; $i < count($inheritance[$fam['id']]); $i++ ) {
352  $parent_id = $fam_inherit[ $inheritance[$fam['id']][$i] ];
353  // echo sprintf(" Parent of %s is %s\n", $inheritance[$fam['id']][$i], $parent_id);
354  if( $parent_id != 0 ) {
355  // echo sprintf(" Adding %s\n", $parent_id);
356  array_push($inheritance[$fam['id']], $parent_id);
357  }
358  }
359  $famList[$idx_famList]['inherit'] = join(':', $inheritance[$fam['id']]);
360  // echo sprintf("Inheritance of %s is %s\n", $fam['id'], $fam['inherit']);
361  } else {
362  $famList[$idx_famList]['inherit'] = '';
363  }
364  }
365  // var_dump($famList);
366  */
367 
368  echo sprintf("Found %s families to process.\n", count($famList));
369 
370  foreach ($famList as $fam) {
371  bench_search_fam($stat, $fam);
372  }
373 }
374 
375 function bench_search_fam(&$stat, &$fam)
376 {
377  global $dbaccess_freedom;
378  global $action;
379  global $parms;
380 
381  if (!array_key_exists('search', $stat)) {
382  return false;
383  }
384 
385  $stat['search'][$fam['id']] = array();
386  // id
387  $stat['search'][$fam['id']]['id'] = $fam['id'];
388  // name
389  $stat['search'][$fam['id']]['name'] = $fam['name'];
390  // fromid
391  $stat['search'][$fam['id']]['fromid'] = $fam['fromid'];
392  // doc count
393  $q = pg_query(getDbId($dbaccess_freedom) , sprintf("SELECT count(id) FROM doc%s", pg_escape_string(($fam['id'] == 0) ? '' : $fam['id'])));
394  if ($q === false) {
395  error_log(__FILE__ . " " . sprintf("Error: doc count on family '%s' (%s) failed.", $fam['name'], $fam['id']));
396  return false;
397  }
398  $d = pg_fetch_all($q);
399  $stat['search'][$fam['id']]['count'] = $d[0]['count'];
400  // inherit
401  $stat['search'][$fam['id']]['inherit'] = $fam['inherit'];
402  // profile
403  if ($fam['profid'] == 0) {
404  $stat['search'][$fam['id']]['profile'] = 'none';
405  } else if ($fam['profid'] == $fam['id']) {
406  $stat['search'][$fam['id']]['profile'] = 'dynamic';
407  } else {
408  $stat['search'][$fam['id']]['profile'] = 'static';
409  }
410  // search
415  // regex
420  // fulltext
426 }
427 /**
428  * Search
429  */
430 
432 {
433  global $dbaccess_freedom;
434  global $action;
435  global $parms;
436 
437  $stat['search'][$fam['id']]['no_order']['time'] = bench_searchdoc(array(
438  'fam' => $fam['id']
439  ));
440 
441  if ($fam['fromid'] != '0') {
442  $stat['search'][$fam['id']]['only']['no_order']['time'] = bench_searchdoc(array(
443  'fam' => - $fam['id']
444  ));
445  }
446 
447  $stat['search'][$fam['id']]['no_order']['distinct']['time'] = bench_searchdoc(array(
448  'fam' => $fam['id'],
449  'distinct' => true
450  ));
451 
452  if ($fam['fromid'] != '0') {
453  $stat['search'][$fam['id']]['only']['no_order']['distinct']['time'] = bench_searchdoc(array(
454  'fam' => - $fam['id'],
455  'distinct' => true
456  ));
457  }
458 }
459 
461 {
462  global $dbaccess_freedom;
463  global $action;
464  global $parms;
465 
466  $stat['search'][$fam['id']]['order_by_title']['time'] = bench_searchdoc(array(
467  'fam' => $fam['id'],
468  'orderby' => 'title'
469  ));
470 
471  if ($fam['fromid'] != '0') {
472  $stat['search'][$fam['id']]['only']['order_by_title']['time'] = bench_searchdoc(array(
473  'fam' => - $fam['id'],
474  'orderby' => 'title'
475  ));
476  }
477 
478  $stat['search'][$fam['id']]['order_by_title']['distinct']['time'] = bench_searchdoc(array(
479  'fam' => $fam['id'],
480  'orderby' => 'title',
481  'distinct' => true
482  ));
483 
484  if ($fam['fromid'] != '0') {
485  $stat['search'][$fam['id']]['only']['order_by_title']['distinct']['time'] = bench_searchdoc(array(
486  'fam' => - $fam['id'],
487  'orderby' => 'title',
488  'distinct' => true
489  ));
490  }
491 }
492 
494 {
495  global $dbaccess_freedom;
496  global $action;
497  global $parms;
498 
499  $stat['search'][$fam['id']]['order_by_cdate']['time'] = bench_searchdoc(array(
500  'fam' => $fam['id'],
501  'orderby' => 'cdate'
502  ));
503 
504  if ($fam['fromid'] != '0') {
505  $stat['search'][$fam['id']]['only']['order_by_cdate']['time'] = bench_searchdoc(array(
506  'fam' => - $fam['id'],
507  'orderby' => 'cdate'
508  ));
509  }
510 
511  $stat['search'][$fam['id']]['order_by_cdate']['distinct']['time'] = bench_searchdoc(array(
512  'fam' => $fam['id'],
513  'orderby' => 'cdate',
514  'distinct' => true
515  ));
516 
517  if ($fam['fromid'] != '0') {
518  $stat['search'][$fam['id']]['only']['order_by_cdate']['distinct']['time'] = bench_searchdoc(array(
519  'fam' => - $fam['id'],
520  'orderby' => 'cdate',
521  'distinct' => true
522  ));
523  }
524 }
525 
527 {
528  global $dbaccess_freedom;
529  global $action;
530  global $parms;
531 
532  $stat['search'][$fam['id']]['order_by_id']['time'] = bench_searchdoc(array(
533  'fam' => $fam['id'],
534  'orderby' => 'id'
535  ));
536 
537  if ($fam['fromid'] != '0') {
538  $stat['search'][$fam['id']]['only']['order_by_id']['time'] = bench_searchdoc(array(
539  'fam' => - $fam['id'],
540  'orderby' => 'id'
541  ));
542  }
543 
544  $stat['search'][$fam['id']]['order_by_id']['distinct']['time'] = bench_searchdoc(array(
545  'fam' => $fam['id'],
546  'orderby' => 'id',
547  'distinct' => true
548  ));
549 
550  if ($fam['fromid'] != '0') {
551  $stat['search'][$fam['id']]['only']['order_by_id']['distinct']['time'] = bench_searchdoc(array(
552  'fam' => - $fam['id'],
553  'orderby' => 'id',
554  'distinct' => true
555  ));
556  }
557 }
558 /**
559  * Regex
560  */
561 
563 {
564  global $dbaccess_freedom;
565  global $action;
566  global $parms;
567 
568  $stat['regex'][$fam['id']]['no_order']['time'] = bench_searchdoc(array(
569  'fam' => $fam['id'],
570  'filter' => sprintf("svalues ~* '%s'", pg_escape_string($parms['word']))
571  ));
572 
573  $stat['regex'][$fam['id']]['no_order']['distinct']['time'] = bench_searchdoc(array(
574  'fam' => $fam['id'],
575  'filter' => sprintf("svalues ~* '%s'", pg_escape_string($parms['word'])) ,
576  'distinct' => true
577  ));
578 }
579 
581 {
582  global $dbaccess_freedom;
583  global $action;
584  global $parms;
585 
586  $stat['regex'][$fam['id']]['order_by_title']['time'] = bench_searchdoc(array(
587  'fam' => $fam['id'],
588  'orderby' => 'title',
589  'filter' => sprintf("svalues ~* '%s'", pg_escape_string($parms['word']))
590  ));
591 
592  $stat['regex'][$fam['id']]['order_by_title']['distinct']['time'] = bench_searchdoc(array(
593  'fam' => $fam['id'],
594  'orderby' => 'title',
595  'filter' => sprintf("svalues ~* '%s'", pg_escape_string($parms['word'])) ,
596  'distinct' => true
597  ));
598 }
599 
601 {
602  global $dbaccess_freedom;
603  global $action;
604  global $parms;
605 
606  $stat['regex'][$fam['id']]['order_by_cdate']['time'] = bench_searchdoc(array(
607  'fam' => $fam['id'],
608  'orderby' => 'cdate',
609  'filter' => sprintf("svalues ~* '%s'", pg_escape_string($parms['word']))
610  ));
611 
612  $stat['regex'][$fam['id']]['order_by_cdate']['distinct']['time'] = bench_searchdoc(array(
613  'fam' => $fam['id'],
614  'orderby' => 'cdate',
615  'filter' => sprintf("svalues ~* '%s'", pg_escape_string($parms['word'])) ,
616  'distinct' => true
617  ));
618 }
619 
621 {
622  global $dbaccess_freedom;
623  global $action;
624  global $parms;
625 
626  $stat['regex'][$fam['id']]['order_by_id']['time'] = bench_searchdoc(array(
627  'fam' => $fam['id'],
628  'orderby' => 'id',
629  'filter' => sprintf("svalues ~* '%s'", pg_escape_string($parms['word']))
630  ));
631 
632  $stat['regex'][$fam['id']]['order_by_id']['distinct']['time'] = bench_searchdoc(array(
633  'fam' => $fam['id'],
634  'orderby' => 'id',
635  'filter' => sprintf("svalues ~* '%s'", pg_escape_string($parms['word'])) ,
636  'distinct' => true
637  ));
638 }
639 /**
640  * Fulltext
641  */
642 
644 {
645  global $dbaccess_freedom;
646  global $action;
647  global $parms;
648 
649  include_once ('FDL/Class.DocSearch.php');
650 
651  $ret_sqlfilter = array();
652  $ret_orderby = '';
653  $ret_keys = '';
654  DocSearch::getFullSqlFilters($parm['word'], $ret_filter, $ret_orderby, $ret_keys);
655 
656  $stat['fulltext'][$fam['id']]['no_order']['time'] = bench_searchdoc(array(
657  'fam' => $fam['id'],
658  'filter' => $ret_filter
659  ));
660 
661  $stat['fulltext'][$fam['id']]['no_order']['distinct']['time'] = bench_searchdoc(array(
662  'fam' => $fam['id'],
663  'filter' => $ret_filter,
664  'distinct' => true
665  ));
666 }
667 
669 {
670  global $dbaccess_freedom;
671  global $action;
672  global $parms;
673 
674  include_once ('FDL/Class.DocSearch.php');
675 
676  $ret_sqlfilter = array();
677  $ret_orderby = '';
678  $ret_keys = '';
679  DocSearch::getFullSqlFilters($parm['word'], $ret_filter, $ret_orderby, $ret_keys);
680 
681  $stat['fulltext'][$fam['id']]['order_by_title']['time'] = bench_searchdoc(array(
682  'fam' => $fam['id'],
683  'filter' => $ret_filter,
684  'orderby' => 'title'
685  ));
686 
687  $stat['fulltext'][$fam['id']]['order_by_title']['distinct']['time'] = bench_searchdoc(array(
688  'fam' => $fam['id'],
689  'filter' => $ret_filter,
690  'orderby' => 'title',
691  'distinct' => true
692  ));
693 }
694 
696 {
697  global $dbaccess_freedom;
698  global $action;
699  global $parms;
700 
701  include_once ('FDL/Class.DocSearch.php');
702 
703  $ret_sqlfilter = array();
704  $ret_orderby = '';
705  $ret_keys = '';
706  DocSearch::getFullSqlFilters($parm['word'], $ret_filter, $ret_orderby, $ret_keys);
707 
708  $stat['fulltext'][$fam['id']]['order_by_cdate']['time'] = bench_searchdoc(array(
709  'fam' => $fam['id'],
710  'filter' => $ret_filter,
711  'orderby' => 'cdate'
712  ));
713 
714  $stat['fulltext'][$fam['id']]['order_by_cdate']['distinct']['time'] = bench_searchdoc(array(
715  'fam' => $fam['id'],
716  'filter' => $ret_filter,
717  'orderby' => 'cdate',
718  'distinct' => true
719  ));
720 }
721 
723 {
724  global $dbaccess_freedom;
725  global $action;
726  global $parms;
727 
728  include_once ('FDL/Class.DocSearch.php');
729 
730  $ret_sqlfilter = array();
731  $ret_orderby = '';
732  $ret_keys = '';
733  DocSearch::getFullSqlFilters($parm['word'], $ret_filter, $ret_orderby, $ret_keys);
734 
735  $stat['fulltext'][$fam['id']]['order_by_id']['time'] = bench_searchdoc(array(
736  'fam' => $fam['id'],
737  'filter' => $ret_filter,
738  'orderby' => 'id'
739  ));
740 
741  $stat['fulltext'][$fam['id']]['order_by_id']['distinct']['time'] = bench_searchdoc(array(
742  'fam' => $fam['id'],
743  'filter' => $ret_filter,
744  'orderby' => 'id',
745  'distinct' => true
746  ));
747 }
748 
750 {
751  global $dbaccess_freedom;
752  global $action;
753  global $parms;
754 
755  include_once ('FDL/Class.DocSearch.php');
756 
757  $ret_sqlfilter = array();
758  $ret_orderby = '';
759  $ret_keys = '';
760  DocSearch::getFullSqlFilters($parm['word'], $ret_filter, $ret_orderby, $ret_keys);
761 
762  $stat['fulltext'][$fam['id']]['order_by_rank']['time'] = bench_searchdoc(array(
763  'fam' => $fam['id'],
764  'filter' => $ret_filter,
765  'orderby' => $ret_orderby
766  ));
767 
768  $stat['fulltext'][$fam['id']]['order_by_rank']['distinct']['time'] = bench_searchdoc(array(
769  'fam' => $fam['id'],
770  'filter' => $ret_filter,
771  'orderby' => $ret_orderby,
772  'distinct' => true
773  ));
774 }
775 /**
776  * Generic bench_searchdoc()
777  */
778 
779 function bench_searchdoc($opt)
780 {
781  global $dbaccess_freedom;
782  global $parms;
783 
784  if (!array_key_exists('dbaccess', $opt)) {
785  $opt['dbaccess'] = $dbaccess_freedom;
786  }
787 
788  $s = new SearchDoc($opt['dbaccess'], $opt['fam']);
789  $s->setDebugMode();
790  $s->setObjectReturn();
791 
792  $s->orderby = '';
793  if (array_key_exists('orderby', $opt)) {
794  $s->orderby = $opt['oderby'];
795  }
796 
797  $s->slice = $parms['limit'];
798  if (array_key_exists('limit', $opt)) {
799  $s->slice = $opt['limit'];
800  }
801 
802  if (array_key_exists('distinct', $opt)) {
803  if ($opt['distinct'] === false || $opt['distinct'] === true) {
804  $s->distinct = $opt['distinct'];
805  }
806  }
807 
808  if (array_key_exists('filter', $opt)) {
809  if (is_array($opt['filter'])) {
810  foreach ($opt['filter'] as $filter) {
811  $s->addFilter($filter);
812  }
813  } else {
814  $s->addFilter($opt['filter']);
815  }
816  }
817 
818  $s->search();
819 
820  $debugInfo = $s->getDebugInfo();
821  return $debugInfo['delay'];
822 }
823 /**
824  * Bench info header
825  */
826 
827 function bench_info($stat)
828 {
829  global $dbaccess_freedom;
830  global $dbaccess_core;
831  global $action;
832  global $parms;
833 
834  $stat['login'] = $action->user->login;
835 
836  $stat['uid'] = $action->user->id;
837 
838  $q = pg_query(getDbId($dbaccess_freedom) , "SELECT count(id) AS count FROM doc");
839  if ($q === false) {
840  error_log(__FILE__ . " " . sprintf("Error: count doc query failed"));
841  return false;
842  }
843  $d = pg_fetch_all($q);
844  $stat['doc_count'] = $d[0]['count'];
845 
846  $q = pg_query(getDbId($dbaccess_freedom) , "SELECT count(*) AS count FROM docperm");
847  if ($q === false) {
848  error_log(__FILE__ . " " . sprintf("Error: count docperm query failed"));
849  return false;
850  }
851  $d = pg_fetch_all($q);
852  $stat['docperm_count'] = $d[0]['count'];
853 
854  $parent_groups = $action->user->getGroupsId();
855  $all_groups_list = array();
856  foreach ($parent_groups as $group) {
857  array_push($all_groups_list, $group);
858  }
859  $group_count = 0;
860  for ($i = 0; $i < count($all_groups_list); $i++) {
861  $gid = $all_groups_list[$i];
862  $group_count++;
863  $group = new User($dbaccess_core, $gid);
864  if (!is_object($group)) {
865  error_log(__FILE__ . " " . sprintf("Error: invalid group with id '%s'"));
866  return false;
867  }
868  $groups_list = $group->getGroupsId();
869  foreach ($groups_list as $g) {
870  if (!in_array($g, $all_groups_list)) {
871  array_push($all_groups_list, $g);
872  }
873  }
874  }
875  $stat['user_groups_count'] = $group_count++;
876 
877  echo sprintf("login (uid) = %s (%s)\n", $stat['login'], $stat['uid']);
878  echo sprintf("doc count = %s\n", $stat['doc_count']);
879  echo sprintf("docperm count = %s\n", $stat['docperm_count']);
880  echo sprintf("user groups count = %s\n", $stat['user_groups_count']);
881  echo sprintf("search word = %s\n", $parms['word']);
882  echo sprintf("limit = %s\n", $parms['limit']);
883 }
884 ?>
← centre documentaire © anakeen - published under CC License - Dynacase