PHP Classes

File: example/IFile_Ex04_CustomFields.php

Recommend this page to a friend!
  Classes of Giampaolo Losito  >  IFile  >  example/IFile_Ex04_CustomFields.php  >  Download  
File: example/IFile_Ex04_CustomFields.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: 2 years ago
Size: 2,275 bytes


Class file image Download
 * IFile framework
 * @category IndexingFile
 * @package ifile.example
 * @author Giampaolo Losito, Antonio Di Girolomo
 * @copyright 2011-2013 (
 * @license GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999
 * @version 1.2.1
 * This script is a example how to indexed a single document with Custom Fields with Lucene
/** 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';
// Path of Document
$file = 'myfiles/customFields/TestAddCustomField.txt';

// try/catch
try {
// instance IFileFactory
$IFileFactory = IFileFactory::getInstance();
// define lucene interface
$ifile = $IFileFactory->getIFileIndexing('lucene', $index_path);
// set document
// setting Custom Fields
$ifile->addCustomField('customfield_Keyword', 'my keyword', IFile_Indexing_Interface::FIELD_TYPE_KEYWORD);
$ifile->addCustomField('customfield_Text', 'my text', IFile_Indexing_Interface::FIELD_TYPE_TEXT);
$ifile->addCustomField('customfield_UnStored', 'my text Unstored', IFile_Indexing_Interface::FIELD_TYPE_UNSTORED);
$ifile->addCustomField('customfield_UnIndexed', 'my text Unindexed', IFile_Indexing_Interface::FIELD_TYPE_UNINDEXED);
$ifile->addCustomField('customfield_Binary', 'Binary', IFile_Indexing_Interface::FIELD_TYPE_BINARY);
    // Not use name of custom fields that IFile define automatically
    // The Custom Fields overwrite the field created from IFile when this parse the document
    // Example: this field overwrite the field "key" created to IFile
    // $ifile->addCustomField('key', 'mykeyfile', IFile_Indexing_Interface::FIELD_TYPE_KEYWORD);
    // get all custom field
$customFields = $ifile->getCustomField();
// add document to index
$doc = $ifile->addDocument();
// store document

"The ($file) is correctly indexing<br />";
"With this custom fields:<br>";
} catch (
Exception $e) {
"Error in document: ($file) - ".$e->getMessage()."<br />";