Пример #1
0
 	arsort($scores, SORT_NUMERIC);		
 	$result = array();	
 	foreach ($scores as $key => $value) {
 		$result[$key] = $search_results_lessons[$key];
 	}
 	$search_results_lessons = $result;
 */
 foreach ($search_results_current_lesson as $key => $value) {
     $search_results_current_lesson[$key] = eF_multiSort($search_results_current_lesson[$key], 'score', 'asc', true);
 }
 foreach ($search_results_courses as $key => $value) {
     $search_results_courses[$key] = eF_multiSort($search_results_courses[$key], 'score', 'asc', true);
 }
 $search_results_forum = eF_multiSort($search_results_forum, 'body', 'desc');
 if (extension_loaded('xapian')) {
     $results_filesystem = EfrontXapian::getInstance()->search($_POST['search_text']);
     if ($currentUser->user['user_type'] != 'administrator') {
         //non-admins don't have access to files outside their lessons
         $paths = array();
         foreach ($currentUser->getLessons(true) as $lesson) {
             if ($lesson->lesson['active'] && !$lesson->lesson['archive']) {
                 $paths[] = str_replace(G_ROOTPATH, '', $lesson->getDirectory());
             }
         }
         foreach ($results_filesystem as $key => $value) {
             $keep = false;
             foreach ($paths as $path) {
                 if (strpos($value['path'], $path) !== false) {
                     $keep = true;
                 }
             }
Пример #2
0
<?php

if (php_sapi_name() != "cli") {
    print "This script is written to run under the command line ('cli') version of\n";
    print "the PHP interpreter, but you're using the '" . php_sapi_name() . "' version\n";
    exit(1);
}
error_reporting(E_ALL);
ini_set("display_errors", true);
ini_set("html_errors", true);
//$file = $argv[1];
require_once "xapian.class.php";
//EfrontXapian::getInstance()->addFileToIndex($file);
EfrontXapian::cron();
Пример #3
0
 public static function cron()
 {
     $hash_file_name = 'xapian_list_hash.txt';
     $list_file_name = 'xapian_list.txt';
     $new_file_name = 'temp.txt';
     $parse_root_path = realpath(dirname(__FILE__) . '/../../www/content/lessons');
     //$parse_root_path = "xapian_tests";
     if (is_file($list_file_name)) {
         $lines = file($list_file_name);
         if (is_file($hash_file_name)) {
             $hashes = file($hash_file_name, FILE_IGNORE_NEW_LINES);
         } else {
             foreach ($lines as $key => $value) {
                 if (is_file($value)) {
                     $hashes[$key] = sha1_file(trim($value));
                 } else {
                     $hashes[$key] = '';
                 }
             }
         }
     } else {
         $lines = $hashes = array();
     }
     $find_str = array();
     foreach (self::$_accepted_formats as $value) {
         $find_str[] = "\\*.{$value}";
     }
     $find_str = implode(" -o -name ", $find_str);
     exec("find {$parse_root_path} -name {$find_str} > {$new_file_name}");
     $newlines = file($new_file_name);
     $newFiles = array_slice(array_diff($newlines, $lines), 0, self::PARSE_LIMIT);
     //only parse 20 files at a time
     $deletedFiles = array_diff($lines, $newlines);
     EfrontXapian::getInstance()->addFilesToIndex($newFiles);
     EfrontXapian::getInstance()->removeFilesFromIndex($deletedFiles);
     //Remove deleted files from the list
     foreach ($deletedFiles as $value) {
         if (($key = array_search($value, $lines)) !== false) {
             unset($lines[$key]);
             unset($hashes[$key]);
         }
     }
     $lines = array_merge($lines, $newFiles);
     foreach ($newFiles as $value) {
         $hashes[] = sha1_file(trim($value));
     }
     foreach ($lines as $key => $value) {
         $hash = sha1_file(trim($value));
         if ($hashes[$key] != $hash) {
             //meaning the file has changed
             unset($lines[$key]);
             unset($hashes[$key]);
         }
     }
     $lines = array_values($lines);
     //Re-index $lines in case values where unset
     file_put_contents($list_file_name, implode("", $lines));
     file_put_contents($hash_file_name, implode("\n", $hashes));
 }