本文整理汇总了PHP中Zend_Search_Lucene_Storage_Directory_Filesystem::createFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Storage_Directory_Filesystem::createFile方法的具体用法?PHP Zend_Search_Lucene_Storage_Directory_Filesystem::createFile怎么用?PHP Zend_Search_Lucene_Storage_Directory_Filesystem::createFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Search_Lucene_Storage_Directory_Filesystem
的用法示例。
在下文中一共展示了Zend_Search_Lucene_Storage_Directory_Filesystem::createFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFilesystem
public function testFilesystem()
{
$tempPath = dirname(__FILE__) . '/_tempFiles/_files';
if (is_dir($tempPath)) {
// remove files from temporary direcytory
$dir = opendir($tempPath);
while (($file = readdir($dir)) !== false) {
if (!is_dir($tempPath . '/' . $file)) {
@unlink($tempPath . '/' . $file);
}
}
closedir($dir);
}
$directory = new Zend_Search_Lucene_Storage_Directory_Filesystem($tempPath);
$this->assertTrue($directory instanceof Zend_Search_Lucene_Storage_Directory);
$this->assertEquals(count($directory->fileList()), 0);
$fileObject = $directory->createFile('file1');
$this->assertTrue($fileObject instanceof Zend_Search_Lucene_Storage_File);
unset($fileObject);
$this->assertEquals($directory->fileLength('file1'), 0);
$this->assertEquals(count(array_diff($directory->fileList(), array('file1'))), 0);
$directory->deleteFile('file1');
$this->assertEquals(count($directory->fileList()), 0);
$this->assertFalse($directory->fileExists('file2'));
$fileObject = $directory->createFile('file2');
$this->assertEquals($directory->fileLength('file2'), 0);
$fileObject->writeBytes('0123456789');
unset($fileObject);
$this->assertEquals($directory->fileLength('file2'), 10);
$directory->renameFile('file2', 'file3');
$this->assertEquals(count(array_diff($directory->fileList(), array('file3'))), 0);
$modifiedAt1 = $directory->fileModified('file3');
clearstatcache();
$directory->touchFile('file3');
$modifiedAt2 = $directory->fileModified('file3');
sleep(1);
clearstatcache();
$directory->touchFile('file3');
$modifiedAt3 = $directory->fileModified('file3');
$this->assertTrue($modifiedAt2 >= $modifiedAt1);
$this->assertTrue($modifiedAt3 > $modifiedAt2);
$fileObject = $directory->getFileObject('file3');
$this->assertEquals($fileObject->readBytes($directory->fileLength('file3')), '0123456789');
unset($fileObject);
$fileObject = $directory->createFile('file3');
$this->assertEquals($fileObject->readBytes($directory->fileLength('file3')), '');
unset($fileObject);
$directory->deleteFile('file3');
$this->assertEquals(count($directory->fileList()), 0);
$directory->close();
}
示例2: writeChanges
/**
* Write changes if it's necessary.
*/
public function writeChanges()
{
if (!$this->_deletedDirty) {
return;
}
if (extension_loaded('bitset')) {
$delBytes = $this->_deleted;
$bitCount = count(bitset_to_array($delBytes));
} else {
$byteCount = floor($this->_docCount / 8) + 1;
$delBytes = str_repeat(chr(0), $byteCount);
for ($count = 0; $count < $byteCount; $count++) {
$byte = 0;
for ($bit = 0; $bit < 8; $bit++) {
if (isset($this->_deleted[$count * 8 + $bit])) {
$byte |= 1 << $bit;
}
}
$delBytes[$count] = chr($byte);
}
$bitCount = count($this->_deleted);
}
$delFile = $this->_directory->createFile($this->_name . '.del');
$delFile->writeInt($this->_docCount);
$delFile->writeInt($bitCount);
$delFile->writeBytes($delBytes);
$this->_deletedDirty = false;
}
示例3: createFile
public function createFile($filename)
{
try {
parent::createFile($filename);
} catch (Zend_Search_Lucene_Exception $e) {
if (false === strpos($e->getMessage(), 'chmod')) {
throw $e;
}
}
return $this->_fileHandlers[$filename];
}
示例4: writeChanges
/**
* Write changes if it's necessary.
*
* This method must be invoked only from the Writer _updateSegments() method,
* so index Write lock has to be already obtained.
*
* @internal
* @throws Zend_Search_Lucene_Exceptions
*/
public function writeChanges()
{
// Get new generation number
$latestDelGen = $this->_detectLatestDelGen();
if (!$this->_deletedDirty) {
// There was no deletions by current process
if ($latestDelGen == $this->_delGen) {
// Delete file hasn't been updated by any concurrent process
return;
} else if ($latestDelGen > $this->_delGen) {
// Delete file has been updated by some concurrent process
// Reload deletions file
$this->_delGen = $latestDelGen;
$this->_deleted = $this->_loadDelFile();
return;
} else {
require_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Delete file processing workflow is corrupted for the segment \'' . $this->_name . '\'.');
}
}
if ($latestDelGen > $this->_delGen) {
// Merge current deletions with latest deletions file
$this->_delGen = $latestDelGen;
$latestDelete = $this->_loadDelFile();
if (extension_loaded('bitset')) {
$this->_deleted = bitset_union($this->_deleted, $latestDelete);
} else {
$this->_deleted += $latestDelete;
}
}
if (extension_loaded('bitset')) {
$delBytes = $this->_deleted;
$bitCount = count(bitset_to_array($delBytes));
} else {
$byteCount = floor($this->_docCount/8)+1;
$delBytes = str_repeat(chr(0), $byteCount);
for ($count = 0; $count < $byteCount; $count++) {
$byte = 0;
for ($bit = 0; $bit < 8; $bit++) {
if (isset($this->_deleted[$count*8 + $bit])) {
$byte |= (1<<$bit);
}
}
$delBytes[$count] = chr($byte);
}
$bitCount = count($this->_deleted);
}
if ($this->_delGen == -1) {
// Set delete file generation number to 1
$this->_delGen = 1;
} else {
// Increase delete file generation number by 1
$this->_delGen++;
}
$delFile = $this->_directory->createFile($this->_name . '_' . base_convert($this->_delGen, 10, 36) . '.del');
$delFile->writeInt($this->_docCount);
$delFile->writeInt($bitCount);
$delFile->writeBytes($delBytes);
$this->_deletedDirty = false;
}
示例5: writeChanges
/**
* Write changes if it's necessary.
*
* This method must be invoked only from the Writer _updateSegments() method,
* so index Write lock has to be already obtained.
*
* @internal
*/
public function writeChanges()
{
if (!$this->_deletedDirty) {
return;
}
if (extension_loaded('bitset')) {
$delBytes = $this->_deleted;
$bitCount = count(bitset_to_array($delBytes));
} else {
$byteCount = floor($this->_docCount / 8) + 1;
$delBytes = str_repeat(chr(0), $byteCount);
for ($count = 0; $count < $byteCount; $count++) {
$byte = 0;
for ($bit = 0; $bit < 8; $bit++) {
if (isset($this->_deleted[$count * 8 + $bit])) {
$byte |= 1 << $bit;
}
}
$delBytes[$count] = chr($byte);
}
$bitCount = count($this->_deleted);
}
// Get new generation number
$this->_detectLatestDelGen();
if ($this->_delGen == -1) {
// Set delete file generation number to 1
$this->_delGen = 1;
} else {
// Increase delete file generation number by 1
$this->_delGen++;
}
$delFile = $this->_directory->createFile($this->_name . '_' . base_convert($this->_delGen, 10, 36) . '.del');
$delFile->writeInt($this->_docCount);
$delFile->writeInt($bitCount);
$delFile->writeBytes($delBytes);
$this->_deletedDirty = false;
}
示例6: writeChanges
/**
* Write changes if it's necessary.
*/
public function writeChanges()
{
if (!$this->_deletedDirty) {
return;
}
if (extension_loaded('bitset')) {
$delBytes = $this->_deleted;
$bitCount = count(bitset_to_array($delBytes));
} else {
$byteCount = floor($this->_docCount / 8) + 1;
$delBytes = str_repeat(chr(0), $byteCount);
for ($count = 0; $count < $byteCount; $count++) {
$byte = 0;
for ($bit = 0; $bit < 8; $bit++) {
if (isset($this->_deleted[$count * 8 + $bit])) {
$byte |= 1 << $bit;
}
}
$delBytes[$count] = chr($byte);
}
$bitCount = count($this->_deleted);
}
// Get new generation number
$lock = Zend_Search_Lucene::obtainWriteLock($this->_directory);
$delFileList = array();
foreach ($this->_directory->fileList() as $file) {
if ($file == $this->_name . '.del') {
// Matches <segment_name>.del file name
$delFileList[] = 0;
} else {
if (preg_match('/^' . $this->_name . '_([a-zA-Z0-9]+)\\.del$/i', $file, $matches)) {
// Matches <segment_name>_NNN.del file names
$delFileList[] = (int) $matches[1];
}
}
}
if (count($delFileList) == 0) {
// There is no deletions file for current segment in the directory
// Set detetions file generation number to 1
$this->_delGen = 1;
} else {
// There are some deletions files for current segment in the directory
// Set detetions file generation number to the highest + 1
$this->_delGen = max($delFileList) + 1;
}
$delFile = $this->_directory->createFile($this->_name . '_' . base_convert($this->_delGen, 10, 36) . '.del');
Zend_Search_Lucene::releaseWriteLock($this->_directory, $lock);
$delFile->writeInt($this->_docCount);
$delFile->writeInt($bitCount);
$delFile->writeBytes($delBytes);
$this->_deletedDirty = false;
}