function build_query($user_search, $filtered, $count_only = false) { if ($count_only) { $search_query = "SELECT count(*) as count FROM resource"; } else { $search_query = "SELECT * FROM resource"; } $final_search_words = get_final_search_words($user_search); if (count($final_search_words) > 0) { $title = generate_where_clause($final_search_words, 'title'); $creator = generate_where_clause($final_search_words, 'creator'); $description = generate_where_clause($final_search_words, 'description'); $subject = generate_where_clause($final_search_words, 'subject'); $where_clause = $title . ' OR ' . $creator . ' OR ' . $description . ' OR ' . $subject; if (count($filtered) != 0) { $where_clause = '(' . $where_clause . ') and (id not in (' . implode(',', $filtered) . '))'; } // Add the keyword WHERE clause to the search query if (!empty($where_clause)) { $search_query .= " WHERE {$where_clause}"; } } $search_query .= " ORDER BY title"; return $search_query; }
function build_query($user_search, $user_id, $count_only = false) { if ($count_only) { $search_query = "SELECT count(*) as count FROM resource WHERE (user_id = '{$user_id}') "; } else { $search_query = "SELECT * FROM resource WHERE (user_id = '{$user_id}') "; } //$search_query = "SELECT * FROM resource"; // Extract the search keywords into an array $clean_search = str_replace(',', ' ', $user_search); $search_words = explode(' ', $clean_search); $final_search_words = array(); if (count($search_words) > 0) { foreach ($search_words as $word) { if (!empty($word)) { $final_search_words[] = $word; } } } if (count($final_search_words) > 0) { $title = generate_where_clause($final_search_words, 'title'); $creator = generate_where_clause($final_search_words, 'creator'); $description = generate_where_clause($final_search_words, 'description'); $subject = generate_where_clause($final_search_words, 'subject'); $where_clause = $title . ' OR ' . $creator . ' OR ' . $description . ' OR ' . $subject; // Add the keyword WHERE clause to the search query if (!empty($where_clause)) { $search_query .= " and ({$where_clause})"; } } $search_query .= " ORDER BY title"; return $search_query; }
function build_query($user_search, $count_only = false) { if ($count_only) { $search_query = "SELECT count(*) as count FROM def"; } else { $search_query = "SELECT * FROM def"; } //$search_query = "SELECT * FROM resource"; // Extract the search keywords into an array $clean_search = str_replace(',', ' ', $user_search); $search_words = explode(' ', $clean_search); $final_search_words = array(); if (count($search_words) > 0) { foreach ($search_words as $word) { if (!empty($word)) { $final_search_words[] = $word; } } } if (count($final_search_words) > 0) { $name = generate_where_clause($final_search_words, 'name'); $def = generate_where_clause($final_search_words, 'def'); $where_clause = $name . ' OR ' . $def; // Add the keyword WHERE clause to the search query if (!empty($where_clause)) { $search_query .= " WHERE {$where_clause}"; } } $search_query .= " ORDER BY name"; return $search_query; }
function build_query($user_search, $count_only = false) { if ($count_only) { $search_query = "SELECT count(*) as count FROM relation"; } else { $search_query = "SELECT * FROM relation"; } //$search_query = "SELECT * FROM resource"; // Extract the search keywords into an array $clean_search = str_replace(',', ' ', $user_search); $search_words = explode(' ', $clean_search); $final_search_words = array(); if (count($search_words) > 0) { foreach ($search_words as $word) { if (!empty($word)) { $final_search_words[] = $word; } } } if (count($final_search_words) > 0) { $subject = generate_where_clause($final_search_words, 'subject'); $object = generate_where_clause($final_search_words, 'object'); $predicate = generate_where_clause($final_search_words, 'predicate'); $where_clause = $subject . ' OR ' . $predicate . ' OR ' . $object; // Add the keyword WHERE clause to the search query if (!empty($where_clause)) { $search_query .= " WHERE {$where_clause}"; } } $search_query .= " ORDER BY value desc, distance, frequency desc"; return $search_query; }
function build_query($dbc, $user_search, $active_relation, $count_only = false) { if ($count_only) { $search_query = "SELECT count(*) as count FROM graph"; } else { $search_query = "SELECT * FROM graph"; } $clean_search = str_replace(',', ' ', $user_search); $search_words = explode(' ', $clean_search); $final_search_words = array(); if (count($search_words) > 0) { foreach ($search_words as $word) { if (!empty($word)) { //$final_search_words[] = $word; foreach (get_ids($dbc, $word) as $id) { $final_search_words[] = PREFIX . $id; } $final_search_words[] = $word; } } } //print_r($final_search_words); if (isset($active_relation)) { $where_clause_1 = "property='" . $active_relation . "'"; } if (count($final_search_words) > 0) { $subject = generate_where_clause($final_search_words, 'subject'); $object = generate_where_clause($final_search_words, 'value'); //$predicate = generate_where_clause($final_search_words, 'property'); $where_clause_2 = $subject . ' OR ' . $object; } if (isset($where_clause_1) && isset($where_clause_2)) { $search_query .= " WHERE {$where_clause_1} and ({$where_clause_2})"; } elseif (isset($where_clause_2)) { $search_query .= " WHERE {$where_clause_2}"; } elseif (isset($where_clause_1)) { $search_query .= " WHERE {$where_clause_1}"; } $search_query .= " ORDER BY subject desc"; return $search_query; }