17 include_once (
'WHAT/Lib.Common.php');
18 include_once (
'FDL/freedom_util.php');
19 include_once (
'FDL/Class.SearchDoc.php');
21 ini_set(
'memory_limit',
'1G');
25 error_log(__FILE__ .
" " . sprintf(
"Error: empty FREEDOM_DB"));
31 error_log(__FILE__ .
" " . sprintf(
"Error: empty CORE_DB"));
42 if (!is_numeric(
$parms[
'famid'])) {
45 error_log(__FILE__ .
" " . sprintf(
"Error: unknown family with name '%s'",
$parms[
'famid']));
51 if (
$parms[
'word'] ==
"") {
56 if (!is_numeric(
$parms[
'limit']) ||
$parms[
'limit'] <= 0) {
57 error_log(__FILE__ .
" " . sprintf(
"Error: limit should be numeric and >= 1"));
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']));
67 if (
$parms[
'resetcperm'] ==
'yes') {
70 error_log(__FILE__ .
" " . sprintf(
"Error resetting docperm.\n"));
93 $delete.=
"delete from docperm where upacl=0 and unacl=0;";
94 $delete.=
"update docperm set cacl=0 where cacl != 0;";
96 $vacuum =
"vacuum full docperm;";
98 $q = pg_query(getDbId($dbaccess_freedom) , $delete);
103 $q = pg_query(getDbId($dbaccess_freedom) , $vacuum);
127 'lineformat' =>
" %32s | %6s | %6s | %7s | %8s | %8s | %8s | %8s\n"
130 echo
"\n\n\n=== Search ===\n\n\n";
132 echo sprintf(
$table[
'lineformat'],
"Name",
"Id",
"Count",
"Profile",
"^O",
"O(title)",
"O(cdate)",
"O(id)");
133 echo sprintf(
$table[
'lineformat'],
"---",
"---",
"---",
"---",
"---",
"---",
"---",
"---");
135 foreach (
$stat[
'search'] as $fam) {
142 echo sprintf(
$table[
'lineformat'],
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']);
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']);
154 'lineformat' =>
" %32s | %6s | %6s | %7s | %8s | %8s | %8s | %8s\n"
157 echo
"\n\n\n=== Search DISTINCT ===\n\n\n";
159 echo sprintf(
$table[
'lineformat'],
"Name",
"Id",
"Count",
"Profile",
"^O",
"O(title)",
"O(cdate)",
"O(id)");
160 echo sprintf(
$table[
'lineformat'],
"---",
"---",
"---",
"---",
"---",
"---",
"---",
"---");
162 foreach (
$stat[
'search'] as $fam) {
169 echo sprintf(
$table[
'lineformat'],
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']);
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']);
184 'lineformat' =>
" %32s | %6s | %6s | %7s | %8s | %8s | %8s | %8s\n"
187 echo
"\n\n\n=== Regex ===\n\n\n";
189 echo sprintf(
$table[
'lineformat'],
"Name",
"Id",
"Count",
"Profile",
"^O",
"O(title)",
"O(cdate)",
"O(id)");
190 echo sprintf(
$table[
'lineformat'],
"---",
"---",
"---",
"---",
"---",
"---",
"---",
"---");
192 foreach (
$stat[
'search'] as $fam) {
199 echo sprintf(
$table[
'lineformat'],
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']);
207 'lineformat' =>
" %32s | %6s | %6s | %7s | %8s | %8s | %8s | %8s\n"
210 echo
"\n\n\n=== Regex DISTINCT ===\n\n\n";
212 echo sprintf(
$table[
'lineformat'],
"Name",
"Id",
"Count",
"Profile",
"^O",
"O(title)",
"O(cdate)",
"O(id)");
213 echo sprintf(
$table[
'lineformat'],
"---",
"---",
"---",
"---",
"---",
"---",
"---",
"---");
215 foreach (
$stat[
'search'] as $fam) {
222 echo sprintf(
$table[
'lineformat'],
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']);
233 'lineformat' =>
" %32s | %6s | %6s | %7s | %8s | %8s | %8s | %8s | %8s\n"
236 echo
"\n\n\n=== Fulltext ===\n\n\n";
238 echo sprintf(
$table[
'lineformat'],
"Name",
"Id",
"Count",
"Profile",
"^O",
"O(title)",
"O(cdate)",
"O(id)",
"O(rank)");
239 echo sprintf(
$table[
'lineformat'],
"---",
"---",
"---",
"---",
"---",
"---",
"---",
"---",
"---");
241 foreach (
$stat[
'search'] as $fam) {
248 echo sprintf(
$table[
'lineformat'],
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']);
256 'lineformat' =>
" %32s | %6s | %6s | %7s | %8s | %8s | %8s | %8s | %8s\n"
259 echo
"\n\n\n=== Fulltext DISTINCT ===\n\n\n";
261 echo sprintf(
$table[
'lineformat'],
"Name",
"Id",
"Count",
"Profile",
"^O",
"O(title)",
"O(cdate)",
"O(id)",
"O(rank)");
262 echo sprintf(
$table[
'lineformat'],
"---",
"---",
"---",
"---",
"---",
"---",
"---",
"---",
"---");
264 foreach (
$stat[
'search'] as $fam) {
271 echo sprintf(
$table[
'lineformat'],
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']);
291 $stat[
'search'] = array();
294 $s->setObjectReturn();
296 $s->addFilter(
"usefor != 'W'");
297 $s->addFilter(
"usefor != 'S'");
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(
307 'name' => $fam->name,
308 'fromid' => $fam->fromid,
309 'profid' => $fam->profid,
310 'dprofid' => $fam->dprofid,
311 'cprofid' => $fam->cprofid,
312 'inherit' => $inherit
315 if ($inherit !=
'') {
316 echo sprintf(
"Childs of '%s' = [%s]\n", $fam->name, $inherit);
329 array_push($famList, array(
368 echo sprintf(
"Found %s families to process.\n", count($famList));
370 foreach ($famList as $fam) {
381 if (!array_key_exists(
'search',
$stat)) {
385 $stat[
'search'][$fam[
'id']] = array();
387 $stat[
'search'][$fam[
'id']][
'id'] = $fam[
'id'];
389 $stat[
'search'][$fam[
'id']][
'name'] = $fam[
'name'];
391 $stat[
'search'][$fam[
'id']][
'fromid'] = $fam[
'fromid'];
393 $q = pg_query(getDbId($dbaccess_freedom) , sprintf(
"SELECT count(id) FROM doc%s", pg_escape_string(($fam[
'id'] == 0) ?
'' : $fam[
'id'])));
395 error_log(__FILE__ .
" " . sprintf(
"Error: doc count on family '%s' (%s) failed.", $fam[
'name'], $fam[
'id']));
398 $d = pg_fetch_all(
$q);
399 $stat[
'search'][$fam[
'id']][
'count'] =
$d[0][
'count'];
401 $stat[
'search'][$fam[
'id']][
'inherit'] = $fam[
'inherit'];
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';
408 $stat[
'search'][$fam[
'id']][
'profile'] =
'static';
441 if ($fam[
'fromid'] !=
'0') {
443 'fam' => - $fam[
'id']
452 if ($fam[
'fromid'] !=
'0') {
454 'fam' => - $fam[
'id'],
471 if ($fam[
'fromid'] !=
'0') {
473 'fam' => - $fam[
'id'],
480 'orderby' =>
'title',
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',
504 if ($fam[
'fromid'] !=
'0') {
506 'fam' => - $fam[
'id'],
513 'orderby' =>
'cdate',
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',
537 if ($fam[
'fromid'] !=
'0') {
539 'fam' => - $fam[
'id'],
550 if ($fam[
'fromid'] !=
'0') {
552 'fam' => - $fam[
'id'],
570 'filter' => sprintf(
"svalues ~* '%s'", pg_escape_string($parms[
'word']))
575 'filter' => sprintf(
"svalues ~* '%s'", pg_escape_string($parms[
'word'])) ,
588 'orderby' =>
'title',
589 'filter' => sprintf(
"svalues ~* '%s'", pg_escape_string($parms[
'word']))
594 'orderby' =>
'title',
595 'filter' => sprintf(
"svalues ~* '%s'", pg_escape_string($parms[
'word'])) ,
608 'orderby' =>
'cdate',
609 'filter' => sprintf(
"svalues ~* '%s'", pg_escape_string($parms[
'word']))
614 'orderby' =>
'cdate',
615 'filter' => sprintf(
"svalues ~* '%s'", pg_escape_string($parms[
'word'])) ,
629 'filter' => sprintf(
"svalues ~* '%s'", pg_escape_string($parms[
'word']))
635 'filter' => sprintf(
"svalues ~* '%s'", pg_escape_string($parms[
'word'])) ,
649 include_once (
'FDL/Class.DocSearch.php');
651 $ret_sqlfilter = array();
658 'filter' => $ret_filter
663 'filter' => $ret_filter,
674 include_once (
'FDL/Class.DocSearch.php');
676 $ret_sqlfilter = array();
683 'filter' => $ret_filter,
689 'filter' => $ret_filter,
690 'orderby' =>
'title',
701 include_once (
'FDL/Class.DocSearch.php');
703 $ret_sqlfilter = array();
710 'filter' => $ret_filter,
716 'filter' => $ret_filter,
717 'orderby' =>
'cdate',
728 include_once (
'FDL/Class.DocSearch.php');
730 $ret_sqlfilter = array();
737 'filter' => $ret_filter,
743 'filter' => $ret_filter,
755 include_once (
'FDL/Class.DocSearch.php');
757 $ret_sqlfilter = array();
764 'filter' => $ret_filter,
765 'orderby' => $ret_orderby
770 'filter' => $ret_filter,
771 'orderby' => $ret_orderby,
784 if (!array_key_exists(
'dbaccess', $opt)) {
790 $s->setObjectReturn();
793 if (array_key_exists(
'orderby', $opt)) {
794 $s->orderby = $opt[
'oderby'];
797 $s->slice = $parms[
'limit'];
798 if (array_key_exists(
'limit', $opt)) {
799 $s->slice = $opt[
'limit'];
802 if (array_key_exists(
'distinct', $opt)) {
803 if ($opt[
'distinct'] ===
false || $opt[
'distinct'] ===
true) {
804 $s->distinct = $opt[
'distinct'];
808 if (array_key_exists(
'filter', $opt)) {
809 if (is_array($opt[
'filter'])) {
810 foreach ($opt[
'filter'] as
$filter) {
811 $s->addFilter($filter);
814 $s->addFilter($opt[
'filter']);
820 $debugInfo =
$s->getDebugInfo();
821 return $debugInfo[
'delay'];
834 $stat[
'login'] = $action->user->login;
836 $stat[
'uid'] = $action->user->id;
838 $q = pg_query(getDbId($dbaccess_freedom) ,
"SELECT count(id) AS count FROM doc");
840 error_log(__FILE__ .
" " . sprintf(
"Error: count doc query failed"));
843 $d = pg_fetch_all(
$q);
844 $stat[
'doc_count'] =
$d[0][
'count'];
846 $q = pg_query(getDbId($dbaccess_freedom) ,
"SELECT count(*) AS count FROM docperm");
848 error_log(__FILE__ .
" " . sprintf(
"Error: count docperm query failed"));
851 $d = pg_fetch_all(
$q);
852 $stat[
'docperm_count'] =
$d[0][
'count'];
854 $parent_groups = $action->user->getGroupsId();
855 $all_groups_list = array();
856 foreach ($parent_groups as $group) {
857 array_push($all_groups_list, $group);
860 for ($i = 0; $i < count($all_groups_list); $i++) {
861 $gid = $all_groups_list[$i];
863 $group =
new User($dbaccess_core, $gid);
864 if (!is_object($group)) {
865 error_log(__FILE__ .
" " . sprintf(
"Error: invalid group with id '%s'"));
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);
875 $stat[
'user_groups_count'] = $group_count++;
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']);