示例#1
0
<?php

require_once "database/connectDatabase.php";
require_once "database/indexesModel.php";
$indexesObj = new indexes($conn);
$indexesArray = $indexesObj->getIndexes();
?>

<html>
<head>
<title> List of indexes </title>
</head>
<body>
<table>
	<tr>
		<th>Dataset</th>
		<th>Indexes</th>
		<th>Content</th>
	</tr>
	<?php 
foreach ($indexesArray as $indexItem) {
    ?>
	<tr>
		<td><?php 
    echo htmlspecialchars($indexItem['title']);
    ?>
</td>
		<td><?php 
    echo $indexItem['indexCount'];
    ?>
</td>
 private function saveIndexes($file_id, $index_count, $total_count)
 {
     $index = new indexes($this->getDb());
     foreach ($index_count as $name => $count) {
         $wpm = floor(1000000 * ($count / $total_count));
         $index->insert(array('file' => $file_id, 'stem' => $name, 'count' => $count, 'wpm' => $wpm));
         //display('Inserted ' . $file_id . ' -- ' . $name . ' -- ' . $count . ' -- ' . $wpm);
     }
 }
 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'));
 }