/** * Performs and advanced search. */ private function advancedSearch() { // VENUE SEARCH ------------------------------------------ if ($this->sp->venue != '') { $parser = new SearchTermParser($this->sp->venue); $the_search_array = $parser->getWordList(); foreach ($the_search_array as $and_terms) { $union_array = array(); foreach ($and_terms as $or_term) { $this->venuesSearch('title', $or_term, $union_array); $this->venuesSearch('name', $or_term, $union_array); } $this->result_pubs = array_intersect($this->result_pubs, $union_array); } } // CATEGORY SEARCH ---------------------------------------------------- // // if category search found, pass on only the ids found with that match // with category if ($this->sp->cat_id != '') { $temporary_array = NULL; $cat_id = $this->sp->cat_id; $search_query = "SELECT DISTINCT pub_id FROM pub_cat WHERE cat_id=" . $this->db->quote_smart($cat_id); //we then add these matching id's to a temp array $this->add_to_array($search_query, $temporary_array); //then we only keep the common ids between both arrays $this->result_pubs = array_intersect($this->result_pubs, $temporary_array); } // PUBLICATION FIELDS SEARCH ------------------------------------------ $fields = array("title", "paper", "abstract", "keywords", "extra_info"); //same thing happening as category, just with each of these fields foreach ($fields as $field) { if (isset($this->sp->{$field}) && $this->sp->{$field} != '') { $parser = new SearchTermParser($this->sp->{$field}); $the_search_array = $parser->getWordList(); foreach ($the_search_array as $and_terms) { $union_array = null; foreach ($and_terms as $or_term) { $this->add_to_array('SELECT DISTINCT pub_id from publication WHERE ' . $field . ' LIKE ' . $this->db->quote_smart('%' . $or_term . '%'), $union_array); } $this->result_pubs = array_intersect($this->result_pubs, $union_array); } } } // MYSELF or AUTHOR SELECTED SEARCH ----------------------------------- $authors = array(); if (!empty($this->sp->authors)) { // need to retrieve author_ids for the selected authors $sel_author_names = explode(', ', preg_replace('/\\s\\s+/', ' ', $this->sp->authors)); $author_ids = array(); foreach ($sel_author_names as $author_name) { if (empty($author_name)) { continue; } $author_id = array_search($author_name, $this->db_authors); if ($author_id !== false) { $author_ids[] = $author_id; } } if (count($author_ids) > 0) { $authors = array_merge($authors, $author_ids); } } if (!empty($_SESSION['user'])) { if ($this->sp->author_myself != '' && $_SESSION['user']->author_id != '') { array_push($authors, $_SESSION['user']->author_id); } } if (count($authors) > 0) { foreach ($authors as $auth_id) { $author_pubs = array(); $search_query = "SELECT DISTINCT pub_id from pub_author " . "WHERE author_id=" . $this->db->quote_smart($auth_id); $this->add_to_array($search_query, $author_pubs); $this->result_pubs = array_intersect($this->result_pubs, $author_pubs); } } // ranking if (isset($this->sp->paper_rank)) { $union_array = array(); foreach ($this->sp->paper_rank as $rank_id => $value) { if ($value != 'yes') { continue; } $search_result = $this->db->query('SELECT venue_id from venue_rankings ' . 'WHERE rank_id=' . $this->db->quote_smart($rank_id)); foreach ($search_result as $row) { if (!empty($row->venue_id)) { $this->add_to_array('SELECT DISTINCT pub_id from publication ' . 'WHERE venue_id=' . $this->db->quote_smart($row->venue_id), $union_array); } } } foreach ($this->sp->paper_rank as $rank_id => $value) { if ($value != 'yes') { continue; } $this->add_to_array('SELECT DISTINCT pub_id from publication ' . 'WHERE rank_id=' . $this->db->quote_smart($rank_id), $union_array); } } if (!empty($this->sp->paper_rank_other)) { $this->add_to_array('SELECT DISTINCT pub_id from pub_rankings ' . 'WHERE description LIKE ' . $this->db->quote_smart("%" . $this->sp->paper_rank_other . "%"), $union_array); } if (isset($union_array) && is_array($union_array) && count($union_array) > 0) { $this->result_pubs = array_intersect($this->result_pubs, $union_array); } // collaboration if (isset($this->sp->paper_col)) { $union_array = array(); foreach ($this->sp->paper_col as $col_id => $value) { if ($value != 'yes') { continue; } $this->add_to_array('SELECT DISTINCT pub_id from pub_col ' . 'WHERE col_id=' . $this->db->quote_smart($col_id), $union_array); } if (count($union_array) > 0) { $this->result_pubs = array_intersect($this->result_pubs, $union_array); } } // user info if (!empty($this->sp->user_info)) { pdDb::debugOn(); $union_array = array(); $user_infos = preg_split('/\\s*[;,]\\s*/', $this->sp->user_info); foreach ($user_infos as $user_info) { $user_info = trim($user_info); $this->add_to_array('SELECT DISTINCT pub_id from publication ' . "WHERE user like '%{$user_info}%'", $union_array); } if (count($union_array) > 0) { $this->result_pubs = array_intersect($this->result_pubs, $union_array); } } // DATES SEARCH -------------------------------------- // adjust date information if user did not enter all the fields if (isset($this->sp->startdate['Y']) && !isset($this->sp->startdate['M'])) { $this->sp->startdate['M'] = '1'; } if (isset($this->sp->enddate['Y']) && !isset($this->sp->enddate['M'])) { $this->sp->enddate['M'] = '12'; } if (isset($this->sp->startdate)) { $startdate =& $this->sp->startdate; $stime = strtotime(implode('-', $startdate) . '-1'); } if (isset($this->sp->enddate)) { $enddate =& $this->sp->enddate; $etime = strtotime(implode('-', $enddate) . '-1'); } if (isset($stime) && isset($etime)) { if ($stime > $etime) { // the user did not enter an end date, default it to now $enddate['Y'] = date('Y'); $enddate['M'] = date('m'); $etime = strtotime(implode('-', $enddate) . '-1'); } if ($etime > $stime) { $startdate_str = date('Y-m-d', mktime(0, 0, 0, $startdate['M'], 1, $startdate['Y'])); $enddate_str = date('Y-m-d', mktime(0, 0, 0, $enddate['M'] + 1, 0, $enddate['Y'])); $temporary_array = NULL; $search_query = "SELECT DISTINCT pub_id from publication " . "WHERE published BETWEEN " . $this->db->quote_smart($startdate_str) . " AND " . $this->db->quote_smart($enddate_str); $this->add_to_array($search_query, $temporary_array); $this->result_pubs = array_intersect($this->result_pubs, $temporary_array); } } if ($this->debug) { debugVar('result', $this->result_pubs); } return $this->result_pubs; }
$index = $count > 0 ? $count - 1 : 0; $log_words[$index][] = $word; $or_condition = false; } else { $log_words[] = array($word); } } } // now remove common words foreach ($log_words as $and_term) { foreach ($and_term as $key => $or_term) { if (in_array($or_term, self::$common_words)) { unset($and_term[$key]); } } } return $log_words; } } // the following code runs only in CLI mode. // // should be replaced by unit test (in it's own file). if (PHP_SAPI == "cli") { require_once '../../php_common/functions.php'; if (!isset($argv[1])) { die("parameter expected\n"); } $parser = new SearchTermParser($argv[1]); $wordList = $parser->getWordList(); debugVar('$wordList', $wordList); }