public function base() { $submit = isset($_GET['submit']) ? true : false; $link = isset($_GET['link']) ? $_GET['link'] : false; $message = 'Add the link below'; if ($submit && $link) { $link_explode = explode('/', $link); $file = new files($this->getDb()); $added = $file->select('*', 'WHERE link="' . $link . '"'); if (!isset($added[0]['id'])) { $file->insert(array('name' => urldecode($link_explode[count($link_explode) - 1]), 'approved' => 0, 'downloaded' => 0, 'created' => time(), 'link' => $link)); $message = 'Successfully Added! You can add another link below'; } else { $message = 'This link is already in the index. You can add another link below'; } } $this->set('message', $message); }
private function getFileId($file_name) { if ($file_name == '') { return; } $file = new files($this->getDb()); $file_id = false; $files = $file->select('*', 'WHERE name="' . $file_name . '" OR name="' . $file_name . '.pdf" '); if (!isset($files[0]['id'])) { $id_array = $file->insert(array('name' => $file_name, 'approved' => 1, 'downloaded' => 1, 'created' => time())); $file_id = $id_array[0][1]; } else { $file_id = $files[0]['id']; } return $file_id; }
public function base() { $results = array(); $query = isset($_GET['q']) ? $_GET['q'] : false; $search = $query; if ($query !== false) { $stemmer = new PorterStemmer(); $index = new indexes($this->getDb()); $file = new files($this->getDb()); $scores = array(); $terms = explode(' ', $query); $db_searches = new searches($this->getDb()); foreach ($terms as $term) { if ($term != '') { $old = $db_searches->select('*', 'WHERE term="' . $term . '"'); if (isset($old[0]['id'])) { $db_searches->update(array('count' => ++$old[0]['count'], 'date' => time()), 'WHERE term="' . $term . '"'); } else { $db_searches->insert(array('term' => $term, 'count' => 1, 'date' => time())); } } } $term_weight = 0.05; $wpm_weight = 5; //7 $count_weight = 150; //135 $count = 0; foreach ($terms as $term) { $term = 'indx-' . $stemmer->Stem($term); $data = $index->select('*', 'WHERE stem="' . $term . '" ORDER BY wpm DESC, count DESC LIMIT 0, 100'); foreach ($data as $file_data) { $file_id = $file_data['file']; $wpm = $file_data['wpm']; $index_count = $file_data['count']; $weight = $wpm * $wpm_weight * (1 - $term_weight * $count) + $index_count * $count_weight * (1 - $term_weight * $count); if (isset($scores[$file_id])) { $scores[$file_id] += $weight; } else { $scores[$file_id] = $weight; } } $count++; } arsort($scores); foreach ($scores as $key => $score) { $results[$key] = array(); $results[$key]['score'] = $score; } $ids = array_keys($scores); $files = array(); if (count($ids) > 0) { $files = $file->select('*', 'WHERE id IN (' . implode(', ', $ids) . ')'); } foreach ($files as $selected) { $results[$selected['id']]['id'] = $selected['id']; $results[$selected['id']]['name'] = $selected['name']; $results[$selected['id']]['link'] = $selected['link']; } $this->set('results', $results); } else { $this->set('results', $results); } $this->set('search', $search); $searches = new searches($this->getDb()); $this->set('popular', $searches->select('*', 'ORDER BY count DESC LIMIT 0, 10')); }