function seq_search_test($type, $string, $limit = 20, $modes = NULL, $count = false) { echo "<ol>"; $res = sequential_code_set_search($type, $string, $limit, $modes, $count); if ($count) { echo "<li>" . $res . "</li>"; } else { while ($code = sqlFetchArray($res)) { echo "<li>" . $code['code_type_name'] . ":" . $code['code'] . ":" . $code['code_text'] . ":" . $code['code_text_short'] . "</li>"; } } echo "</ol>"; }
/** * Code set searching "internal" function for when searching multiple code sets. * * It will also work for one code set search, although not meant for this. * (This function is not meant to be called directly) * * @param array $form_code_types code set keys (will default to checking all active code types if blank) * @param string $search_term search term * @param integer $limit Number of results to return (NULL means return all) * @param array $modes Holds the search modes to process along with the order of processing (default behavior is described in above function comment) * @param boolean $count if true, then will only return the number of entries * @param boolean $active if true, then will only return active entries * @param integer $start Query start limit (for pagination) * @param integer $number Query number returned (for pagination) * @param array $filter_elements Array that contains elements to filter * @return recordset/integer */ function multiple_code_set_search($form_code_types = array(), $search_term, $limit = NULL, $modes = NULL, $count = false, $active = true, $start = NULL, $number = NULL, $filter_elements = array()) { if (empty($form_code_types)) { // Collect the active code types $form_code_types = collect_codetypes("active", "array"); } if ($count) { //start the counter $counter = 0; } else { // Figure out the appropriate limit clause $limit_query = limit_query_string($limit, $start, $number); // Prepare the sql bind array $sql_bind_array = array(); // Start the query string $query = "SELECT * FROM (("; } // Loop through each code type $flag_first = true; $flag_hit = false; //ensure there is a hit to avoid trying an empty query foreach ($form_code_types as $form_code_type) { // see if there is a hit $mode_hit = NULL; // only use the count method here, since it's much more efficient than doing the actual query $mode_hit = sequential_code_set_search($form_code_type, $search_term, NULL, $modes, true, $active, NULL, NULL, $filter_elements, true); if ($mode_hit) { if ($count) { // count the hits $count_hits = code_set_search($form_code_type, $search_term, $count, $active, false, NULL, NULL, $filter_elements, NULL, $mode_hit); // increment the counter $counter += $count_hits; } else { $flag_hit = true; // build the query $return_query = code_set_search($form_code_type, $search_term, $count, $active, false, NULL, NULL, $filter_elements, NULL, $mode_hit, true); if (!empty($sql_bind_array)) { $sql_bind_array = array_merge($sql_bind_array, $return_query['binds']); } else { $sql_bind_array = $return_query['binds']; } if (!$flag_first) { $query .= ") UNION ALL ("; } $query .= $return_query['query']; } $flag_first = false; } } if ($count) { //return the count return $counter; } else { // Finish the query string $query .= ")) as atari {$limit_query}"; // Process and return the query (if there was a hit) if ($flag_hit) { return sqlStatement($query, $sql_bind_array); } } }