PHP Classes
elePHPant
Icontem

File: example/IFile_Ex02_MultipleFile.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Giampaolo Losito  >  IFile  >  example/IFile_Ex02_MultipleFile.php  >  Download  
File: example/IFile_Ex02_MultipleFile.php
Role: Example script
Content type: text/plain
Description: Example script
Class: IFile
Index and search documents using Lucene or MySQL
Author: By
Last change:
Date: 1 year ago
Size: 1,748 bytes
 

Contents

Class file image Download
<?php
/**
 * IFile framework
 *
 * @category IndexingFile
 * @package ifile.example
 * @author Giampaolo Losito, Antonio Di Girolomo
 * @copyright 2011-2013 isApp.it (www.isapp.it)
 * @license GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999
 * @version 1.2.1
 *
 */
 
/**
 * This script is a example how to indexed more documents with Lucene
 */
error_reporting(E_ALL);
/** require IFileFactory */
require_once '../IFileFactory.php';

// Define the folder of index.
// The first time, if the folder exists IFile throw an exception.
$index_path = 'example_ifile_index';
// Folder of Documents
$directory = "myfiles";

// first try for catch the errors of interface
try {
   
   
// instance IFileFactory
   
$IFileFactory = IFileFactory::getInstance();
   
// define lucene interface
   
$ifile = $IFileFactory->getIFileIndexing('lucene', $index_path);
   
   
// array of files
   
$files = array();
   
// get files in folder
   
if ($handle = opendir($directory)) {
        while (
$file = readdir($handle)) {
            if (!
is_dir("{$directory}/{$file}")) {
                if (
$file != "." & $file != "..") {
                   
$files[] = "{$directory}/{$file}";
                }
            }
        }
    }
   
closedir($handle);
   
    foreach (
$files as $file) {
       
// second try for catch the error in index process of documents
       
try {
           
// set document
           
$ifile ->setIndexFile($file);
           
// add document to index
           
$doc = $ifile->addDocument();
           
// store document
           
$ifile->commit();
           
            echo
"The ($file) is correctly indexing<br />";
           
        } catch (
exception $e) {
            echo
"Error in document: ($file) - ".$e->getMessage()."<br />";
        }
    }
   
} catch (
Exception $e) {
    echo
"Generic Error: ".$e->getMessage()."<br />";
}
?>