<?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 a single document with Custom Fields with MySql
*
* IMPORTANT:
* For MySql is important define in the configuration (IFileConfig.xml)
* Define Table name that IFile must used
* The fields: name, path, filename as "Text":
*
<table-name collation="utf8_general_ci">ifile_index_table</table-name>
...
<zend-document>
<fields>
<field name="name" type="Text" />
<field name="path" type="Text" />
<field name="filename" type="Text" />
</fields>
</zend-document>
*/
error_reporting(E_ALL);
/** require IFileFactory */
require_once '../IFileFactory.php';
// Create connection at MySql
// IFile works only with MySqli InterfaceĆ¹
// First to test, you must create "example_ifile_index" DB in the your MySql
$connection = @new mysqli('localhost', 'root', '', 'example_ifile_index', 3306);
if (mysqli_connect_error()) {die(" - ".mysqli_connect_error()." - ");}
// Path of Document
$file = 'myfiles/customFields/TestAddCustomField.txt';
// try/catch
try {
// instance IFileFactory
$IFileFactory = IFileFactory::getInstance();
// define mysqli interface
$ifile = $IFileFactory->getIFileIndexing('mysqli', $connection);
// set document
$ifile->setIndexFile($file);
// 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);
// WARNING:
// 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
$ifile->commit();
echo "The ($file) is correctly indexing<br />";
echo "With this custom fields:<br>";
var_dump($customFields);
} catch (Exception $e) {
echo "Error in document: ($file) - ".$e->getMessage()."<br />";
}
?>
|