CommunityID/libs/Monkeys/Lucene.php

95 lines
2.5 KiB
PHP
Raw Normal View History

2019-07-17 20:16:19 +00:00
<?php
/*
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
2019-07-17 20:16:19 +00:00
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
* @author Keyboard Monkeys Ltd.
* @package Monkeys Framework
2019-07-17 20:16:19 +00:00
* @packager Keyboard Monkeys
*/
abstract class Monkeys_Lucene
2019-07-17 20:16:19 +00:00
{
const LUCENE_DIR = '/lucene';
private static $_index;
2019-07-17 20:16:19 +00:00
/**
* @throws Zend_Search_Lucene_exception
*/
public static function getIndex()
{
if (!@self::$_index) {
try {
self::$_index = Zend_Search_Lucene::open(APP_DIR . self::LUCENE_DIR);
} catch (Zend_Search_Lucene_Exception $e) {
self::$_index = Zend_Search_Lucene::create(APP_DIR . self::LUCENE_DIR);
Zend_Registry::get('logger')->log('Created Lucene index file', Zend_Log::INFO);
}
2019-07-17 20:16:19 +00:00
}
return self::$_index;
2019-07-17 20:16:19 +00:00
}
public static function optimizeIndex()
2019-07-17 20:16:19 +00:00
{
$index = self::getIndex();
$index->optimize();
}
2019-07-17 20:16:19 +00:00
public static function checkPcreUtf8Support()
{
if (@preg_match('/\pL/u', 'a') == 1) {
return true;
} else {
return false;
2019-07-17 20:16:19 +00:00
}
}
2019-07-17 20:16:19 +00:00
public static function clearIndex()
{
// need to remove the locks, otherwise error under windows
self::getIndex()->removeReference();
self::$_index = null;
2019-07-17 20:16:19 +00:00
self::_rmdirr(APP_DIR . self::LUCENE_DIR);
2019-07-17 20:16:19 +00:00
}
/** * Delete a file, or a folder and its contents
*
* @author Aidan Lister <aidan@php.net>
* @version 1.0.1
* @param string $dirname Directory to delete
* @return bool Returns TRUE on success, FALSE on failure
*/
private static function _rmdirr($dirname)
2019-07-17 20:16:19 +00:00
{
// Sanity check
if (!file_exists($dirname)) {
return false;
2019-07-17 20:16:19 +00:00
}
// Simple delete for a file
if (is_file($dirname)) {
return unlink($dirname);
2019-07-17 20:16:19 +00:00
}
// Loop through the folder
$dir = dir($dirname);
while (false !== $entry = $dir->read()) {
// Skip pointers and dot directories
if (substr($entry, 0, 1) == '.') {
continue;
}
// Deep delete directories
if (is_dir("$dirname/$entry")) {
self::_rmdirr("$dirname/$entry");
} else {
unlink("$dirname/$entry");
}
}
// Clean up
$dir->close();
2019-07-17 20:16:19 +00:00
return true;
2019-07-17 20:16:19 +00:00
}
}