18 require_once SQ_FUDGE_PATH.
'/general/text.inc';
52 function processWordSearch(&$sm, $search_term, $data_source, $base_query, $word_logic=
'AND')
54 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'dbsearch');
56 switch ($data_source[
'type']) {
61 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
64 $base_query[
'where'][] = $contains_str;
68 $attribute = $GLOBALS[
'SQ_SYSTEM']->am->getAttribute($data_source[
'params'][
'attrid']);
69 $base_query[
'where'][] =
'ai.component = '.MatrixDAL::quote(
'attr:'.$attribute->name);
73 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
76 $base_query[
'where'][] = $contains_str;
80 $metadata_field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($data_source[
'params'][
'assetid']);
82 'metadata_field_hierarchy' =>
'selection',
83 'metadata_field_select' =>
'selection',
84 'metadata_field_multiple_text' =>
'selection',
85 'metadata_field_thesaurus' =>
'thesaurus',
86 'metadata_field_wysiwyg' =>
'metadata_field_wysiwyg',
88 $key_type = array_get_index($key_types, get_class_lower($metadata_field),
'text');
89 $base_query[
'where'][] =
'ai.type = '.MatrixDAL::quote($key_type);
90 $base_query[
'where'][] =
'ai.component = '.MatrixDAL::quote(
'metadata:'.(
int)$data_source[
'params'][
'assetid']);
92 if (get_class_lower($metadata_field) ==
'metadata_field_select' && $metadata_field->attr(
'multiple')) {
93 if (strpos($search_term,
' AND ') !== FALSE) {
101 $searched_terms = explode($split,$search_term);
102 $sub_contains_qry =
'';
103 foreach ($searched_terms as $sterm) {
106 $sub_contains_qry .=
'{[option]'.$sterm.
'[/option]}'.$split_type;
108 $sub_contains_qry = trim($sub_contains_qry,$split_type);
109 $contains_str =
' contains(ai.value, '.MatrixDAL::quote($sub_contains_qry).
', 1) > 0';
112 $contains_str = $this->
_buildContainsQuery($sm,
'ai.value', $search_term, $word_logic, 1, ($key_type !=
'text' && $key_type !=
'metadata_field_wysiwyg' && get_class_lower($metadata_field) !=
'metadata_field_multiple_text' && ($key_type !=
'thesaurus')));
114 if (!$contains_str) {
115 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
118 $base_query[
'where'][] = $contains_str;
122 $field = $data_source[
'params'][
'field'];
123 if (isset($sm->standard_text_fields[$field])) {
124 $base_query[
'where'][] =
'ai.component = '.MatrixDAL::quote(
'__'.$field.
'__');
127 if (!$contains_str) {
128 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
131 $base_query[
'where'][] = $contains_str;
133 trigger_error(
'Invalid standard search field '.$field, E_USER_WARNING);
139 $bind_vars = array_get_index($base_query,
'bind_vars', Array());
140 $sql = implode_sql($base_query);
141 $query = MatrixDAL::preparePDOQuery($sql);
142 foreach ($bind_vars as $bind_var => $value) {
145 if (count($base_query[
'select']) > 2) {
151 $result_old_format = Array();
152 foreach ($result as $assetid => $info) {
153 $result_old_format[$assetid] = $info[0][
'search_score'];
156 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
158 return $result_old_format;
161 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
188 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'dbsearch');
190 switch ($data_source[
'type']) {
193 $attrid = $data_source[
'params'][
'attrid'];
194 $attr_info = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeInfo(Array($attrid));
195 $attr_info = $attr_info[$attrid];
197 $attr_type = $attr_info[
'type'];
198 $base_query[
'where'][] =
'ai.component = '.MatrixDAL::quote(
'attr:'.$attr_info[
'name']);
200 if ($numeric_range[
'upper'] == $numeric_range[
'lower']) {
201 $search_compare =
'= '.MatrixDAL::quote($numeric_range[
'upper']);
202 }
else if (is_null($numeric_range[
'upper'])) {
203 $search_compare =
'>= '.MatrixDAL::quote($numeric_range[
'lower']);
204 }
else if (is_null($numeric_range[
'lower'])) {
205 $search_compare =
'<= '.MatrixDAL::quote($numeric_range[
'upper']);
206 }
else if ($numeric_range[
'upper'] > $numeric_range[
'lower']) {
208 $search_compare =
'BETWEEN '.MatrixDAL::quote($numeric_range[
'lower']).
' AND '.
MatrixDAL::quote($numeric_range[
'upper']);
212 $search_compare =
'BETWEEN '.MatrixDAL::quote($numeric_range[
'upper']).
' AND '.
MatrixDAL::quote($numeric_range[
'lower']);
215 if ($attr_type ==
'int') {
216 $base_query[
'where'][] =
'CAST(CAST(ai.value AS varchar(255)) AS integer) '.$search_compare;
218 $base_query[
'where'][] =
'CAST(CAST(ai.value AS varchar(255)) AS double precision) '.$search_compare;
231 $bind_vars = array_get_index($base_query,
'bind_vars', Array());
232 $sql = implode_sql($base_query);
233 $query = MatrixDAL::preparePDOQuery($sql);
234 foreach ($bind_vars as $bind_var => $value) {
237 if (count($base_query[
'select']) > 2) {
243 $result_old_format = Array();
244 foreach ($result as $assetid => $info) {
245 $result_old_format[$assetid] = $info[0][
'search_score'];
248 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
250 return $result_old_format;
253 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
280 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'dbsearch');
282 switch ($data_source[
'type']) {
286 $attribute = $GLOBALS[
'SQ_SYSTEM']->am->getAttribute($data_source[
'params'][
'attrid']);
287 $base_query[
'where'][] =
'ai.component = '.MatrixDAL::quote(
'attr:'.$attribute->name);
291 $metadata_field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($data_source[
'params'][
'assetid']);
293 'metadata_field_select' =>
'selection',
294 'metadata_field_thesaurus' =>
'thesaurus',
295 'metadata_field_date' =>
'datetime',
297 $key_type = array_get_index($key_types, get_class_lower($metadata_field),
'text');
298 $base_query[
'where'][] =
'ai.type = '.MatrixDAL::quote($key_type);
299 $base_query[
'where'][] =
'ai.component = '.MatrixDAL::quote(
'metadata:'.(
int)$data_source[
'params'][
'assetid']);
303 $field = $data_source[
'params'][
'field'];
304 if (isset($sm->standard_date_fields[$field])) {
305 $base_query[
'where'][] =
'ai.component = '.MatrixDAL::quote(
'__'.$field.
'__');
307 trigger_error(
'Invalid standard date search field '.$field, E_USER_WARNING);
312 if ($date_range[
'from'] !=
'---------- --:--:--') {
315 if ($date_range[
'to'] !=
'---------- --:--:--') {
318 $bind_vars = array_get_index($base_query,
'bind_vars', Array());
319 $sql = implode_sql($base_query);
320 $query = MatrixDAL::preparePDOQuery($sql);
321 foreach ($bind_vars as $bind_var => $value) {
324 if (count($base_query[
'select']) > 2) {
330 $result_old_format = Array();
331 foreach ($result as $assetid => $info) {
332 $result_old_format[$assetid] = $info[0][
'search_score'];
335 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
337 return $result_old_format;
340 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
362 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'dbsearch');
366 foreach ($search_term as $exclude_value) {
369 $words = array_unique($words);
370 foreach($words as $key => $val) {
371 $words[$key] = strtolower($val);
374 $new_base = $base_query;
378 $new_base[
'where'][] = $contains_str;
379 $new_base[
'select'] = Array(
'ai.assetid');
380 $new_base[
'group_by'] = Array(
'ai.assetid');
381 $bind_vars = array_get_index($new_base,
'bind_vars', Array());
382 $sql = implode_sql($new_base);
383 $query = MatrixDAL::preparePDOQuery($sql);
384 foreach ($bind_vars as $bind_var => $value) {
392 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
406 if (!empty($result)) {
407 $new_result_format = Array();
408 foreach($result as $key => $val) {
409 $new_result_format[$val] = Array();
411 $result = $new_result_format;
434 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'dbsearch');
438 'from' => Array(
'sq_ast a'),
440 'where_joiner' =>
'AND',
441 'order_by' => Array(),
445 if (!empty($search_info[
'roots'])) {
446 $root_logic = array_get_index($search_info,
'root_logic',
'OR');
448 $treeid_sql =
'SELECT l.minorid, t.treeid
449 FROM sq_ast_lnk_tree t
450 JOIN sq_ast_lnk l on t.linkid = l.linkid
451 WHERE l.minorid IN ('.implode(
',', $search_info[
'roots']).
')';
455 if ($root_logic ==
'AND') {
456 foreach (array_values($search_info[
'roots']) as $i => $rootid) {
457 $treeid = $root_treeids[$rootid][0][
'treeid'];
458 $query[
'where'][] =
' EXISTS (
460 sq_ast_lnk l INNER JOIN sq_ast_lnk_tree t ON l.linkid = t.linkid
462 a.assetid = l.minorid
463 AND substr(t.treeid, 1, '.strlen($treeid).
') = '.
MatrixDAL::quote($treeid).
'
469 sq_ast_lnk l INNER JOIN sq_ast_lnk_tree t ON l.linkid = t.linkid
471 a.assetid = l.minorid
474 $treeids_where = Array();
475 foreach ($root_treeids as $treeid_value) {
476 $treeid = $treeid_value[0][
'treeid'];
477 $treeids_where[] =
'substr(t.treeid, 1, '.strlen($treeid).
') = '.
MatrixDAL::quote($treeid);
479 $sql .=
'('.implode(
' OR ', $treeids_where).
')';
480 $query[
'where'][] = $sql.
')';
485 $user_restrictions = (!$GLOBALS[
'SQ_SYSTEM']->userRoot() && !$GLOBALS[
'SQ_SYSTEM']->userSystemAdmin());
486 if ($user_restrictions) {
487 $query[
'from'][] =
'sq_ast_perm ap';
488 $query[
'where'][] =
'a.assetid = ap.assetid';
489 $userids = array_keys($GLOBALS[
'SQ_SYSTEM']->am->getParents($GLOBALS[
'SQ_SYSTEM']->user->id,
'user_group', FALSE));
490 array_push($userids, $GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user'), $GLOBALS[
'SQ_SYSTEM']->user->id);
491 for (reset($userids); NULL !== ($i = key($userids)); next($userids)) {
494 $query[
'where'][] =
'ap.userid IN ('.implode(
',', $userids).
')';
499 if (!empty($search_info[
'statuses'])) {
500 $statuses = $search_info[
'statuses'];
501 if (array_sum($statuses) != SQ_SC_STATUS_ALL) {
502 foreach ($statuses as $i => $status) {
505 $query[
'where'][] =
'a.status IN ('.implode(
', ', $statuses).
')';
509 $query[
'where'][] =
'a.status >= '.MatrixDAL::quote(SQ_STATUS_LIVE);
513 if (!empty($search_info[
'asset_types'])) {
514 $inherited_types = Array();
515 $normal_types = Array();
516 for (reset($search_info[
'asset_types']); NULL !== ($i = key($search_info[
'asset_types'])); next($search_info[
'asset_types'])) {
517 if ($search_info[
'asset_types'][$i] == 1) {
524 $type_code_cond = Array();
526 if (!empty($inherited_types)) {
527 $type_code_cond[] =
'inhd_type_code IN ('.implode(
', ', $inherited_types).
')';
528 if (!empty($normal_types)) {
529 $type_code_cond[] =
'type_code IN ('.implode(
', ', $normal_types).
')';
531 $type_code_cond = implode(
' OR ', $type_code_cond);
532 $query[
'where'][] =
'a.type_code IN (
535 WHERE '.$type_code_cond.
'
539 $query[
'where'][] =
'a.type_code IN ('.implode(
', ', $normal_types).
')';
543 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
567 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'dbsearch');
568 $sm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'search_manager');
577 assetid = '.MatrixDAL::quote($asset->id).
578 ($include_metadata ?
'' :
' AND component NOT LIKE '.MatrixDAL::quote(
'metadata:%'));
582 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
585 $word_scores = Array();
587 foreach ($result as $result_item) {
588 $word_string = strtolower($result_item[
'value']);
589 if ($result_item[
'type'] ==
'text') {
590 $words = preg_split(
'|\s+|', $word_string);
592 $words = Array($word_string);
594 $words = array_count_values($words);
595 foreach ($words as $word => $score) {
597 if ($sm->isWordIndexable($word)) {
598 if (!isset($word_scores[$word])) {
599 $word_scores[$word] = 0;
601 $word_scores[$word] += $score * $result_item[
'score'];
606 arsort($word_scores);
608 if ($include_scores) {
611 return array_keys($word_scores);
631 if (is_array($words)) {
633 }
else if (is_string($words)) {
635 $words = strtr($words,
'*?',
'%_');
638 $words = remove_silent_chars($words, TRUE, TRUE);
640 return Array($words);
666 $index_content = Array();
669 if (function_exists(
'mb_strtolower')) {
671 $contents = mb_strtolower($contents, SQ_CONF_DEFAULT_CHARACTER_SET);
674 $contents = htmlentities($contents, ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
675 $contents = strtolower($contents);
676 $contents = html_entity_decode($contents, ENT_NOQUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
678 $contents = str_replace(
' ',
' ', $contents);
679 $contents = trim($contents);
681 if (($data_type ==
'text') || ($data_type ==
'wysiwyg')) {
683 $contents = html_entity_decode($contents, ENT_QUOTES, SQ_CONF_DEFAULT_CHARACTER_SET);
686 $index_content[] = Array(
687 'value' => $contents,
688 'type_code' => $type_code,
689 'type' => $data_type,
690 'component' => $component,
691 'score' => $weighting,
692 'contextid' => $contextid,
693 'use_default' => $use_default,
696 return $index_content;
714 $components = explode(
'; ', $value);
716 foreach ($components as $comp) {
718 $value .=
'[option]'.$comp.
'[/option]';
741 if ($terms ==
'')
return FALSE;
743 $prev_terms = $terms;
750 for ($i = 0; $i < strlen($terms); $i++) {
751 if ($terms{$i} ==
')') {
753 if (($last_open != -1 && $last_close != -1) && $last_open < $last_close) {
754 if ($open_brackets == 0) {
763 }
else if ($terms{$i} ==
'(') {
769 if ($close_brackets != $open_brackets) {
770 if ($close_brackets > 0) {
771 $terms = str_repeat(
'(', $close_brackets).$terms;
774 if ($open_brackets > 0) {
775 $terms = $terms.str_repeat(
')', $open_brackets);
778 }
else if ($close_brackets > 0) {
779 $terms =
'('.$terms.
')';
783 while (substr_count($terms,
'()') != 0) {
784 $terms = str_replace(
'()',
'', $terms);
787 return ($prev_terms != $terms || $reparse);
805 $prev_terms = $terms;
806 $operators = Array(
'|',
'&',
'~');
814 $pattern_found = TRUE;
815 while ($pattern_found) {
816 $pattern_found = FALSE;
817 foreach ($operators as $op1) {
818 foreach ($operators as $op2) {
819 $prev_terms = $terms;
820 $terms = preg_replace(
'/(\\'.$op1.
')(\\'.$op2.
')/',
'\\2', $terms);
821 if ($prev_terms != $terms) $pattern_found = TRUE;
827 $bad_op_patterns = Array(
836 foreach ($operators as $op) {
837 foreach ($bad_op_patterns as $patt) {
838 $patt = str_replace(
'%',
'\\'.$op, $patt);
839 $terms = preg_replace($patt,
'\1\2\3', $terms);
840 if ($prev_terms != $terms) $pattern_found = TRUE;
844 return ($prev_terms != $terms);
863 $prev_terms = $terms;
871 $op = ($word_logic ==
'OR') ?
'|' :
'&';
873 $replacements = Array(
874 '/(#)+(#)+/U' =>
'\1'.$op.
'\2',
875 '/(@)+(@)+/U' =>
'\1'.$op.
'\2',
876 '/(\)+)([^\&\|\~\@\#])*(\()/U' =>
'\1'.$op.
'\3',
877 '/(\))(#)/' =>
'\1'.$op.
'\2',
878 '/(#)(\()/' =>
'\1'.$op.
'\2',
879 '/(\))(@)/' =>
'\1'.$op.
'\2',
880 '/(@)(\()/' =>
'\1'.$op.
'\2',
881 '/(#)(@)/' =>
'\1'.$op.
'\2',
882 '/(@)(#)/' =>
'\1'.$op.
'\2',
884 $terms = preg_replace(array_keys($replacements), $replacements, $terms);
886 return ($terms != $prev_terms);
909 $sym = ($clear) ?
' ' :
'!';
911 $match_chars =
'[\r\n\t ]';
914 '/('.$match_chars.
'+)%('.$match_chars.
'+)/' =>
'\1'.$sym.
'\2',
915 '/('.$match_chars.
'+)%('.$match_chars.
'+)/U' =>
'\1'.$sym.
'\2',
916 '/^%('.$match_chars.
'+)/U' => $sym.
'\1',
917 '/('.$match_chars.
'+)%$/U' =>
'\1'.$sym.
'\2',
921 foreach ($ops as $op => $sym) {
922 foreach ($pats as $pat => $rep) {
923 $pat = str_replace(
'%', $op, $pat);
924 $rep = str_replace(
'!', $sym, $rep);
925 $terms = preg_replace($pat, $rep, $terms);
948 function _getWords(&$terms, $remove_stop_words=FALSE, $return_stop_words=FALSE, $replace=FALSE, $ignore_chars=Array())
950 $preg_ignore_chars = Array();
951 foreach ($ignore_chars as $char) {
952 $preg_ignore_chars[] = preg_quote($char,
'/');
959 $match_chars =
'[^\r\n\t \(\)\|\&\~\%]';
960 $replace_chars =
'[^\r\n\t \(\)\|\&\~\%#'.implode(
'', $preg_ignore_chars).
']';
963 if (preg_match_all(
'/('.$match_chars.
'+)/', $terms, $words)) {
967 $terms = preg_replace(
'/#/',
'', $terms);
970 $good_words = Array();
971 $sm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'search_manager');
973 foreach ($words[1] as $word) {
974 if (empty($ignore_chars) || !in_array($word, $ignore_chars)) {
978 if ($sm->isWordIndexable($word)) {
980 $terms = preg_replace(
'/'.$replace_chars.
'+/',
'#', $terms, 1);
983 $good_words[] = $word;
990 $terms = preg_replace(
'/'.$replace_chars.
'+/',
'', $terms, 1);
1024 $phrase_placeholder =
'@';
1025 $preg_phrase_placeholder = preg_quote($phrase_placeholder,
'/');
1027 $exact_terms = $terms;
1028 $terms = strtolower($terms);
1031 $use_contains = (strlen($terms) <= 252);
1034 $terms = str_replace(
'""',
'', $terms);
1036 $good_phrases = Array();
1039 if (preg_match_all(
'/"([^"]+)"/', $terms, $phrases)) {
1040 $terms = preg_replace(
'/'.$preg_phrase_placeholder.
'/',
'', $terms);
1042 foreach ($phrases[1] as $phrase) {
1044 $phrase = preg_replace(
'/[^a-zA-Z0-9\s\.]/',
' ', $phrase);
1049 $phrase = trim($phrase);
1051 if ($phrase ==
'') {
1054 $good_phrases[] = $phrase;
1055 $replacement = $phrase_placeholder;
1057 $terms = preg_replace(
'/"[^"]+"/', $replacement, $terms, 1);
1062 $terms = preg_replace(
'/[^a-zA-Z0-9_\&\|\~'.$preg_phrase_placeholder.
'\(\)\s]/',
'&', $terms);
1067 $words = $this->
_getWords($terms, TRUE, FALSE, TRUE, Array($phrase_placeholder));
1070 $terms = preg_replace(
'/\s+/',
'', $terms);
1077 $reparse |= $this->
_parseTerms($sm, $terms, $word_logic);
1081 foreach ($words as $word) {
1083 $word =
'{'.$word.
'}';
1087 $word = str_replace(
'_',
'{_}', $word);
1088 $word = str_replace(
'%',
'{%}', $word);
1097 if ($sm->
attr(
'enable_begins_with')) {
1098 $word =
'%'.$word.
'%';
1104 $terms = preg_replace(
'/#/',
" $word ", $terms, 1);
1114 foreach ($good_phrases as $phrase) {
1115 $terms = preg_replace(
'/'.$preg_phrase_placeholder.
'/',
'{'.$phrase.
'}', $terms, 1);
1119 if (!preg_match(
'/[^\r\n\t ]+/', str_replace(
'_',
'', $terms))) {
1122 if (trim($terms) ==
'')
return FALSE;
1125 if (strpos($terms,
'|') !== FALSE) $multiple = TRUE;
1127 if ($use_contains) {
1128 $sql =
'contains('.$column.
', '.
MatrixDAL::quote(trim($terms)).
', '.$score.
') > 0';
1133 if ($exact && !$multiple) {
1134 $sql .=
' AND length(ai.value) = '.strlen($exact_terms);
1154 return 'DBMS_LOB.COMPARE('.$date1.
', '.$date2.
') '.$operator.
' 0';
1173 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'dbsearch');
1175 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($source_id);
1178 $query_array[
'select'][] =
'ai.assetid';
1179 $query_array[
'from'][] =
'sq_sch_idx ai';
1181 $query_array[
'where_joiner'] =
'AND';
1183 $query_array[
'where'][] =
'ai.type_code = '.MatrixDAL::quote($type);
1186 $terms = implode(
' or ', $keywords);
1189 $words = $this->
_getWords($terms, TRUE, FALSE);
1191 $words = array_unique($words);
1192 $terms = implode(
'|', $words);
1194 $terms_len = strlen($terms);
1196 $found_ids = Array();
1199 $term_string_built = FALSE;
1201 while (!$term_string_built && !empty($words)) {
1202 $recent_term = array_pop($words);
1203 if (strlen($terms.$recent_term) < 200) {
1206 $terms .= empty($terms) ? $escaped_term :
'|'.$escaped_term;
1208 array_push($words, $recent_term);
1209 $term_string_built = TRUE;
1213 $contains_str =
'contains(value, '.MatrixDAL::quote(trim($terms)).
', 1) > 0';
1215 $paginated_query_array = $query_array;
1216 $paginated_query_array[
'where'][] = $contains_str;
1217 if (!empty($found_ids)) {
1218 $pag_query_array[
'where'][] =
'ai.assetid not in (\''.implode($found_ids,
'\', \
'').
'\')
';
1221 $sql = implode_sql($paginated_query_array);
1222 $result = MatrixDAL::executeSqlAssoc($sql, 0);
1223 $found_ids = array_merge($found_ids, array_unique($result));
1226 $GLOBALS['SQ_SYSTEM
']->restoreDatabaseConnection();
1230 }//end getAssetidsByWordIntersection()
1239 function getMaxWordLength()
1243 }//end getMaxWordLength()
1256 function _escapeContainReservedWords($word)
1258 $reserved_words = Array(
1286 if (isset($reserved_words[$word])) {
1287 return '{
'.$word.'}
';
1292 }//end _escapeContainReservedWords()
1303 function _escapeContainReservedChars($word)
1305 $reserved_chars = Array('\\
',',
','?
','&
','=
','-
',';
','~
','|
','$
','!
','>
','*
','%
','_
','(
',')
','[
',']
','{
','}
');
1306 $escaped_chars = Array('\\\\
','\,
','\?
','\&
','\=
','\-
','\;
','\~
','\|
','\$
','\!
','\>
','\*
','\%
','\_
','\(
','\)
','\[
','\]
','\{
','\}
');
1308 $escaped_word = str_replace($reserved_chars, $escaped_chars, $word);
1310 return $escaped_word;
1313 }//end _escapeContainReservedChars()
1325 function getWords($search_string)
1327 return $this->_getWords($search_string);
1341 function getSearchListAssets(&$search_list, &$search_page)
1343 // get information about the search field
1344 $search_page_fields = $search_page->attr('fields
');
1345 $search_field_name = $search_list->attr('search_field
');
1346 if (empty($search_page_fields) || empty($search_field_name)) {
1347 // if search field has not been setup properly
1350 $search_field = $search_page_fields[$search_field_name];
1352 $GLOBALS['SQ_SYSTEM
']->changeDatabaseConnection('dbsearch
');
1353 $sm = $GLOBALS['SQ_SYSTEM
']->am->getSystemAsset('search_manager
');
1354 $search_info = $search_page->populateBaseSearchInfo();
1355 $query_comps = $sm->constructBaseSearchQuery($search_info);
1357 $query_comps['select
'][] = 'ai.assetid
';
1359 $data_source_comps = Array();
1360 $data_source_comps_values = Array();
1362 foreach ($search_field['data_sources
'] as $data_source) {
1363 switch ($data_source['type
']) {
1364 case 'asset_attrib
' :
1365 $type_code = $data_source['params
']['asset_type
'];
1366 $attrid = $data_source['params
']['attrid
'];
1368 $attr_info = $GLOBALS['SQ_SYSTEM
']->am->getAttributeInfo(Array($attrid));
1369 $name = $attr_info[$attrid]['name
'];
1370 $data_source_comps[] = 'ai.component =
'.MatrixDAL::quote('attr:
'.$name);
1371 $data_source_comps_values[] = MatrixDAL::quote('attr:
'.$name);
1374 $assetid = $data_source['params
']['assetid
'];
1375 $data_source_comps[] = 'ai.component =
'.MatrixDAL::quote('metadata:
'.$assetid);
1376 $data_source_comps_values[] = MatrixDAL::quote('metadata:
'.$assetid);
1379 $param_field = $data_source['params
']['field
'];
1380 $data_source_comps[] = 'ai.component =
'.MatrixDAL::quote('__
'.$param_field.'__
');
1381 $data_source_comps_values[] = MatrixDAL::quote('__
'.$param_field.'__
');
1390 if (!empty($data_source_comps)) {
1391 $query_comps['where
'][] = '(
'.implode(') OR (
', $data_source_comps).')
';
1394 $noise_words = array_keys($sm->attr('noise_word_list
'));
1395 $white_words = array_keys($sm->attr('white_word_list
'));
1396 $where_cond = '(
'.implode(') AND (
',$query_comps['where
']).')
';
1398 $min_length = $sm->attr('min_word_length
');
1399 $noise_words_str = '"'.implode('",
"', $noise_words).'"';
1400 $white_words_str = '"'.implode('",
"', $white_words).'"';
1401 $sql = 'SELECT * FROM table(
1402 sq_search_pkg.get_search_list(\
''.
1403 str_replace(
'\'',
'"', $where_cond).
'\', \
''.
1404 $min_length.
'\', \
''.
1405 $noise_words_str.
'\', \
''.
1406 $white_words_str.
'\'))
';
1408 $results = MatrixDAL::executeSqlAssoc($sql);
1409 $children = Array();
1410 if (!empty($results)) {
1411 foreach ($results as $ele) {
1412 $children[$ele['word
']] = Array(
1413 'num_values
' => $ele['hits
'],
1414 'first_letter
' => $ele['word
']{0},
1420 $GLOBALS['SQ_SYSTEM
']->restoreDatabaseConnection();
1424 }//end getSearchListAssets()