Remove ElasticSearch feature

This commit is contained in:
Sebastian Meyer 2016-02-22 11:14:14 +01:00
parent 9611cfad89
commit 1c0b2b2087
48 changed files with 163 additions and 3975 deletions

View File

@ -1,562 +0,0 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2011 Goobi. Digitalisieren im Verein e.V. <contact@goobi.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*/
use \ElasticSearch\Client;
/**
* Elasticsearch class 'tx_dlf_elasticsearch' for the 'dlf' extension.
*
* @author Christopher Timm <timm@effective-webwork.de>
* @package TYPO3
* @subpackage tx_dlf
* @access public
*/
class tx_dlf_elasticsearch {
/**
* This holds the index name
*
* @var string
* @access protected
*/
protected $index = '';
/**
* This holds the type name
*
* @var string
* @access protected
*/
protected $type = '';
/**
* This holds the PID for the configuration
*
* @var integer
* @access protected
*/
protected $cPid = 0;
/**
* This holds the PID for the dpf API
*
* @var integer
* @access protected
*/
protected $apiPid = 0;
/**
* The extension key
*
* @var string
* @access public
*/
public static $extKey = 'dlf';
/**
* This holds the max results
*
* @var integer
* @access protected
*/
protected $limit = 50000;
/**
* This holds the number of hits for last search
*
* @var integer
* @access protected
*/
protected $numberOfHits = 0;
/**
* This holds the additional query parameters
*
* @var array
* @access protected
*/
protected $params = array ();
/**
* Is the search instantiated successfully?
*
* @var boolean
* @access protected
*/
protected $ready = FALSE;
/**
* This holds the singleton search objects with their core as array key
*
* @var array(tx_dlf_elasticsearch)
* @access protected
*/
protected static $registry = array ();
/**
* This holds the Elasticsearch service object
*
* @var ElasticSearchPhpClient
* @access protected
*/
protected $service;
/**
* This is a singleton class, thus instances must be created by this method
*
* @access public
*
* @param mixed $index: Name or UID of the index to load
*
* @return tx_dlf_solr Instance of this class
*/
public static function getInstance($index) {
// Save parameter for logging purposes.
$_index = $index;
// // Get core name if UID is given.
if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($index)) {
$index = tx_dlf_helper::getIndexName($index, 'tx_dlf_elasticsearchindexes');
}
// // Check if core is set.
if (empty($index)) {
if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_elasticsearch->getInstance('.$_index.')] Invalid index name "'.$index.'" for Elasticsearch', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return;
}
// Check if there is an instance in the registry already.
if (is_object(self::$registry[$index]) && self::$registry[$index] instanceof self) {
// Return singleton instance if available.
return self::$registry[$index];
}
// Create new instance...
$instance = new self($index);
// ...and save it to registry.
if ($instance->ready) {
self::$registry[$index] = $instance;
// Return new instance.
return $instance;
} else {
if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_elasticsearch->getInstance()] Could not connect to Elasticsearch server', self::$extKey, SYSLOG_SEVERITY_ERROR);
}
return;
}
}
/**
* Returns the request URL for a specific ElasticSearch index
*
* @access public
*
* @param string $index: Name of the index to load
*
* @return string The request URL for a specific index
*/
public static function getElasticSearchUrl($index = '') {
// Extract extension configuration.
$conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::$extKey]);
// Derive Elasticsearch host name.
$host = ($conf['elasticSearchHost'] ? $conf['elasticSearchHost'] : 'localhost');
// Set port if not set.
$port = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($conf['elasticSearchPort'], 1, 65535, 8180);
// Append core name to path.
$path = trim($conf['index'], '/').'/'.$type;
// Return entire request URL.
return 'http://'.$host.':'.$port.'/'.$path;
}
/**
* Processes a search request.
*
* @access public
*
* @param string $query: The search query
*
* @return tx_dlf_list The result list
*/
public function search($query = '') {
$esQuery['query']['bool']['should'][0]['query_string']['query'] = $query;
$esQuery['query']['bool']['should'][1]['has_child']['query']['query_string']['query'] = $query;
$esQuery['query']['bool']['minimum_should_match'] = "1"; // 1
$esQuery['query']['bool']['should'][1]['has_child']['child_type'] = "datastream"; // 1
// STATE inactive
$esQuery['query']['bool']['must'][] = array('match' => array('STATE' => 'A'));
$esQuery['size'] = $this->limit;
// perform search
$results = $this->service->search($esQuery);
$this->numberOfHits = $results['hits']['total'];
$toplevel = array ();
$checks = array ();
// Get metadata configuration.
if ($this->numberOfHits > 0) {
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_metadata.index_name AS index_name',
'tx_dlf_metadata',
'tx_dlf_metadata.is_sortable=1 AND tx_dlf_metadata.pid='.intval($this->cPid).tx_dlf_helper::whereClause('tx_dlf_metadata'),
'',
'',
''
);
$sorting = array ();
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
$sorting[$resArray['index_name']] = $resArray['index_name'].'_sorting';
}
}
foreach ($results['hits']['hits'] as $doc){
$toplevel[] = array (
'u' => $doc['_source']['PID'],
'h' => '',
's' => $doc['_score'],
'p' => array()
);
}
// Save list of documents.
$list = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_dlf_list');
$list->reset();
$list->add(array_values($toplevel));
// Set metadata for search.
$list->metadata = array (
'label' => '',
'description' => '',
'options' => array (
'source' => 'search',
'engine' => 'elasticsearch',
'select' => $query,
'userid' => 0,
'params' => $this->params,
'index' => $this->index,
'type' => $this->type,
'pid' => $this->cPid,
'apiPid' => $this->apiPid,
'order' => 'relevance',
'order.asc' => TRUE,
)
);
return $list;
}
/**
* This returns $this->limit via __get()
*
* @access protected
*
* @return integer The max number of results
*/
protected function _getLimit() {
return $this->limit;
}
/**
* This returns $this->numberOfHits via __get()
*
* @access protected
*
* @return integer Total number of hits for last search
*/
protected function _getNumberOfHits() {
return $this->numberOfHits;
}
/**
* This returns $this->ready via __get()
*
* @access protected
*
* @return boolean Is the search instantiated successfully?
*/
protected function _getReady() {
return $this->ready;
}
/**
* This returns $this->service via __get()
*
* @access protected
*
* @return Apache_Solr_Service Apache Solr service object
*/
protected function _getService() {
return $this->service;
}
/**
* This sets $this->cPid via __set()
*
* @access protected
*
* @param integer $value: The new PID for the metadata definitions
*
* @return void
*/
protected function _setCPid($value) {
$this->cPid = max(intval($value), 0);
}
/**
* This sets $this->apiPid via __set()
*
* @access protected
*
* @param integer $value: The new PID for the dpf API
*
* @return void
*/
protected function _setApiPid($value) {
$this->apiPid = max(intval($value), 0);
}
/**
* This sets $this->limit via __set()
*
* @access protected
*
* @param integer $value: The max number of results
*
* @return void
*/
protected function _setLimit($value) {
$this->limit = max(intval($value), 0);
}
/**
* This sets $this->params via __set()
*
* @access protected
*
* @param array $value: The query parameters
*
* @return void
*/
protected function _setParams(array $value) {
$this->params = $value;
}
/**
* This magic method is called each time an invisible property is referenced from the object
*
* @access public
*
* @param string $var: Name of variable to get
*
* @return mixed Value of $this->$var
*/
public function __get($var) {
$method = '_get'.ucfirst($var);
if (!property_exists($this, $var) || !method_exists($this, $method)) {
if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_elasticsearch->__get('.$var.')] There is no getter function for property "'.$var.'"', self::$extKey, SYSLOG_SEVERITY_WARNING);
}
return;
} else {
return $this->$method();
}
}
/**
* This magic method is called each time an invisible property is referenced from the object
*
* @access public
*
* @param string $var: Name of variable to set
* @param mixed $value: New value of variable
*
* @return void
*/
public function __set($var, $value) {
$method = '_set'.ucfirst($var);
if (!property_exists($this, $var) || !method_exists($this, $method)) {
if (TYPO3_DLOG) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_elasticsearch->__set('.$var.', [data])] There is no setter function for property "'.$var.'"', self::$extKey, SYSLOG_SEVERITY_WARNING, $value);
}
} else {
$this->$method($value);
}
}
/**
* This is a singleton class, thus the constructor should be private/protected
*
* @access protected
*
*
* @return void
*/
protected function __construct($index) {
$extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('dlf');
require_once $extensionPath . 'lib/ElasticSearchPhpClient/vendor/autoload.php';
//require_once(\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:'.self::$extKey.'/lib/ElasticSearchPhpClient/src/ElasticSearch/Client.php'));
// get configuration for elasticsearch
$conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::$extKey]);
// get host
$host = ($conf['elasticSearchHost'] ? $conf['elasticSearchHost'] : 'localhost');
// get port
$port = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($conf['elasticSearchPort'], 1, 65535, 9200);
// type
$type = 'object';
// configuration array for elasticsearch client
$params = array();
if ($conf['elasticSearchUser'] && $conf['elasticSearchPass']) {
// Authentication configuration
$params['connectionParams']['auth'] = array(
$conf['elasticSearchUser'],
$conf['elasticSearchPass'],
'Basic'
);
}
// establish connection
$this->service = Client::connection(
array(
'servers' => $host.':'.$port,
'protocol' => 'http',
'index' => $index,
'type' => $type
)
);
if ($this->service) {
$this->index = $index;
$this->type = $type;
// Instantiation successful!
$this->ready = TRUE;
} else {
// Instantiation not successful!
$this->ready = FALSE;
}
}
}
/* No xclasses allowed for singleton classes!
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/common/class.tx_dlf_solr.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/common/class.tx_dlf_solr.php']);
}
*/

View File

@ -490,7 +490,7 @@ class tx_dlf_helper {
// Sanitize input.
$uid = max(intval($uid), 0);
if (!$uid || !in_array($table, array ('tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures', 'tx_dlf_solrcores', 'tx_dlf_elasticsearchindexes'))) {
if (!$uid || !in_array($table, array ('tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures', 'tx_dlf_solrcores'))) {
if (TYPO3_DLOG) {

View File

@ -79,31 +79,6 @@ class tx_dlf_list implements ArrayAccess, Countable, Iterator, \TYPO3\CMS\Core\S
*/
protected $records = array ();
/**
* Instance of ElasticSearch PHP Client class
*
* @var Client
* @access protected
*/
protected $es;
/**
* Elasticsearch configuration
*
* @var array
* @access protected
*/
protected $esConfig = array();
/**
* Holds metadata for es
*
* @var array
* @access protected
*/
protected $metadataResult = array();
/**
* Instance of Apache_Solr_Service class
*
@ -282,8 +257,7 @@ class tx_dlf_list implements ArrayAccess, Countable, Iterator, \TYPO3\CMS\Core\S
}
} elseif (!empty($this->metadata['options']['source']) && $this->metadata['options']['source'] == 'search'
&& $this->metadata['options']['engine'] != 'elasticsearch') {
} elseif (!empty($this->metadata['options']['source']) && $this->metadata['options']['source'] == 'search') {
if ($this->solrConnect()) {
@ -329,38 +303,6 @@ class tx_dlf_list implements ArrayAccess, Countable, Iterator, \TYPO3\CMS\Core\S
}
} elseif (!empty($this->metadata['options']['source']) && $this->metadata['options']['source'] == 'search'
&& $this->metadata['options']['engine'] == 'elasticsearch') {
// connection established
if ($this->elasticsearchConnect()) {
// get result from record id
$this->es->service->setIndex($this->esConfig['index_name'])->setType($this->esConfig['type_name']);
$result = $this->es->service->get($record['uid']);
$metadata = $this->elasticsearchResultWalkRecursive($result);
}
$record['metadata'] = $metadata;
// now make real URIs out of uid
// Build typolink configuration array.
$conf = array (
'useCacheHash' => 1,
'parameter' => $this->metadata['options']['apiPid'],
'additionalParams' => '&tx_dpf[qid]=' . $record['uid'] . '&tx_dpf[action]=mets',
'forceAbsoluteUrl' => TRUE
);
// we need to make instance of cObj here because its not available in this context
$cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
// replace uid with URI to dpf API
$record['uid'] = $cObj->typoLink_URL($conf);
}
// Save record for later usage.
@ -382,46 +324,6 @@ class tx_dlf_list implements ArrayAccess, Countable, Iterator, \TYPO3\CMS\Core\S
}
/**
* Get all metadata from elasticsearch result recursive
* @param array $data data from elasticsearch
* @param string $keyPoint key from last point
* @return array Array with metadata
*/
public function elasticsearchResultWalkRecursive($data, $keyPoint = '') {
$metadata = array();
// try to get all metadata from elasticsearch result
foreach($data as $key => $value) {
if (!is_array($value)) {
if(is_int($key) && !empty($keyPoint)) {
$metadata[$keyPoint] = array($keyPoint => $value);
} else {
$metadata[$key] = array($key => $value);
}
} else {
$new_metadata = $this->elasticsearchResultWalkRecursive($value, $key);
if (is_array($new_metadata)) {
$metadata = array_merge($new_metadata, $metadata);
}
}
}
return $metadata;
}
/**
* This returns the current position
* @see Iterator::key()
@ -708,33 +610,6 @@ class tx_dlf_list implements ArrayAccess, Countable, Iterator, \TYPO3\CMS\Core\S
}
/**
* Connects to Elasticsearch server.
*
* @access protected
*
* @return boolean TRUE on success or FALSE on failure
*/
protected function elasticsearchConnect() {
if (!$this->es) {
// Connect to Solr server.
if (!$this->es = tx_dlf_elasticsearch::getInstance($this->metadata['options']['index'])) {
return FALSE;
}
$this->esConfig['index_name'] = $this->metadata['options']['index'];
$this->esConfig['type_name'] = $this->metadata['options']['type'];
}
return TRUE;
}
/**
* Connects to Solr server.
*

View File

@ -1,24 +1,24 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<!--
Copyright notice
(c) 2011 Goobi. Digitalisieren im Verein e.V. <contact@goobi.org>
All rights reserved
This script is part of the TYPO3 project. The TYPO3 project is
free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
The GNU General Public License can be found at
http://www.gnu.org/copyleft/gpl.html.
This script is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This copyright notice MUST APPEAR in all copies of the script!
-->
<T3locallang>
@ -68,14 +68,10 @@
<label index="flash.usergroupAddedMsg">Access to this SysFolder was granted for usergroup "_cli_dlf".</label>
<label index="flash.solrcoreOkay">Solr core found!</label>
<label index="flash.solrcoreOkayMsg">There are configuration records for Solr cores. They can be edited in the list module.</label>
<label index="flash.elasticsearchindexOkay">Elasticsearch index found!</label>
<label index="flash.elasticsearchindexOkayMsg">There are configuration records for Elasticsearch index. They can be edited in the list module.</label>
<label index="flash.solrcoreDeprecated">Deprecated configuration found!</label>
<label index="flash.solrcoreDeprecatedMsg">A common Solr core was found in the root-page. This is deprecated since Goobi.Presentation 1.1. Solr cores should be stored in the client's SysFolder instead. Move a Solr core to this SysFolder (manually) or create a new one automatically.&lt;br /&gt;&lt;br /&gt;&lt;a href="%s"&gt;Create new Solr core!&lt;/a&gt;</label>
<label index="flash.solrcoreMissing">No Solr core found!</label>
<label index="flash.solrcoreMissingMsg">There is no Solr core configured. For the search plugin at least one Solr core is needed. It can be created automatically.&lt;br /&gt;&lt;br /&gt;&lt;a href="%s"&gt;Create new Solr core!&lt;/a&gt;</label>
<label index="flash.elasticsearchindexMissing">No Elasticsearch index found!</label>
<label index="flash.elasticsearchindexMissingMsg">There is no Elasticsearch index configured. For the search plugin at least one Elasticsearch index or Solr core is needed. It can be added.&lt;br /&gt;&lt;br /&gt;&lt;a href="%s"&gt;Add new Elasticsearch index!&lt;/a&gt;</label>
<label index="flash.solrcoreAdded">Solr core created!</label>
<label index="flash.solrcoreAddedMsg">A new Solr core was created. It can be edited in the list module.</label>
<label index="flash.solrcoreNotAdded">No Solr core created!</label>
@ -125,14 +121,10 @@
<label index="flash.usergroupAddedMsg">Der Benutzergruppe "_cli_dlf" wurden die nötigen Zugriffsrechte für diesen SysOrdner erteilt.</label>
<label index="flash.solrcoreOkay">Solr Kern gefunden!</label>
<label index="flash.solrcoreOkayMsg">Es wurde die Konfiguration für einen Solr Kern gefunden. Über das Listenmodul können neue Datensätze hinzugefügt und die vorhandenen editiert werden.</label>
<label index="flash.elasticsearchindexOkay">Elasticsearch Index gefunden!</label>
<label index="flash.elasticsearchindexOkayMsg">Es wurde die Konfiguration für einen Elasticsearch Index gefunden. Über das Listenmodul können neue Datensätze hinzugefügt und die vorhandenen editiert werden.</label>
<label index="flash.solrcoreDeprecated">Veraltete Konfiguration gefunden!</label>
<label index="flash.solrcoreDeprecatedMsg">Es wurde ein allgemeiner Solr Kern in der Root-Page gefunden. Das entspricht dem Verhalten von Goobi.Presentation 1.0. Seit Version 1.1 sollten Solr Kerne im SysOrdner des jeweiligen Mandanten konfiguriert werden. Es sollte entweder einer der Solr Kerne aus der Root-Page in diesen SysOrdner verschoben werden (manuell) oder ein neuer Solr Kern angelegt werden.&lt;br /&gt;&lt;br /&gt;&lt;a href="%s"&gt;Neuen Solr Kern jetzt anlegen!&lt;/a&gt;</label>
<label index="flash.solrcoreMissing">Kein Solr Kern gefunden!</label>
<label index="flash.solrcoreMissingMsg">Es wurde kein Solr Kern gefunden. Ohne Solr Kern kann das Plugin zur Recherche in den Meta- und Strukturdaten nicht verwendet werden. Ein Solr Kern kann automatisch angelegt werden.&lt;br /&gt;&lt;br /&gt;&lt;a href="%s"&gt;Solr Kern jetzt anlegen!&lt;/a&gt;</label>
<label index="flash.elasticsearchindexMissing">Kein Elasticsearch Index gefunden!</label>
<label index="flash.elasticsearchindexMissingMsg">Es wurde kein Elasticsearch Index gefunden. Ohne Elasticsearch/Solr kann das Plugin zur Recherche in den Meta- und Strukturdaten nicht verwendet werden. Ein Elasticsearch Index muss angegeben werden.&lt;br /&gt;&lt;br /&gt;&lt;a href="%s"&gt;Elasticsearch Index jetzt angeben!&lt;/a&gt;</label>
<label index="flash.solrcoreAdded">Solr Kern angelegt!</label>
<label index="flash.solrcoreAddedMsg">Es wurde ein Solr Kern angelegt. Über das Listenmodul können neue Datensätze hinzugefügt und die vorhandenen editiert werden.</label>
<label index="flash.solrcoreNotAdded">Kein Solr Kern angelegt!</label>

View File

@ -37,7 +37,6 @@ return array (
'tx_dlf_module' => $extensionPath.'common/class.tx_dlf_module.php',
'tx_dlf_plugin' => $extensionPath.'common/class.tx_dlf_plugin.php',
'tx_dlf_solr' => $extensionPath.'common/class.tx_dlf_solr.php',
'tx_dlf_elasticsearch' => $extensionPath.'common/class.tx_dlf_elasticsearch.php',
'tx_dlf_teihdr' => $extensionPath.'common/class.tx_dlf_teihdr.php',
'tx_dlf_em' => $extensionPath.'hooks/class.tx_dlf_em.php',
'tx_dlf_hacks' => $extensionPath.'hooks/class.tx_dlf_hacks.php',
@ -60,7 +59,6 @@ return array (
'tx_dlf_toolbox' => $extensionPath.'plugins/toolbox/class.tx_dlf_toolbox.php',
'tx_dlf_toolsPdf' => $extensionPath.'plugins/toolbox/tools/pdf/class.tx_dlf_toolsPdf.php',
'tx_dlf_toolsFulltext' => $extensionPath.'plugins/toolbox/tools/fulltext/class.tx_dlf_toolsFulltext.php',
'tx_dlf_toolsPublicationDownload' => $extensionPath.'plugins/toolbox/tools/publicationDownload/class.tx_dlf_toolsPublicationDownload.php',
'tx_dlf_validator' => $extensionPath.'plugins/validator/class.tx_dlf_validator.php',
'tx_dlf_doctype' => $extensionPath.'plugins/doctype/class.tx_dlf_doctype.php',
);

View File

@ -48,24 +48,3 @@ solrUser =
# cat=Solr; type=string; label=LLL:EXT:dlf/locallang.xml:config.solrPass
solrPass =
# cat=Elasticsearch; type=user[EXT:dlf/hooks/class.tx_dlf_em.php:tx_dlf_em->checkElasticsearchConnection]; label=LLL:EXT:dlf/locallang.xml:config.elasticSearchConnect
elasticSearchConnect = 0
# cat=Elasticsearch; type=string; label=LLL:EXT:dlf/locallang.xml:config.elasticSearchHost
elasticSearchHost = localhost
# cat=Elasticsearch; type=int[0-65535]; label=LLL:EXT:dlf/locallang.xml:config.elasticSearchPort
elasticSearchPort = 9200
# cat=Elasticsearch; type=string; label=LLL:EXT:dlf/locallang.xml:config.elasticSearchIndex
elasticSearchIndex = index
# cat=Elasticsearch; type=string; label=LLL:EXT:dlf/locallang.xml:config.elasticSearchType
elasticSearchType = type
# cat=Elasticsearch; type=string; label=LLL:EXT:dlf/locallang.xml:config.elasticSearchUser
elasticSearchUser =
# cat=Elasticsearch; type=string; label=LLL:EXT:dlf/locallang.xml:config.elasticSearchPass
elasticSearchPass =

View File

@ -58,9 +58,6 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/plugins/toolbox/tools'][\TYPO3\CM
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPItoST43($_EXTKEY, 'plugins/toolbox/tools/fulltext/class.tx_dlf_toolsFulltext.php', '_toolsFulltext', '', TRUE);
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/plugins/toolbox/tools'][\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getCN($_EXTKEY).'_toolsFulltext'] = 'LLL:EXT:dlf/locallang.xml:tx_dlf_toolbox.toolsFulltext';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPItoST43($_EXTKEY, 'plugins/toolbox/tools/publicationDownload/class.tx_dlf_toolsPublicationDownload.php', '_toolsPublicationDownload', '', TRUE);
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/plugins/toolbox/tools'][\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getCN($_EXTKEY).'_toolsPublicationDownload'] = 'LLL:EXT:dlf/locallang.xml:tx_dlf_toolbox.toolsPublicationDownload';
// Register hooks.
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'EXT:'.$_EXTKEY.'/hooks/class.tx_dlf_tcemain.php:tx_dlf_tcemain';
@ -76,7 +73,6 @@ $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['tx_dlf_search_suggest'] = 'EXT
$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['tx_dlf_fulltext_eid'] = 'EXT:'.$_EXTKEY.'/plugins/pageview/class.tx_dlf_fulltext_eid.php';
if (TYPO3_MODE === 'FE') {
/*
@ -86,16 +82,12 @@ if (TYPO3_MODE === 'FE') {
* DOCTYPE: document type string to test
*
* [userFunc = user_dlf_docTypeCheck(STORAGEID:DOCTYPE)]
*
* do something different
*
* ...
* [global]
*
**/
function user_dlf_docTypeCheck($cmd) {
// we have to split the cmd as we cannot have two parameters.
// this changed in TYPO3 6.2
$pidCondition = explode(':', $cmd);
$conf['pages'] = $pidCondition[0];
@ -103,26 +95,45 @@ if (TYPO3_MODE === 'FE') {
$docType = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_dlf_doctype');
switch($pidCondition[1]){
case "periodical":
if ($docType->main($cObj, $conf) === "periodical")
return TRUE;
break;
break;
case "newspaper_global_anchor":
if ($docType->main($cObj, $conf) === "newspaper_global_anchor")
return TRUE;
break;
break;
case "newspaper_year_anchor":
if ($docType->main($cObj, $conf) === "newspaper_year_anchor")
return TRUE;
break;
break;
case "newspaper_issue":
if ($docType->main($cObj, $conf) === "newspaper_issue")
return TRUE;
break;
default : return FALSE;
break;
default:
return FALSE;
}
// this function has to return FALSE or TRUE nothing else
return FALSE;
}
}

View File

@ -165,26 +165,6 @@ $TCA['tx_dlf_solrcores'] = array (
)
);
$TCA['tx_dlf_elasticsearchindexes'] = array (
'ctrl' => array (
'title' => 'LLL:EXT:dlf/locallang.xml:tx_dlf_elasticsearchindexes',
'label' => 'label',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'default_sortby' => 'ORDER BY label',
'delete' => 'deleted',
'dynamicConfigFile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY).'tca.php',
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($_EXTKEY).'res/icons/txdlfsolrcores.png',
'rootLevel' => -1,
'dividers2tabs' => 2,
'searchFields' => 'label,index_name, type_name',
),
'feInterface' => array (
'fe_admin_fieldList' => '',
)
);
$TCA['tx_dlf_collections'] = array (
'ctrl' => array (
'title' => 'LLL:EXT:dlf/locallang.xml:tx_dlf_collections',

View File

@ -35,7 +35,7 @@ CREATE TABLE tx_dlf_documents (
owner int(11) DEFAULT '0' NOT NULL,
solrcore int(11) DEFAULT '0' NOT NULL,
status tinyint(4) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid),
INDEX partof (partof)
@ -160,25 +160,6 @@ CREATE TABLE tx_dlf_solrcores (
INDEX index_name (index_name(32))
);
--
-- Table structure for table 'tx_dlf_elasticsearchindexes'
--
CREATE TABLE tx_dlf_elasticsearchindexes (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
tstamp int(11) DEFAULT '0' NOT NULL,
crdate int(11) DEFAULT '0' NOT NULL,
cruser_id int(11) DEFAULT '0' NOT NULL,
deleted tinyint(4) DEFAULT '0' NOT NULL,
label tinytext NOT NULL,
index_name tinytext NOT NULL,
type_name tinytext NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid),
INDEX index_name (index_name(32))
);
--
-- Table structure for table 'tx_dlf_collections'
--

View File

@ -131,92 +131,6 @@ class tx_dlf_em {
}
/**
* Check if a connection to a Elasticsearch server could be established with the given credentials.
*
* @access public
*
* @param array &$params: An array with parameters
* @param \TYPO3\CMS\Core\TypoScript\ConfigurationForm &$pObj: The parent object
*
* @return string Message informing the user of success or failure
*/
public function checkElasticsearchConnection(&$params, &$pObj) {
// Prepend username and password to hostname.
if (!empty($this->conf['elasticSearchUser']) && !empty($this->conf['elasticSearchPass'])) {
$host = $this->conf['elasticSearchUser'].':'.$this->conf['elasticSearchPass'].'@'.(!empty($this->conf['elasticSearchHost']) ? $this->conf['elasticSearchHost'] : 'localhost');
} else {
$host = (!empty($this->conf['elasticSearchHost']) ? $this->conf['elasticSearchHost'] : 'localhost');
}
// Set port if not set.
$port = (!empty($this->conf['elasticSearchPort']) ? \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->conf['elasticSearchPort'], 0, 65535, 9200) : 9200);
// Build request URI.
$url = 'http://'.$host.':'.$port.'/';
//$url = 'http://127.0.0.1:9200';
$context = stream_context_create(array (
'http' => array (
'method' => 'GET',
'user_agent' => (!empty($this->conf['useragent']) ? $this->conf['useragent'] : ini_get('user_agent'))
)
));
$response = json_decode(@file_get_contents($url, FALSE, $context));
if ($response) {
if ($response->status == "200") {
$message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
sprintf($GLOBALS['LANG']->getLL('elasticSearch.status'), (string) $response->status),
$GLOBALS['LANG']->getLL('solr.connected'),
($status[0] == 0 ? \TYPO3\CMS\Core\Messaging\FlashMessage::OK : \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING),
FALSE
);
$this->content .= $message->render();
return $this->content;
} else {
$message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
sprintf($GLOBALS['LANG']->getLL('elasticSearch.error'), $url),
$GLOBALS['LANG']->getLL('solr.notConnected'),
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
FALSE
);
$this->content .= $message->render();
return $this->content;
}
} else {
$message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
sprintf($GLOBALS['LANG']->getLL('elasticSearch.error'), $url),
$GLOBALS['LANG']->getLL('solr.notConnected'),
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
FALSE
);
$this->content .= $message->render();
return $this->content;
}
$extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('dlf');
}
/**
* Make sure a backend user exists and is configured properly.
*
@ -415,8 +329,7 @@ class tx_dlf_em {
'tx_dlf_metadata',
'tx_dlf_metadataformat',
'tx_dlf_formats',
'tx_dlf_solrcores',
'tx_dlf_elasticsearchindexes'
'tx_dlf_solrcores'
),
'tables_modify' => array (
'tx_dlf_documents',

View File

@ -340,61 +340,6 @@ class tx_dlf_tceforms {
}
/**
* Helper to get flexform's items array for plugin "tx_dlf_search"
*
* @access public
*
* @param array &$params: An array with parameters
* @param \TYPO3\CMS\Core\TypoScript\ConfigurationForm &$pObj: The parent object
*
* @return void
*/
public function itemsProcFunc_elasticsearchList(&$params, &$pObj) {
if ($params['row']['pi_flexform']) {
$pi_flexform = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($params['row']['pi_flexform']);
$pages = $pi_flexform['data']['sDEF']['lDEF']['pages']['vDEF'];
// There is a strange behavior where the uid from the flexform is prepended by the table's name and appended by its title.
// i.e. instead of "18" it reads "pages_18|Title"
if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($pages)) {
$parts = explode('|', $pages);
$pages = array_pop(explode('_', $parts[0]));
}
if ($pages > 0) {
$result_elasticsearch = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'label,uid',
'tx_dlf_elasticsearchindexes',
'pid IN ('.intval($pages).',0)'.tx_dlf_helper::whereClause('tx_dlf_elasticsearchindexes'),
'',
'label',
''
);
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result_elasticsearch) > 0) {
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_row($result_elasticsearch)) {
$params['items'][] = $resArray;
}
}
}
}
}
/**
* Helper to get flexform's items array for plugin "tx_dlf_toolbox"
*

View File

@ -1,19 +0,0 @@
Copyright (c) 2010-2012 Raymond Julin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -1,171 +0,0 @@
[![Build Status](https://secure.travis-ci.org/nervetattoo/elasticsearch.png?branch=master)](http://travis-ci.org/nervetattoo/elasticsearch)
# ElasticSearch PHP client
ElasticSearch is a distributed lucene powered search indexing, this is a PHP client for it
## Usage
### Initial setup
1. Install composer. `curl -s http://getcomposer.org/installer | php`
2. Create `composer.json` containing:
```js
{
"require" : {
"nervetattoo/elasticsearch" : ">=2.0"
}
}
```
3. Run `./composer.phar install`
4. Keep up-to-date: `./composer.phar update`
### Indexing and searching
```php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use \ElasticSearch\Client;
// The recommended way to go about things is to use an environment variable called ELASTICSEARCH_URL
$es = Client::connection();
// Alternatively you can use dsn string
$es = Client::connection('http://127.0.0.1:9200/myindex/mytype');
$es->index(array('title' => 'My cool document'), $id);
$es->get($id);
$es->search('title:cool');
```
### Creating mapping
```php
<?php
$es->map(array(
'title' => array(
'type' => 'string',
'index' => 'analyzed'
)
));
```
### Search multiple indexes or types
```php
<?php
$results = $es
->setIndex(array("one", "two"))
->setType(array("mytype", "other-type"))
->search('title:cool');
```
### Using the Query DSL
```php
<?php
$es->search(array(
'query' => array(
'term' => array('title' => 'cool')
)
);
```
### Provide configuration as array
Using an array for configuration also works
```php
<?php
$es = Client::connection(array(
'servers' => '127.0.0.1:9200',
'protocol' => 'http',
'index' => 'myindex',
'type' => 'mytype'
));
```
### Support for Routing
```php
<?php
$document = array(
'title' => 'My routed document',
'user_id' => '42'
);
$es->index($document, $id, array('routing' => $document['user_id']));
$es->search('title:routed', array('routing' => '42'));
```
### Support for Bulking
```php
<?php
$document = array(
'title' => 'My bulked entry',
'user_id' => '43'
);
$es->beginBulk();
$es->index($document, $id, array('routing' => $document['user_id']));
$es->delete(2);
$es->delete(3);
$es->commitBulk();
$es->createBulk()
->delete(4)
->index($document, $id, 'myIndex', 'myType', array('parent' => $parentId));
->delete(5)
->delete(6)
->commit();
```
### Usage as a service in Symfony2
In order to use the Dependency Injection to inject the client as a service, you'll have to define it before.
So in your bundle's services.yml file you can put something like this :
```yml
your_bundle.elastic_transport:
class: ElasticSearch\Transport\HTTP
arguments:
- localhost
- 9200
- 60
your_bundle.elastic_client:
class: ElasticSearch\Client
arguments:
- @your_bundle.elastic_transport
```
To make Symfony2 recognize the `ElasticSearch` namespace, you'll have to register it. So in your `app/autoload.php` make sure your have :
```php
<?php
// ...
$loader->registerNamespaces(array(
// ...
'ElasticSearch' => __DIR__.'/path/to/your/vendor/nervetattoo/elasticsearch/src',
));
```
Then, you can get your client via the service container and use it like usual. For example, in your controller you can do this :
```php
<?php
class FooController extends Controller
{
// ...
public function barAction()
{
// ...
$es = $this->get('your_bundle.elastic_client');
$results = $es
->setIndex(array("one", "two"))
->setType(array("mytype", "other-type"))
->search('title:cool');
}
}
```

View File

@ -1,25 +0,0 @@
{
"name" : "nervetattoo/elasticsearch",
"type" : "library",
"description" : "ElasticSearch client for PHP 5.3",
"keywords" : ["elasticsearch", "client"],
"homepage" : "http://github.com/nervetattoo/elasticsearch",
"license" : "MIT",
"authors" : [
{
"name" : "Raymond Julin",
"email" : "raymond.julin@gmail.com",
"homepage" : "http://raymondjulin.com"
}
],
"require" : {
"php" : ">=5.3.0"
},
"require-dev" : {
},
"autoload" : {
"psr-0" : {
"ElasticSearch" : "src/"
}
}
}

View File

@ -1,20 +0,0 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "40a916dc0130bdf0ac7c2000d95c6b6b",
"content-hash": "e75d307570427808299af845315e7e93",
"packages": [],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=5.3.0"
},
"platform-dev": []
}

View File

@ -1,184 +0,0 @@
From: http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/549fb5ede5df6ff4/0890e504cc13d486
QUERY DSL SPEC: (better read in fixed-width font)
--------------------------------------------------
curl -XGET 'http://$server/_search -d '{ TOPLEVEL }'
curl -XGET 'http://$server/_all/_search -d '{ TOPLEVEL }'
curl -XGET 'http://$server/_all/$types/_search -d '{ TOPLEVEL }'
curl -XGET 'http://$server/$indices/_search -d '{ TOPLEVEL }'
curl -XGET 'http://$server/$indices/$types/_search -d '{ TOPLEVEL }'
TOPLEVEL:
---------
{
explain: BOOL,
from: INT,
size: INT,
fields: ["field_1", "field_n"],
query: { QUERY_CLAUSE },
facets: { FACETS_CLAUSE },
sort: { SORT_CLAUSE }
}
QUERY_CLAUSE:
-------------
{
term: { TERM_QUERY }
| range: { RANGE_QUERY }
| prefix: { PREFIX_QUERY }
| wildcard: { WILDCARD_QUERY }
| matchAll: { MATCH_ALL_QUERY }
| queryString: { QUERY_STRING_QUERY }
| bool: { BOOLEAN_QUERY }
| disMax: { DISMAX_QUERY }
| constantScore: { CONSTANT_SCORE_QUERY }
| filteredQuery: { FILTERED_QUERY },
}
FILTER_CLAUSE:
--------------
{
query: { QUERY_CLAUSE },
| term: { TERM_FILTER },
| range: { RANGE_FILTER },
| prefix: { PREFIX_FILTER },
| wildcard: { WILDCARD_FILTER },
| bool: { BOOLEAN_FILTER },
| constantScore: { CONSTANT_SCORE_QUERY }
}
FACETS_CLAUSE:
--------------
{
$facet_name_1: { QUERY_CLAUSE },
$facet_name_n: ...
}
SORT_CLAUSE:
------------
[
$fieldname_1 | "score
| { $fieldname_1 : { reverse: BOOL }},
...
]
TERM_FILTER:
------------
{ $fieldname: VALUE_1 }
TERM_QUERY:
-----------
{ $fieldname: VALUE_1 }
| { $fieldname: { value: VALUE, boost: FLOAT } }
PREFIX_FILTER:
--------------
{ $fieldname: STRING}
PREFIX_QUERY:
-------------
{ $fieldname: STRING}
| { $fieldname: { prefix: STRING_1, boost: FLOAT } }
WILDCARD_FILTER:
----------------
{ $fieldname: STRING }
WILDCARD_QUERY:
---------------
{ $fieldname: STRING }
| { $fieldname: { wildcard: STRING, boost: FLOAT } }
MATCH_ALL_QUERY:
----------------
{}
| { boost: FLOAT }
RANGE_FILTER:
-------------
{ $fieldname: {
from: INT | FLOAT | STRING | DATETIME,
to: INT | FLOAT | STRING | DATETIME,
includeLower: BOOL,
includeUpper: BOOL,
}}
RANGE_QUERY:
------------
{ $fieldname: {
from: INT | FLOAT | STRING | DATETIME,
to: INT | FLOAT | STRING | DATETIME,
includeLower: BOOL
includeUpper: BOOL
boost: FLOAT
}}
BOOLEAN_FILTER:
---------------
{
must: { FILTER_CLAUSE } | [ { FILTER_CLAUSE }, ... ],
should: { FILTER_CLAUSE } | [ { FILTER_CLAUSE }, ... ],
mustNot: { FILTER_CLAUSE } | [ { FILTER_CLAUSE }, ... ],
minimumNumberShouldMatch: INT
}
BOOLEAN_QUERY:
--------------
{
must: { QUERY_CLAUSE} | [ { QUERY_CLAUSE }, ... ],
should: { QUERY_CLAUSE} | [ { QUERY_CLAUSE }, ... ],
mustNot: { QUERY_CLAUSE} | [ { QUERY_CLAUSE }, ... ],
boost: FLOAT,
minimumNumberShouldMatch: INT
}
DISMAX_QUERY:
-------------
{
queries: [ { QUERY_CLAUSE }, ... ],
tieBreakerMultiplier: FLOAT,
boost: FLOAT
}
CONSTANT_SCORE_QUERY:
---------------------
{
filter: { FILTER_CLAUSE }
boost: FLOAT
}
FILTERED_QUERY:
---------------
{
query: { QUERY_CLAUSE },
filter: { FILTER_CLAUSE, ... }
}
QUERY_STRING_QUERY:
-------------------
{
query: STRING,
defaultField: $fieldname,
defaultOperator: "AND" | "OR",
analyzer: STRING,
allowLeadingWildcard: BOOL,
lowercaseExpandedTerms: BOOL,
enablePositionIncrements: BOOL,
fuzzyPrefixLength: BOOL,
fuzzyMinSim: FLOAT,
phraseSlop: INT,
boost: FLOAT
}
ARGUMENT TYPES:
---------------
- BOOL: true | false
- INT: integer eg 5
- FLOAT: float eg 1.2
- STRING: text eg "foo"
- DATETIME: dates and times
eg "2010-02-31T13:30:45", "2010-02-31", "13:30:45"
- VALUE: BOOL | INT | FLOAT | STRING | DATETIME

View File

@ -1 +0,0 @@
./vendor/bin/atoum --ulr -d tests/units

View File

@ -1,118 +0,0 @@
<?php // vim:set ts=4 sw=4 et:
namespace ElasticSearch;
class Bulk {
private $client;
private $operations = array();
/**
* Construct a bulk operation
*
* @param \ElasticSearch\Client
*/
public function __construct(Client $client) {
$this->client = $client;
}
/**
* commit this operation
*/
public function commit() {
return $this->client->request('/_bulk', 'POST', $this->createPayload());
}
/**
* reset this operation
*/
public function reset() {
$this->operations = array();
}
/**
* Index a new document or update it if existing
*
* @param array $document
* @param mixed $id Optional
* @param string $index Index
* @param string $type Type
* @param array $options Allow sending query parameters to control indexing further
* _refresh_ *bool* If set to true, immediately refresh the shard after indexing
* @return \Elasticsearch\Bulk
*/
public function index($document, $id=null, $index, $type, array $options = array()) {
$params = array( '_id' => $id,
'_index' => $index,
'_type' => $type);
foreach ($options as $key => $value) {
$params['_' . $key] = $value;
}
$operation = array(
array('index' => $params),
$document
);
$this->operations[] = $operation;
return $this;
}
/**
* delete a document
*
* @param mixed $id
* @param string $index Index
* @param string $type Type
* @param array $options Parameters to pass to delete action
* @return \Elasticsearch\Bulk
*/
public function delete($id=false, $index, $type, array $options = array()) {
$params = array( '_id' => $id,
'_index' => $index,
'_type' => $type);
foreach ($options as $key => $value) {
$params['_' . $key] = $value;
}
$operation = array(
array('delete' => $params)
);
$this->operations[] = $operation;
return $this;
}
/**
* get all pending operations
* @return array
*/
public function getOperations() {
return $this->operations;
}
/**
* count all pending operations
* @return int
*/
public function count() {
return count($this->operations);
}
/**
* create a request payload with all pending operations
* @return string
*/
public function createPayload()
{
$payloads = array();
foreach ($this->operations as $operation) {
foreach ($operation as $partial) {
$payloads[] = json_encode($partial);
}
}
return join("\n", $payloads)."\n";
}
}

View File

@ -1,343 +0,0 @@
<?php // vim:set ts=4 sw=4 et:
namespace ElasticSearch;
/**
* This file is part of the ElasticSearch PHP client
*
* (c) Raymond Julin <raymond.julin@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Client {
const DEFAULT_PROTOCOL = 'http';
const DEFAULT_SERVER = '127.0.0.1:9200';
const DEFAULT_INDEX = 'default-index';
const DEFAULT_TYPE = 'default-type';
protected $_config = array();
protected static $_defaults = array(
'protocol' => Client::DEFAULT_PROTOCOL,
'servers' => Client::DEFAULT_SERVER,
'index' => Client::DEFAULT_INDEX,
'type' => Client::DEFAULT_TYPE,
'timeout' => null,
);
protected static $_protocols = array(
'http' => 'ElasticSearch\\Transport\\HTTP',
'memcached' => 'ElasticSearch\\Transport\\Memcached',
);
private $transport, $index, $type, $bulk;
/**
* Construct search client
*
* @return \ElasticSearch\Client
* @param \ElasticSearch\Transport\Base $transport
* @param string $index
* @param string $type
*/
public function __construct($transport, $index = null, $type = null) {
$this->transport = $transport;
$this->setIndex($index)->setType($type);
}
/**
* Get a client instance
* Defaults to opening a http transport connection to 127.0.0.1:9200
*
* @param string|array $config Allow overriding only the configuration bits you desire
* - _transport_
* - _host_
* - _port_
* - _index_
* - _type_
* @throws \Exception
* @return \ElasticSearch\Client
*/
public static function connection($config = array()) {
if (!$config && ($url = getenv('ELASTICSEARCH_URL'))) {
$config = $url;
}
if (is_string($config)) {
$config = self::parseDsn($config);
}
$config += self::$_defaults;
$protocol = $config['protocol'];
if (!isset(self::$_protocols[$protocol])) {
throw new \Exception("Tried to use unknown protocol: $protocol");
}
$class = self::$_protocols[$protocol];
if (null !== $config['timeout'] && !is_numeric($config['timeout'])) {
throw new \Exception("HTTP timeout should have a numeric value when specified.");
}
$server = is_array($config['servers']) ? $config['servers'][0] : $config['servers'];
list($host, $port) = explode(':', $server);
$transport = new $class($host, $port, $config['timeout']);
$client = new self($transport, $config['index'], $config['type']);
$client->config($config);
return $client;
}
/**
* @param array|null $config
* @return array|void
*/
public function config($config = null) {
if (!$config)
return $this->_config;
if (is_array($config))
$this->_config = $config + $this->_config;
}
/**
* Change what index to go against
* @return \ElasticSearch\Client
* @param mixed $index
*/
public function setIndex($index) {
if (is_array($index))
$index = implode(",", array_filter($index));
$this->index = $index;
$this->transport->setIndex($index);
return $this;
}
/**
* Change what types to act against
* @return \ElasticSearch\Client
* @param mixed $type
*/
public function setType($type) {
if (is_array($type))
$type = implode(",", array_filter($type));
$this->type = $type;
$this->transport->setType($type);
return $this;
}
/**
* Fetch a document by its id
*
* @return array
* @param mixed $id Optional
* @param bool $verbose
*/
public function get($id, $verbose=false) {
return $this->request($id, "GET");
}
/**
* Puts a mapping on index
*
* @param array|object $mapping
* @param array $config
* @throws Exception
* @return array
*/
public function map($mapping, array $config = array()) {
if (is_array($mapping)) $mapping = new Mapping($mapping);
$mapping->config($config);
try {
$type = $mapping->config('type');
}
catch (\Exception $e) {} // No type is cool
if (isset($type) && !$this->passesTypeConstraint($type)) {
throw new Exception("Cant create mapping due to type constraint mismatch");
}
return $this->request('_mapping', 'PUT', $mapping->export(), true);
}
protected function passesTypeConstraint($constraint) {
if (is_string($constraint)) $constraint = array($constraint);
$currentType = explode(',', $this->type);
$includeTypes = array_intersect($constraint, $currentType);
return ($constraint && count($includeTypes) === count($constraint));
}
/**
* Perform a raw request
*
* Usage example
*
* $response = $client->request('_status', 'GET');
*
* @return array
* @param mixed $path Request path to use.
* `type` is prepended to this path inside request
* @param string $method HTTP verb to use
* @param mixed $payload Array of data to be json-encoded
* @param bool $verbose Controls response data, if `false`
* only `_source` of response is returned
*/
public function request($path, $method = 'GET', $payload = false, $verbose=false) {
$response = $this->transport->request($this->expandPath($path), $method, $payload);
return ($verbose || !isset($response['_source']))
? $response
: $response['_source'];
}
/**
* Index a new document or update it if existing
*
* @return array
* @param array $document
* @param mixed $id Optional
* @param array $options Allow sending query parameters to control indexing further
* _refresh_ *bool* If set to true, immediately refresh the shard after indexing
*/
public function index($document, $id=false, array $options = array()) {
if ($this->bulk) {
return $this->bulk->index($document, $id, $this->index, $this->type, $options);
}
return $this->transport->index($document, $id, $options);
}
/**
* Perform search, this is the sweet spot
*
* @return array
* @param $query
* @param array $options
*/
public function search($query, array $options = array()) {
$start = microtime(true);
$result = $this->transport->search($query, $options);
$result['time'] = microtime(true) - $start;
return $result;
}
/**
* Flush this index/type combination
*
* @return array
* @param mixed $id If id is supplied, delete that id for this index
* if not wipe the entire index
* @param array $options Parameters to pass to delete action
*/
public function delete($id=false, array $options = array()) {
if ($this->bulk) {
return $this->bulk->delete($id, $this->index, $this->type, $options);
}
return $this->transport->delete($id, $options);
}
/**
* Flush this index/type combination
*
* @return array
* @param mixed $query Text or array based query to delete everything that matches
* @param array $options Parameters to pass to delete action
*/
public function deleteByQuery($query, array $options = array()) {
return $this->transport->deleteByQuery($query, $options);
}
/**
* Perform refresh of current indexes
*
* @return array
*/
public function refresh() {
return $this->transport->request(array('_refresh'), 'GET');
}
/**
* Expand a given path (array or string)
* If this is not an absolute path index + type will be prepended
* If it is an absolute path it will be used as is
*
* @param mixed $path
* @return array
*/
protected function expandPath($path) {
$path = (array) $path;
$isAbsolute = $path[0][0] === '/';
return $isAbsolute
? $path
: array_merge((array) $this->type, $path);
}
/**
* Parse a DSN string into an associative array
*
* @param string $dsn
* @return array
*/
protected static function parseDsn($dsn) {
$parts = parse_url($dsn);
$protocol = $parts['scheme'];
$servers = $parts['host'] . ':' . $parts['port'];
if (isset($parts['path'])) {
$path = explode('/', $parts['path']);
list($index, $type) = array_values(array_filter($path));
}
return compact('protocol', 'servers', 'index', 'type');
}
/**
* Create a bulk-transaction
*
* @return \Elasticsearch\Bulk
*/
public function createBulk() {
return new Bulk($this);
}
/**
* Begin a transparent bulk-transaction
* if one is already running, return its handle
* @return \Elasticsearch\Bulk
*/
public function beginBulk() {
if (!$this->bulk) {
$this->bulk = $this->createBulk($this);
}
return $this->bulk;
}
/**
* @see beginBulk
*/
public function begin() {
return $this->beginBulk();
}
/**
* commit a bulk-transaction
* @return array
*/
public function commitBulk() {
if ($this->bulk) {
$result = $this->bulk->commit();
$this->bulk = null;
return $result;
}
}
/**
* @see commitBulk
*/
public function commit() {
return $this->commitBulk();
}
}

View File

@ -1,79 +0,0 @@
<?php // vim:set ts=4 sw=4 et:
namespace ElasticSearch\DSL;
/**
* This file is part of the ElasticSearch PHP client
*
* (c) Raymond Julin <raymond.julin@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Helper stuff for working with the ElasticSearch DSL
* How to build a mildly complex query:
* $dsl = new ElasticSearchDSL;
* $bool = $dsl->bool(); // Return a new bool structure
*
* @author Raymond Julin <raymond.julin@gmail.com>
* @package ElasticSearchClient
* @since 0.1
* Created: 2010-07-23
*/
class Builder {
protected $dsl = array();
private $explain = null;
private $from = null;
private $size = null;
private $fields = null;
private $query = null;
private $facets = null;
private $sort = null;
/**
* Construct DSL object
*
* @return \ElasticSearch\DSL\Builder
* @param array $options
*/
public function __construct(array $options=array()) {
foreach ($options as $key => $value)
$this->$key = $value;
}
/**
* Add array clause, can only be one
*
* @return \ElasticSearch\DSL\Query
* @param array $options
*/
public function query(array $options=array()) {
if (!($this->query instanceof Query))
$this->query = new Query($options);
return $this->query;
}
/**
* Build the DSL as array
*
* @throws \ElasticSearch\Exception
* @return array
*/
public function build() {
$built = array();
if ($this->from != null)
$built['from'] = $this->from;
if ($this->size != null)
$built['size'] = $this->size;
if ($this->sort && is_array($this->sort))
$built['sort'] = $this->sort;
if (!$this->query)
throw new \ElasticSearch\Exception("Query must be specified");
else
$built['query'] = $this->query->build();
return $built;
}
}

View File

@ -1,94 +0,0 @@
<?php // vim:set ts=4 sw=4 et:
namespace ElasticSearch\DSL;
/**
* This file is part of the ElasticSearch PHP client
*
* (c) Raymond Julin <raymond.julin@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Handle the query sub dsl
*
* @author Raymond Julin <raymond.julin@gmail.com>
* @package ElasticSearchClient
* @since 0.1
* Created: 2010-07-24
*/
class Query {
protected $term = null;
/**
* @var RangeQuery
*/
protected $range;
protected $prefix = null;
protected $wildcard = null;
protected $matchAll = null;
protected $queryString = null;
protected $bool = null;
protected $disMax = null;
protected $constantScore = null;
protected $filteredQuery = null;
public function __construct(array $options=array()) {
}
/**
* Add a term to this query
*
* @return \ElasticSearch\DSL\Query
* @param string $term
* @param bool|string $field
*/
public function term($term, $field=false) {
$this->term = ($field)
? array($field => $term)
: $term;
return $this;
}
/**
* Add a wildcard to this query
*
* @return \ElasticSearch\DSL\Query
* @param $val
* @param bool|string $field
*/
public function wildcard($val, $field=false) {
$this->wildcard = ($field)
? array($field => $val)
: $val;
return $this;
}
/**
* Add a range query
*
* @return \ElasticSearch\DSL\RangeQuery
* @param array $options
*/
public function range(array $options=array()) {
$this->range = new RangeQuery($options);
return $this->range;
}
/**
* Build the DSL as array
*
* @return array
*/
public function build() {
$built = array();
if ($this->term)
$built['term'] = $this->term;
elseif ($this->range)
$built['range'] = $this->range->build();
elseif ($this->wildcard)
$built['wildcard'] = $this->wildcard;
return $built;
}
}

View File

@ -1,117 +0,0 @@
<?php // vim:set ts=4 sw=4 et:
namespace ElasticSearch\DSL;
/**
* This file is part of the ElasticSearch PHP client
*
* (c) Raymond Julin <raymond.julin@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Range queries
*
* @author Raymond Julin <raymond.julin@gmail.com>
* @package ElasticSearchClient
* @since 0.1
* Created: 2010-07-24
*/
class RangeQuery {
protected $fieldname = null;
protected $from = null;
protected $to = null;
protected $includeLower = null;
protected $includeUpper = null;
protected $boost = null;
/**
* Construct new RangeQuery component
*
* @return \ElasticSearch\DSL\RangeQuery
* @param array $options
*/
public function __construct(array $options=array()) {
$this->fieldname = key($options);
$values = current($options);
if (is_array($values)) {
foreach ($values as $key => $val)
$this->$key = $val;
}
}
/**
* Setters
*
* @return \ElasticSearch\DSL\RangeQuery
* @param mixed $value
*/
public function fieldname($value) {
$this->fieldname = $value;
return $this;
}
/**
* @param $value
* @return \ElasticSearch\DSL\RangeQuery $this
*/
public function from($value) {
$this->from = $value;
return $this;
}
/**
* @param $value
* @return \ElasticSearch\DSL\RangeQuery $this
*/
public function to($value) {
$this->to = $value;
return $this;
}
/**
* @param $value
* @return \ElasticSearch\DSL\RangeQuery $this
*/
public function includeLower($value) {
$this->includeLower = $value;
return $this;
}
/**
* @param $value
* @return \ElasticSearch\DSL\RangeQuery $this
*/
public function includeUpper($value) {
$this->includeUpper = $value;
return $this;
}
/**
* @param $value
* @return \ElasticSearch\DSL\RangeQuery $this
*/
public function boost($value) {
$this->boost = $value;
return $this;
}
/**
* Build to array
*
* @throws \ElasticSearch\Exception
* @return array
*/
public function build() {
$built = array();
if ($this->fieldname) {
$built[$this->fieldname] = array();
foreach (array("from","to","includeLower","includeUpper", "boost") as $opt) {
if ($this->$opt !== null)
$built[$this->fieldname][$opt] = $this->$opt;
}
if (count($built[$this->fieldname]) == 0)
throw new \ElasticSearch\Exception("Empty RangeQuery cant be created");
}
return $built;
}
}

View File

@ -1,117 +0,0 @@
<?php // vim:set ts=4 sw=4 et:
namespace ElasticSearch\DSL;
/**
* This file is part of the ElasticSearch PHP client
*
* (c) Raymond Julin <raymond.julin@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Parse a DSL object into a string based representation
* Return string representation of DSL for search.
* This will remove certain fields that are not supported
* in a string representation
*
* @author Raymond Julin <raymond.julin@gmail.com>
* @package ElasticSearch
* @since 0.1
* Created: 2010-07-24
*/
class Stringify {
protected $dsl = array();
public function __construct(array $dsl) {
$this->dsl = $dsl;
}
public function __toString() {
$dsl = $this->dsl;
$query = $dsl['query'];
$string = "";
if (array_key_exists("term", $query))
$string .= $this->transformDSLTermToString($query['term']);
if (array_key_exists("wildcard", $query))
$string .= $this->transformDSLTermToString($query['wildcard']);
if (array_key_exists("sort", $dsl))
$string .= $this->transformDSLSortToString($dsl['sort']);
if (array_key_exists("fields", $dsl))
$string .= $this->transformDSLFieldsToString($dsl['fields']);
return $string;
}
/**
* A naive transformation of possible term and wildcard arrays in a DSL
* query
*
* @return string
* @param mixed $dslTerm
*/
protected function transformDSLTermToString($dslTerm) {
$string = "";
if (is_array($dslTerm)) {
$key = key($dslTerm);
$value = $dslTerm[$key];
if (is_string($key))
$string .= "$key:";
}
else
$value = $dslTerm;
/**
* If a specific key is used as key in the array
* this should translate to searching in a specific field (field:term)
*/
if (strpos($value, " ") !== false)
$string .= '"' . $value . '"';
else
$string .= $value;
return $string;
}
/**
* Transform search parameters to string
*
* @return string
* @param mixed $dslSort
*/
protected function transformDSLSortToString($dslSort) {
$string = "";
if (is_array($dslSort)) {
foreach ($dslSort as $sort) {
if (is_array($sort)) {
$field = key($sort);
$info = current($sort);
}
else
$field = $sort;
$string .= "&sort=" . $field;
if (isset($info)) {
if (is_string($info) && $info == "desc")
$string .= ":reverse";
elseif (is_array($info) && array_key_exists("reverse", $info) && $info['reverse'])
$string .= ":reverse";
}
}
}
return $string;
}
/**
* Transform a selection of fields to return to string form
*
* @return string
* @param mixed $dslFields
*/
protected function transformDSLFieldsToString($dslFields) {
$string = "";
if (is_array($dslFields))
$string .= "&fields=" . join(",", $dslFields);
return $string;
}
}

View File

@ -1,14 +0,0 @@
<?php // vim:set ts=4 sw=4 et:
namespace ElasticSearch;
/**
* This file is part of the ElasticSearch PHP client
*
* (c) Raymond Julin <raymond.julin@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Exception extends \Exception {
}

View File

@ -1,73 +0,0 @@
<?php // vim:set ts=4 sw=4 et:
namespace ElasticSearch;
/**
* This file is part of the ElasticSearch PHP client
*
* (c) Raymond Julin <raymond.julin@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Mapping {
protected $properties = array();
protected $config = array();
/**
* Build mapping data
*
* @param array $properties
* @param array $config
* @return \ElasticSearch\Mapping
*/
public function __construct(array $properties = array(), array $config = array()) {
$this->properties = $properties;
$this->config = $config;
}
/**
* Export mapping data as a json-ready array
*
* @return string
*/
public function export() {
return array(
'properties' => $this->properties
);
}
/**
* Add or overwrite existing field by name
*
* @param string $field
* @param string|array $config
* @return $this
*/
public function field($field, $config = array()) {
if (is_string($config)) $config = array('type' => $config);
$this->properties[$field] = $config;
return $this;
}
/**
* Get or set a config
*
* @param string $key
* @param mixed $value
* @throws \Exception
* @return array|void
*/
public function config($key, $value = null) {
if (is_array($key))
$this->config = $key + $this->config;
else {
if ($value !== null) $this->config[$key] = $value;
if (!isset($this->config[$key]))
throw new \Exception("Configuration key `type` is not set");
return $this->config[$key];
}
}
}

View File

@ -1,131 +0,0 @@
<?php // vim:set ts=4 sw=4 et:
namespace ElasticSearch\Transport;
/**
* This file is part of the ElasticSearch PHP client
*
* (c) Raymond Julin <raymond.julin@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
abstract class Base {
/**
* What host to connect to for server
* @var string
*/
protected $host = "";
/**
* Port to connect on
* @var int
*/
protected $port = 9200;
/**
* ElasticSearch index
* @var string
*/
protected $index;
/**
* ElasticSearch document type
* @var string
*/
protected $type;
/**
* Default constructor, just set host and port
* @param string $host
* @param int $port
*/
public function __construct($host, $port) {
$this->host = $host;
$this->port = $port;
}
/**
* Method for indexing a new document
*
* @param array|object $document
* @param mixed $id
* @param array $options
*/
abstract public function index($document, $id=false, array $options = array());
/**
* Perform a request against the given path/method/payload combination
* Example:
* $es->request('/_status');
*
* @param string|array $path
* @param string $method
* @param array|bool $payload
* @return
*/
abstract public function request($path, $method="GET", $payload=false);
/**
* Delete a document by its id
* @param mixed $id
*/
abstract public function delete($id=false);
/**
* Perform a search based on query
* @param array|string $query
*/
abstract public function search($query);
/**
* Search
*
* @return array
* @param mixed $query String or array to use as criteria for delete
* @param array $options Parameters to pass to delete action
* @throws \Elasticsearch\Exception
*/
public function deleteByQuery($query, array $options = array()) {
throw new \Elasticsearch\Exception(__FUNCTION__ . ' not implemented for ' . __CLASS__);
}
/**
* Set what index to act against
* @param string $index
*/
public function setIndex($index) {
$this->index = $index;
}
/**
* Set what document types to act against
* @param string $type
*/
public function setType($type) {
$this->type = $type;
}
/**
* Build a callable url
*
* @return string
* @param array|bool $path
* @param array $options Query parameter options to pass
*/
protected function buildUrl($path = false, array $options = array()) {
$isAbsolute = (is_array($path) ? $path[0][0] : $path[0]) === '/';
$url = $isAbsolute ? '' : "/" . $this->index;
if ($path && is_array($path) && count($path) > 0)
$url .= "/" . implode("/", array_filter($path));
if (substr($url, -1) == "/")
$url = substr($url, 0, -1);
if (count($options) > 0)
$url .= "?" . http_build_query($options, '', '&');
return $url;
}
}

View File

@ -1,237 +0,0 @@
<?php // vim:set ts=4 sw=4 et:
namespace ElasticSearch\Transport;
/**
* This file is part of the ElasticSearch PHP client
*
* (c) Raymond Julin <raymond.julin@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!defined('CURLE_OPERATION_TIMEDOUT'))
define('CURLE_OPERATION_TIMEDOUT', 28);
class HTTP extends Base {
/**
* How long before timing out CURL call
*/
private $timeout = 5;
/**
* curl handler which is needed for reusing existing http connection to the server
* @var resource
*/
protected $ch;
public function __construct($host='localhost', $port=9200, $timeout=null) {
parent::__construct($host, $port);
if(null !== $timeout) {
$this->setTimeout($timeout);
}
$this->ch = curl_init();
}
/**
* Index a new document or update it if existing
*
* @return array
* @param array $document
* @param mixed $id Optional
* @param array $options
*/
public function index($document, $id=false, array $options = array()) {
$url = $this->buildUrl(array($this->type, $id), $options);
$method = ($id == false) ? "POST" : "PUT";
return $this->call($url, $method, $document);
}
/**
* Search
*
* @return array
* @param array|string $query
* @param array $options
*/
public function search($query, array $options = array()) {
$result = false;
if (is_array($query)) {
/**
* Array implies using the JSON query DSL
*/
$arg = "_search";
if(isset($options['routing'])) {
$arg = "_search?routing=" . $options['routing'];
}
$url = $this->buildUrl(array(
$this->type, $arg
));
$result = $this->call($url, "GET", $query);
}
elseif (is_string($query)) {
/**
* String based search means http query string search
*/
$url = $this->buildUrl(array(
$this->type, "_search?q=" . $query
));
$result = $this->call($url, "POST", $options);
}
return $result;
}
/**
* Search
*
* @return array
* @param mixed $query
* @param array $options Parameters to pass to delete action
*/
public function deleteByQuery($query, array $options = array()) {
$options += array(
'refresh' => true
);
if (is_array($query)) {
/**
* Array implies using the JSON query DSL
*/
$url = $this->buildUrl(array($this->type, "_query"));
$result = $this->call($url, "DELETE", $query);
}
elseif (is_string($query)) {
/**
* String based search means http query string search
*/
$url = $this->buildUrl(array($this->type, "_query"), array('q' => $query));
$result = $this->call($url, "DELETE");
}
if ($options['refresh']) {
$this->request('_refresh', "POST");
}
return !isset($result['error']);
}
/**
* Perform a request against the given path/method/payload combination
* Example:
* $es->request('/_status');
*
* @param string|array $path
* @param string $method
* @param array|bool $payload
* @return array
*/
public function request($path, $method="GET", $payload=false) {
return $this->call($this->buildUrl($path), $method, $payload);
}
/**
* Flush this index/type combination
*
* @return array
* @param mixed $id Id of document to delete
* @param array $options Parameters to pass to delete action
*/
public function delete($id=false, array $options = array()) {
if ($id)
return $this->call($this->buildUrl(array($this->type, $id), $options), "DELETE");
else
return $this->request(false, "DELETE");
}
/**
* Perform a http call against an url with an optional payload
*
* @return array
* @param string $url
* @param string $method (GET/POST/PUT/DELETE)
* @param array|bool $payload The document/instructions to pass along
* @throws HTTPException
*/
protected function call($url, $method="GET", $payload=null) {
$conn = $this->ch;
$protocol = "http";
$requestURL = $protocol . "://" . $this->host . $url;
curl_setopt($conn, CURLOPT_URL, $requestURL);
curl_setopt($conn, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($conn, CURLOPT_PORT, $this->port);
curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1) ;
curl_setopt($conn, CURLOPT_CUSTOMREQUEST, strtoupper($method));
curl_setopt($conn, CURLOPT_FORBID_REUSE , 0) ;
if (is_array($payload) && count($payload) > 0)
curl_setopt($conn, CURLOPT_POSTFIELDS, json_encode($payload)) ;
else
curl_setopt($conn, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($conn);
if ($response !== false) {
$data = json_decode($response, true);
if (!$data) {
$data = array('error' => $response, "code" => curl_getinfo($conn, CURLINFO_HTTP_CODE));
}
}
else {
/**
* cUrl error code reference can be found here:
* http://curl.haxx.se/libcurl/c/libcurl-errors.html
*/
$errno = curl_errno($conn);
switch ($errno)
{
case CURLE_UNSUPPORTED_PROTOCOL:
$error = "Unsupported protocol [$protocol]";
break;
case CURLE_FAILED_INIT:
$error = "Internal cUrl error?";
break;
case CURLE_URL_MALFORMAT:
$error = "Malformed URL [$requestURL] -d " . json_encode($payload);
break;
case CURLE_COULDNT_RESOLVE_PROXY:
$error = "Couldnt resolve proxy";
break;
case CURLE_COULDNT_RESOLVE_HOST:
$error = "Couldnt resolve host";
break;
case CURLE_COULDNT_CONNECT:
$error = "Couldnt connect to host [{$this->host}], ElasticSearch down?";
break;
case CURLE_OPERATION_TIMEDOUT:
$error = "Operation timed out on [$requestURL]";
break;
default:
$error = "Unknown error";
if ($errno == 0)
$error .= ". Non-cUrl error";
break;
}
$exception = new HTTPException($error);
$exception->payload = $payload;
$exception->port = $this->port;
$exception->protocol = $protocol;
$exception->host = $this->host;
$exception->method = $method;
throw $exception;
}
return $data;
}
public function setTimeout($timeout)
{
$this->timeout = $timeout;
}
public function getTimeout()
{
return $this->timeout;
}
}

View File

@ -1,59 +0,0 @@
<?php // vim:set ts=4 sw=4 et:
namespace ElasticSearch\Transport;
/**
* This file is part of the ElasticSearch PHP client
*
* (c) Raymond Julin <raymond.julin@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class HTTPException extends \Exception {
/**
* Exception data
* @var array
*/
protected $data = array(
'payload' => null,
'protocol' => null,
'port' => null,
'host' => null,
'url' => null,
'method' => null,
);
/**
* Setter
* @param mixed $key
* @param mixed $value
*/
public function __set($key, $value) {
if (array_key_exists($key, $this->data))
$this->data[$key] = $value;
}
/**
* Getter
* @param mixed $key
* @return mixed
*/
public function __get($key) {
if (array_key_exists($key, $this->data))
return $this->data[$key];
else
return false;
}
/**
* Rebuild CLI command using curl to further investigate the failure
* @return string
*/
public function getCLICommand() {
$postData = json_encode($this->payload);
$curlCall = "curl -X{$method} 'http://{$this->host}:{$this->port}$this->url' -d '$postData'";
return $curlCall;
}
}

View File

@ -1,113 +0,0 @@
<?php // vim:set ts=4 sw=4 et:
namespace ElasticSearch\Transport;
use \Memcache;
use \ElasticSearch\DSL\Stringify;
/**
* This file is part of the ElasticSearch PHP client
*
* (c) Raymond Julin <raymond.julin@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Memcached extends Base {
public function __construct($host="127.0.0.1", $port=11311, $timeout=null) {
parent::__construct($host, $port);
$this->conn = new Memcache;
$this->conn->connect($host, $port, $timeout);
}
/**
* Index a new document or update it if existing
*
* @return array
* @param array $document
* @param mixed $id Optional
* @param array $options
* @throws \ElasticSearch\Exception
*/
public function index($document, $id=false, array $options = array()) {
if ($id === false)
throw new \ElasticSearch\Exception("Memcached transport requires id when indexing");
$document = json_encode($document);
$url = $this->buildUrl(array($this->type, $id));
$response = $this->conn->set($url, $document);
return array(
'ok' => $response
);
}
/**
* Search
*
* @return array
* @param array|string $query
* @throws \ElasticSearch\Exception
*/
public function search($query) {
if (is_array($query)) {
if (array_key_exists("query", $query)) {
$dsl = new Stringify($query);
$q = (string) $dsl;
$url = $this->buildUrl(array(
$this->type, "_search?q=" . $q
));
$result = json_decode($this->conn->get($url), true);
return $result;
}
throw new \ElasticSearch\Exception("Memcached protocol doesnt support the full DSL, only query");
}
elseif (is_string($query)) {
/**
* String based search means http query string search
*/
$url = $this->buildUrl(array(
$this->type, "_search?q=" . $query
));
$result = json_decode($this->conn->get($url), true);
return $result;
}
}
/**
* Perform a request against the given path/method/payload combination
* Example:
* $es->request('/_status');
*
* @param string|array $path
* @param string $method
* @param array|bool $payload
* @return array
*/
public function request($path, $method="GET", $payload=false) {
$url = $this->buildUrl($path);
switch ($method) {
case 'GET':
$result = $this->conn->get($url);
break;
case 'DELETE':
$result = $this->conn->delete($url);
break;
}
return json_decode($result);
}
/**
* Flush this index/type combination
*
* @return array
* @param mixed $id
* @param array $options Parameters to pass to delete action
*/
public function delete($id=false, array $options = array()) {
if ($id)
return $this->request(array($this->type, $id), "DELETE");
else
return $this->request(false, "DELETE");
}
}

View File

@ -1,7 +0,0 @@
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInitd6aa449f073d9fa5150269bbd4c40394::getLoader();

View File

@ -1,413 +0,0 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0 class loader
*
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class ClassLoader
{
// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
private $fallbackDirsPsr4 = array();
// PSR-0
private $prefixesPsr0 = array();
private $fallbackDirsPsr0 = array();
private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-0 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
if ('\\' == $class[0]) {
$class = substr($class, 1);
}
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative) {
return false;
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if ($file === null && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if ($file === null) {
// Remember that this class does not exist.
return $this->classMap[$class] = false;
}
return $file;
}
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
if (0 === strpos($class, $prefix)) {
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}

View File

@ -1,21 +0,0 @@
Copyright (c) 2015 Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -1,9 +0,0 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@ -1,10 +0,0 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'ElasticSearch' => array($baseDir . '/src'),
);

View File

@ -1,9 +0,0 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@ -1,50 +0,0 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitd6aa449f073d9fa5150269bbd4c40394
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitd6aa449f073d9fa5150269bbd4c40394', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitd6aa449f073d9fa5150269bbd4c40394', 'loadClassLoader'));
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register(true);
return $loader;
}
}
function composerRequired6aa449f073d9fa5150269bbd4c40394($file)
{
require $file;
}

View File

@ -100,11 +100,6 @@
<label index="tx_dlf_solrcores.label">Display Label</label>
<label index="tx_dlf_solrcores.index_name">Solr Name</label>
<label index="tx_dlf_solrcores.tab1">General</label>
<label index="tx_dlf_elasticsearchindexes">Elasticsearch Index</label>
<label index="tx_dlf_elasticsearchindexes.label">Display Label</label>
<label index="tx_dlf_elasticsearchindexes.index_name">Index Name</label>
<label index="tx_dlf_elasticsearchindexes.type_name">Type Name</label>
<label index="tx_dlf_elasticsearchindexes.tab1">General</label>
<label index="tx_dlf_collections">Collections</label>
<label index="tx_dlf_collections.label">Display Label</label>
<label index="tx_dlf_collections.index_name">Index Name</label>
@ -140,7 +135,6 @@
<label index="tx_dlf_libraries.tab3">Catalogs</label>
<label index="tx_dlf_toolbox.toolsPdf">PDF Download</label>
<label index="tx_dlf_toolbox.toolsFulltext">Fulltext</label>
<label index="tx_dlf_toolbox.toolsPublicationDownload">Publication Download</label>
<label index="tt_content.dlf_collection">DLF: Collection</label>
<label index="tt_content.dlf_feeds">DLF: Feeds</label>
<label index="tt_content.dlf_listview">DLF: List View</label>
@ -149,7 +143,6 @@
<label index="tt_content.dlf_oai">DLF: OAI-PMH Interface</label>
<label index="tt_content.dlf_pagegrid">DLF: Page Preview</label>
<label index="tt_content.dlf_pageview">DLF: Page View</label>
<label index="tt_content.dlf_routing">DLF: Routing</label>
<label index="tt_content.dlf_search">DLF: Search</label>
<label index="tt_content.dlf_statistics">DLF: Statistics</label>
<label index="tt_content.dlf_toc">DLF: Table of Contents</label>
@ -172,16 +165,6 @@
<label index="config.solrPath">Solr Server Path: (default is "/solr/")</label>
<label index="config.solrUser">Solr Server User: (default is "")</label>
<label index="config.solrPass">Solr Server Password: (default is "")</label>
<label index="config.elasticSearchConnect">Elasticsearch Connection</label>
<label index="config.elasticSearchHost">Elasticsearch Server Host: (default is "localhost")</label>
<label index="config.elasticSearchPort">Elasticsearch Server Port: (default is "9200")</label>
<label index="config.elasticSearchIndex">Elasticsearch Server Index: </label>
<label index="config.elasticSearchType">Elasticsearch Server Type: </label>
<label index="config.elasticSearchUser">Elasticsearch Server User: (default is "")</label>
<label index="config.elasticSearchPass">Elasticsearch Server Password: (default is "")</label>
<label index="config.repository">Repository</label>
<label index="elasticSearch.status">The status code returned by Elasticsearch is &lt;strong&gt;%s&lt;/strong&gt;.</label>
<label index="elasticSearch.error">Elasticsearch was not reachable under &lt;strong&gt;%s&lt;/strong&gt;.</label>
<label index="solr.connected">Connection established!</label>
<label index="solr.status">The status code returned by Apache Solr is &lt;strong&gt;%s&lt;/strong&gt;.</label>
<label index="solr.notConnected">Connection failed!</label>
@ -295,11 +278,6 @@
<label index="tx_dlf_solrcores.label">Anzeigeform</label>
<label index="tx_dlf_solrcores.index_name">Solr-Bezeichnung</label>
<label index="tx_dlf_solrcores.tab1">General</label>
<label index="tx_dlf_elasticsearchindexes">Elasticsearch Index</label>
<label index="tx_dlf_elasticsearchindexes.label">Anzeigeform</label>
<label index="tx_dlf_elasticsearchindexes.index_name">Index-Bezeichnung</label>
<label index="tx_dlf_elasticsearchindexes.type_name">Type Name</label>
<label index="tx_dlf_elasticsearchindexes.tab1">General</label>
<label index="tx_dlf_collections">Sammlungen</label>
<label index="tx_dlf_collections.label">Anzeigeform</label>
<label index="tx_dlf_collections.index_name">Index-Bezeichnung</label>
@ -335,7 +313,6 @@
<label index="tx_dlf_libraries.tab3">Kataloge</label>
<label index="tx_dlf_toolbox.toolsPdf">PDF-Download</label>
<label index="tx_dlf_toolbox.toolsFulltext">Volltext</label>
<label index="tx_dlf_toolbox.toolsPublicationDownload">Publication Download</label>
<label index="tt_content.dlf_collection">DLF: Kollektion</label>
<label index="tt_content.dlf_feeds">DLF: Feeds</label>
<label index="tt_content.dlf_listview">DLF: Listenansicht</label>
@ -344,7 +321,6 @@
<label index="tt_content.dlf_oai">DLF: OAI-PMH-Schnittstelle</label>
<label index="tt_content.dlf_pagegrid">DLF: Seitenvorschau</label>
<label index="tt_content.dlf_pageview">DLF: Seitenansicht</label>
<label index="tt_content.dlf_routing">DLF: Routing</label>
<label index="tt_content.dlf_search">DLF: Suche</label>
<label index="tt_content.dlf_statistics">DLF: Statistik</label>
<label index="tt_content.dlf_toc">DLF: Inhaltsverzeichnis</label>
@ -367,16 +343,6 @@
<label index="config.solrPath">Solr Server Pfad: (Standard ist "/solr/")</label>
<label index="config.solrUser">Solr Server Benutzername: (Standard ist "")</label>
<label index="config.solrPass">Solr Server Kennwort: (Standard ist "")</label>
<label index="config.elasticSearchConnect">Elasticsearch Verbindung</label>
<label index="config.elasticSearchHost">Elasticsearch Server Host: (Standard ist "localhost")</label>
<label index="config.elasticSearchPort">Elasticsearch Server Port: (Standard ist "9200")</label>
<label index="config.elasticSearchIndex">Elasticsearch Server Index: </label>
<label index="config.elasticSearchType">Elasticsearch Server Type: </label>
<label index="config.elasticSearchUser">Elasticsearch Server Benutzername: (Standard ist "")</label>
<label index="config.elasticSearchPass">Elasticsearch Server Kennwort: (Standard ist "")</label>
<label index="config.repository">Repository</label>
<label index="elasticSearch.status">Elasticsearch gibt den Statuscode &lt;strong&gt;%s&lt;/strong&gt; zurück.</label>
<label index="elasticSearch.error">Elasticsearch ist unter &lt;strong&gt;%s&lt;/strong&gt; nicht erreichbar.</label>
<label index="solr.connected">Verbindung hergestellt!</label>
<label index="solr.status">Apache Solr gibt den Statuscode &lt;strong&gt;%s&lt;/strong&gt; zurück.</label>
<label index="solr.notConnected">Verbindung fehlgeschlagen!</label>

View File

@ -222,55 +222,6 @@ class tx_dlf_modNewclient extends tx_dlf_module {
}
/**
* Add Elasticsearch index
*
* @access protected
*
* @return void
*/
protected function cmdAddElasticsearchindex() {
// Build data array.
$data['tx_dlf_elasticsearchindexes'][uniqid('NEW')] = array (
'pid' => intval($this->id),
// 'label' => $GLOBALS['LANG']->getLL('solrcore').' (PID '.$this->id.')',
'label' => 'Elasticsearch Index'.' (PID '.$this->id.')',
'index_name' => 'index',
);
$_ids = tx_dlf_helper::processDBasAdmin($data);
// Check for failed inserts.
if (count($_ids) == 1) {
// Fine.
$_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
tx_dlf_helper::getLL('flash.solrcoreAddedMsg'),
tx_dlf_helper::getLL('flash.solrcoreAdded', TRUE),
\TYPO3\CMS\Core\Messaging\FlashMessage::OK,
FALSE
);
} else {
// Something went wrong.
$_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
tx_dlf_helper::getLL('flash.solrcoreNotAddedMsg'),
tx_dlf_helper::getLL('flash.solrcoreNotAdded', TRUE),
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
FALSE
);
}
tx_dlf_helper::addMessage($_message);
}
/**
* Add structure configuration
*
@ -509,13 +460,6 @@ class tx_dlf_modNewclient extends tx_dlf_module {
'pid IN ('.intval($this->id).',0)'.tx_dlf_helper::whereClause('tx_dlf_solrcores')
);
// Check for existing elasticsearch index.
$es_result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'uid,pid',
'tx_dlf_elasticsearchindexes',
'pid IN ('.intval($this->id).',0)'.tx_dlf_helper::whereClause('tx_dlf_elasticsearchindexes')
);
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
$resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
@ -546,27 +490,14 @@ class tx_dlf_modNewclient extends tx_dlf_module {
}
} else if ($GLOBALS['TYPO3_DB']->sql_num_rows($es_result)) {
// elasticsearch is configured
$_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
tx_dlf_helper::getLL('flash.elasticsearchindexOkayMsg'),
tx_dlf_helper::getLL('flash.elasticsearchindexOkay', TRUE),
\TYPO3\CMS\Core\Messaging\FlashMessage::OK,
FALSE
);
} else {
// Solr core missing.
$_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array ('id' => $this->id, 'CMD' => 'addSolrcore')));
// Elasticsearch url
$_es_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array ('id' => $this->id, 'CMD' => 'addElasticsearchindex')));
$_message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
sprintf(tx_dlf_helper::getLL('flash.solrcoreMissingMsg'), $_url). '<br />' . sprintf(tx_dlf_helper::getLL('flash.elasticsearchindexMissingMsg'), $_es_url),
sprintf(tx_dlf_helper::getLL('flash.solrcoreMissingMsg'), $_url),
tx_dlf_helper::getLL('flash.solrcoreMissing', TRUE),
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
FALSE

View File

@ -438,7 +438,7 @@ class tx_dlf_search extends tx_dlf_plugin {
$this->setCache(FALSE);
// Quit without doing anything if required variables are not set.
if (empty($this->conf['solrcore']) && empty($this->conf['elasticsearch'])) {
if (empty($this->conf['solrcore'])) {
if (TYPO3_DLOG) {
@ -500,230 +500,172 @@ class tx_dlf_search extends tx_dlf_plugin {
} else {
// switch between elasticsearch and solr
if ($this->conf['searchengine'] == "elasticsearch") {
// Instantiate search object.
$solr = tx_dlf_solr::getInstance($this->conf['solrcore']);
$es = tx_dlf_elasticsearch::getInstance($this->conf['elasticsearch']);
if (!$solr->ready) {
// Build label for result list.
$label = $this->pi_getLL('search', '', TRUE);
if (TYPO3_DLOG) {
if (!empty($this->piVars['query'])) {
$label .= htmlspecialchars(sprintf($this->pi_getLL('for', ''), $this->piVars['query']));
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_search->main('.$content.', [data])] Apache Solr not available', $this->extKey, SYSLOG_SEVERITY_ERROR, $conf);
}
// Set search parameters.
$es->limit = max(intval($this->conf['limit']), 1);
return $content;
$es->cPid = $this->conf['pages'];
}
$es->apiPid = $this->conf['apiPid'];
// Build label for result list.
$label = $this->pi_getLL('search', '', TRUE);
$query = $this->piVars['query'];
if (!empty($this->piVars['query'])) {
// search for specified query
$results = $es->search($query);
$label .= htmlspecialchars(sprintf($this->pi_getLL('for', ''), $this->piVars['query']));
$results->metadata = array (
'label' => $label,
'description' => '<p class="tx-dlf-search-numHits">'.htmlspecialchars(sprintf($this->pi_getLL('hits', ''), $es->numberOfHits, count($results))).'</p>',
'options' => $results->metadata['options']
);
}
$results->save();
// Prepare query parameters.
$params = array ();
// Clean output buffer.
\TYPO3\CMS\Core\Utility\GeneralUtility::cleanOutputBuffers();
// Set search query.
if (!empty($this->conf['fulltext']) && !empty($this->piVars['fulltext'])) {
// Keep some plugin variables.
$linkConf['parameter'] = $this->conf['targetPid'];
// Search in fulltext field if applicable.
$query = 'fulltext:('.tx_dlf_solr::escapeQuery($this->piVars['query']).')';
if (!empty($this->piVars['order'])) {
// Add highlighting for fulltext.
$params['hl'] = 'true';
$linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, array ('order' => $this->piVars['order'], 'asc' => (!empty($this->piVars['asc']) ? '1' : '0')), '', TRUE, FALSE);
}
// Send headers.
header('Location: '.\TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($this->cObj->typoLink_URL($linkConf)));
// Flush output buffer and end script processing.
ob_end_flush();
exit;
$params['hl.fl'] = 'fulltext';
} else {
// Instantiate search object.
$solr = tx_dlf_solr::getInstance($this->conf['solrcore']);
// Retain given search field if valid.
$query = tx_dlf_solr::escapeQueryKeepField($this->piVars['query'], $this->conf['pages']);
if (!$solr->ready) {
}
if (TYPO3_DLOG) {
// Add extended search query.
if (!empty($this->piVars['extQuery']) && is_array($this->piVars['extQuery'])) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_search->main('.$content.', [data])] Apache Solr not available', $this->extKey, SYSLOG_SEVERITY_ERROR, $conf);
$allowedOperators = array('AND', 'OR', 'NOT');
}
$allowedFields = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['extendedFields'], TRUE);
return $content;
for ($i = 0; $i < count($this->piVars['extQuery']); $i++) {
}
if (!empty($this->piVars['extQuery'][$i])) {
// Build label for result list.
$label = $this->pi_getLL('search', '', TRUE);
if (in_array($this->piVars['extOperator'][$i], $allowedOperators) && in_array($this->piVars['extField'][$i], $allowedFields)) {
if (!empty($this->piVars['query'])) {
if (!empty($query)) {
$label .= htmlspecialchars(sprintf($this->pi_getLL('for', ''), $this->piVars['query']));
}
// Prepare query parameters.
$params = array ();
// Set search query.
if (!empty($this->conf['fulltext']) && !empty($this->piVars['fulltext'])) {
// Search in fulltext field if applicable.
$query = 'fulltext:('.tx_dlf_solr::escapeQuery($this->piVars['query']).')';
// Add highlighting for fulltext.
$params['hl'] = 'true';
$params['hl.fl'] = 'fulltext';
} else {
// Retain given search field if valid.
$query = tx_dlf_solr::escapeQueryKeepField($this->piVars['query'], $this->conf['pages']);
}
// Add extended search query.
if (!empty($this->piVars['extQuery']) && is_array($this->piVars['extQuery'])) {
$allowedOperators = array('AND', 'OR', 'NOT');
$allowedFields = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['extendedFields'], TRUE);
for ($i = 0; $i < count($this->piVars['extQuery']); $i++) {
if (!empty($this->piVars['extQuery'][$i])) {
if (in_array($this->piVars['extOperator'][$i], $allowedOperators) && in_array($this->piVars['extField'][$i], $allowedFields)) {
if (!empty($query)) {
$query .= ' '.$this->piVars['extOperator'][$i].' ';
}
$query .= tx_dlf_indexing::getIndexFieldName($this->piVars['extField'][$i], $this->conf['pages']).':('.tx_dlf_solr::escapeQuery($this->piVars['extQuery'][$i]).')';
$query .= ' '.$this->piVars['extOperator'][$i].' ';
}
$query .= tx_dlf_indexing::getIndexFieldName($this->piVars['extField'][$i], $this->conf['pages']).':('.tx_dlf_solr::escapeQuery($this->piVars['extQuery'][$i]).')';
}
}
}
// Add filter query for faceting.
if (!empty($this->piVars['fq'])) {
}
$params['fq'] = $this->piVars['fq'];
// Add filter query for faceting.
if (!empty($this->piVars['fq'])) {
}
// Add filter query for in-document searching.
if ($this->conf['searchIn'] == 'document' || $this->conf['searchIn'] == 'all') {
if (!empty($this->piVars['id']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->piVars['id'])) {
$params['fq'][] = 'uid:('.$this->piVars['id'].') OR partof:('.$this->piVars['id'].')';
$label .= htmlspecialchars(sprintf($this->pi_getLL('in', ''), tx_dlf_document::getTitle($this->piVars['id'])));
}
}
// Add filter query for in-collection searching.
if ($this->conf['searchIn'] == 'collection' || $this->conf['searchIn'] == 'all') {
if (!empty($this->piVars['collection']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->piVars['collection'])) {
$index_name = tx_dlf_helper::getIndexName($this->piVars['collection'], 'tx_dlf_collections', $this->conf['pages']);
$params['fq'][] = 'collection_faceting:("'.tx_dlf_solr::escapeQuery($index_name).'")';
$label .= sprintf($this->pi_getLL('in', '', TRUE), tx_dlf_helper::translate($index_name, 'tx_dlf_collections', $this->conf['pages']));
}
}
// Add filter query for collection restrictions.
if ($this->conf['collections']) {
$collIds = explode(',', $this->conf['collections']);
$collIndexNames = array ();
foreach ($collIds as $collId) {
$collIndexNames[] = tx_dlf_solr::escapeQuery(tx_dlf_helper::getIndexName(intval($collId), 'tx_dlf_collections', $this->conf['pages']));
}
// Last value is fake and used for distinction in $this->addCurrentCollection()
$params['fq'][] = 'collection_faceting:("'.implode('" OR "', $collIndexNames).'" OR "FakeValueForDistinction")';
}
// Set search parameters.
$solr->limit = max(intval($this->conf['limit']), 1);
$solr->cPid = $this->conf['pages'];
$solr->params = $params;
// Perform search.
$results = $solr->search($query);
$results->metadata = array (
'label' => $label,
'description' => '<p class="tx-dlf-search-numHits">'.htmlspecialchars(sprintf($this->pi_getLL('hits', ''), $solr->numberOfHits, count($results))).'</p>',
'thumbnail' => '',
'options' => $results->metadata['options']
);
$results->save();
// Clean output buffer.
\TYPO3\CMS\Core\Utility\GeneralUtility::cleanOutputBuffers();
// Keep some plugin variables.
$linkConf['parameter'] = $this->conf['targetPid'];
if (!empty($this->piVars['order'])) {
$linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, array ('order' => $this->piVars['order'], 'asc' => (!empty($this->piVars['asc']) ? '1' : '0')), '', TRUE, FALSE);
}
// Send headers.
header('Location: '.\TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($this->cObj->typoLink_URL($linkConf)));
// Flush output buffer and end script processing.
ob_end_flush();
exit;
$params['fq'] = $this->piVars['fq'];
}
// Add filter query for in-document searching.
if ($this->conf['searchIn'] == 'document' || $this->conf['searchIn'] == 'all') {
if (!empty($this->piVars['id']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->piVars['id'])) {
$params['fq'][] = 'uid:('.$this->piVars['id'].') OR partof:('.$this->piVars['id'].')';
$label .= htmlspecialchars(sprintf($this->pi_getLL('in', ''), tx_dlf_document::getTitle($this->piVars['id'])));
}
}
// Add filter query for in-collection searching.
if ($this->conf['searchIn'] == 'collection' || $this->conf['searchIn'] == 'all') {
if (!empty($this->piVars['collection']) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->piVars['collection'])) {
$index_name = tx_dlf_helper::getIndexName($this->piVars['collection'], 'tx_dlf_collections', $this->conf['pages']);
$params['fq'][] = 'collection_faceting:("'.tx_dlf_solr::escapeQuery($index_name).'")';
$label .= sprintf($this->pi_getLL('in', '', TRUE), tx_dlf_helper::translate($index_name, 'tx_dlf_collections', $this->conf['pages']));
}
}
// Add filter query for collection restrictions.
if ($this->conf['collections']) {
$collIds = explode(',', $this->conf['collections']);
$collIndexNames = array ();
foreach ($collIds as $collId) {
$collIndexNames[] = tx_dlf_solr::escapeQuery(tx_dlf_helper::getIndexName(intval($collId), 'tx_dlf_collections', $this->conf['pages']));
}
// Last value is fake and used for distinction in $this->addCurrentCollection()
$params['fq'][] = 'collection_faceting:("'.implode('" OR "', $collIndexNames).'" OR "FakeValueForDistinction")';
}
// Set search parameters.
$solr->limit = max(intval($this->conf['limit']), 1);
$solr->cPid = $this->conf['pages'];
$solr->params = $params;
// Perform search.
$results = $solr->search($query);
$results->metadata = array (
'label' => $label,
'description' => '<p class="tx-dlf-search-numHits">'.htmlspecialchars(sprintf($this->pi_getLL('hits', ''), $solr->numberOfHits, count($results))).'</p>',
'thumbnail' => '',
'options' => $results->metadata['options']
);
$results->save();
// Clean output buffer.
\TYPO3\CMS\Core\Utility\GeneralUtility::cleanOutputBuffers();
// Keep some plugin variables.
$linkConf['parameter'] = $this->conf['targetPid'];
if (!empty($this->piVars['order'])) {
$linkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl($this->prefixId, array ('order' => $this->piVars['order'], 'asc' => (!empty($this->piVars['asc']) ? '1' : '0')), '', TRUE, FALSE);
}
// Send headers.
header('Location: '.\TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($this->cObj->typoLink_URL($linkConf)));
// Flush output buffer and end script processing.
ob_end_flush();
exit;
}
}

View File

@ -1,3 +0,0 @@
plugin.tx_dlf_search {
apiPid =
}

View File

@ -46,11 +46,6 @@
<size>1</size>
<maxitems>1</maxitems>
<minitems>1</minitems>
<wizards>
<suggest>
<type>suggest</type>
</suggest>
</wizards>
</config>
</TCEforms>
</pages>
@ -75,32 +70,9 @@
</config>
</TCEforms>
</fulltext>
<searchengine>
<TCEforms>
<onChange>reload</onChange>
<displayCond>FIELD:pages:REQ:true</displayCond>
<exclude>1</exclude>
<label>LLL:EXT:dlf/plugins/search/locallang.xml:tt_content.pi_flexform.searchEngine</label>
<config>
<type>radio</type>
<items type="array">
<numIndex index="0" type="array">
<numIndex index="0">Solr</numIndex>
<numIndex index="1">solr</numIndex>
</numIndex>
<numIndex index="1" type="array">
<numIndex index="0">Elasticsearch</numIndex>
<numIndex index="1">elasticsearch</numIndex>
</numIndex>
</items>
<maxitems>1</maxitems>
<minitems>1</minitems>
</config>
</TCEforms>
</searchengine>
<solrcore>
<TCEforms>
<displayCond>FIELD:searchengine:=:solr</displayCond>
<displayCond>FIELD:pages:REQ:true</displayCond>
<exclude>1</exclude>
<label>LLL:EXT:dlf/plugins/search/locallang.xml:tt_content.pi_flexform.solrcore</label>
<config>
@ -113,21 +85,6 @@
</config>
</TCEforms>
</solrcore>
<elasticsearch>
<TCEforms>
<displayCond>FIELD:searchengine:=:elasticsearch</displayCond>
<exclude>1</exclude>
<label>LLL:EXT:dlf/plugins/search/locallang.xml:tt_content.pi_flexform.elasticsearch</label>
<config>
<type>select</type>
<items type="array"></items>
<itemsProcFunc>tx_dlf_tceforms->itemsProcFunc_elasticsearchList</itemsProcFunc>
<size>1</size>
<maxitems>1</maxitems>
<minitems>0</minitems>
</config>
</TCEforms>
</elasticsearch>
<limit>
<TCEforms>
<displayCond>FIELD:pages:REQ:true</displayCond>
@ -281,11 +238,6 @@
<size>1</size>
<maxitems>1</maxitems>
<minitems>1</minitems>
<wizards>
<suggest>
<type>suggest</type>
</suggest>
</wizards>
</config>
</TCEforms>
</targetPid>

View File

@ -33,7 +33,6 @@
<label index="tt_content.pi_flexform.fulltext.yes">yes</label>
<label index="tt_content.pi_flexform.fulltext.no">no</label>
<label index="tt_content.pi_flexform.solrcore">Solr Core</label>
<label index="tt_content.pi_flexform.elasticsearch">Elasticsearch Index</label>
<label index="tt_content.pi_flexform.limit">Maximum results</label>
<label index="tt_content.pi_flexform.extSearch.slotCount">Number of search slots</label>
<label index="tt_content.pi_flexform.extSearch.fields">Fields for extended search</label>
@ -43,9 +42,6 @@
<label index="tt_content.pi_flexform.searchIn.document">document only</label>
<label index="tt_content.pi_flexform.searchIn.collection">collection only</label>
<label index="tt_content.pi_flexform.searchIn.all">both</label>
<label index="tt_content.pi_flexform.searchEngine">Choose Search Engine</label>
<label index="tt_content.pi_flexform.searchEngine.solr">Solr</label>
<label index="tt_content.pi_flexform.searchEngine.elasticsearch">Elasticsearch</label>
<label index="tt_content.pi_flexform.facets">Show these facets</label>
<label index="tt_content.pi_flexform.limitFacets">Maximum facet values</label>
<label index="tt_content.pi_flexform.resetFacets">Allow to reset facets</label>
@ -72,7 +68,6 @@
<label index="tt_content.pi_flexform.fulltext.yes">ja</label>
<label index="tt_content.pi_flexform.fulltext.no">nein</label>
<label index="tt_content.pi_flexform.solrcore">Solr Kern</label>
<label index="tt_content.pi_flexform.elasticsearch">Elasticsearch Index</label>
<label index="tt_content.pi_flexform.limit">Maximale Ergebnismenge</label>
<label index="tt_content.pi_flexform.extSearch.slotCount">Anzahl Suchfelder</label>
<label index="tt_content.pi_flexform.extSearch.fields">Felder für erweiterte Suche</label>
@ -82,9 +77,6 @@
<label index="tt_content.pi_flexform.searchIn.document">nur Dokument</label>
<label index="tt_content.pi_flexform.searchIn.collection">nur Kollektion</label>
<label index="tt_content.pi_flexform.searchIn.all">beides</label>
<label index="tt_content.pi_flexform.searchEngine">Suchengine wählen</label>
<label index="tt_content.pi_flexform.searchEngine.solr">Solr</label>
<label index="tt_content.pi_flexform.searchEngine.elasticsearch">Elasticsearch</label>
<label index="tt_content.pi_flexform.facets">Diese Facetten anzeigen</label>
<label index="tt_content.pi_flexform.limitFacets">Maximale Facettenwerte</label>
<label index="tt_content.pi_flexform.resetFacets">Facetten zurücksetzen erlauben</label>

View File

@ -33,9 +33,3 @@ plugin.tx_dlf_search.facetsConf {
CUR.wrapItemAndSub = <li class="tx-dlf-search-cur">|</li>
}
}
plugin.tx_dlf_search {
apiPid = {$plugin.tx_dlf_search.apiPid}
}
plugin.tx_dlf_toolsPublicationDownload.apiPid < plugin.tx_dlf_search.apiPid

View File

@ -1,148 +0,0 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2014 Goobi. Digitalisieren im Verein e.V. <contact@goobi.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*/
/**
* Tool 'PDF Download' for the plugin 'DLF: Toolbox' of the 'dlf' extension.
*
* @author Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* @author Alexander Bigga <alexander.bigga@slub-dresden.de>
* @package TYPO3
* @subpackage tx_dlf
* @access public
*/
class tx_dlf_toolsPublicationDownload extends tx_dlf_plugin {
public $scriptRelPath = 'plugins/toolbox/tools/pdf/class.tx_dlf_toolsPublicationDownload.php';
/**
* The main method of the PlugIn
*
* @access public
*
* @param string $content: The PlugIn content
* @param array $conf: The PlugIn configuration
*
* @return string The content that is displayed on the website
*/
public function main($content, $conf) {
$this->init($conf);
// Merge configuration with conf array of toolbox.
$this->conf = tx_dlf_helper::array_merge_recursive_overrule($this->cObj->data['conf'], $this->conf);
// Load current document.
$this->loadDocument();
if ($this->doc === NULL || empty($this->conf['fileGrpDownload'])) {
// Quit without doing anything if required variables are not set.
return $content;
}
// Load template file.
if (!empty($this->conf['templateFile'])) {
$this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), '###TEMPLATE###');
} else {
$this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/toolbox/tools/publicationDownload/template.tmpl'), '###TEMPLATE###');
}
$subpartArray['downloads'] = $this->cObj->getSubpart($this->template, '###DOWNLOADS###');
// Show all PDF Documents
$attachments = $this->getAttachments();
$content = '';
if (is_array($attachments)) {
foreach ($attachments as $id => $file) {
$conf = array(
'useCacheHash' => 0,
'parameter' => $this->conf['apiPid'],
'additionalParams' => '&tx_dpf[qid]=' . $this->doc->recordId . '&tx_dpf[action]=attachment' . '&tx_dpf[attachment]=' . $file['ID'],
'forceAbsoluteUrl' => TRUE
);
$title = $file['TITLE'] ? $file['TITLE'] : $file['ID'];
// replace uid with URI to dpf API
$markerArray['###FILE###'] = $this->cObj->typoLink($title, $conf);
$content .= $this->cObj->substituteMarkerArray($subpartArray['downloads'], $markerArray);
}
}
return $this->cObj->substituteSubpart($this->template, '###DOWNLOADS###', $content, TRUE);
}
/**
* Get PDF document list
* @return html List of attachments
*/
protected function getAttachments() {
// Get pdf documents
//
$xPath = 'mets:fileSec/mets:fileGrp[@USE="'.$this->conf['fileGrpDownload'].'"]';
$files = $this->doc->mets->xpath($xPath);
foreach ($files as $key => $value) {
$file = $value->xpath('mets:file')[0];
$singleFile = array();
foreach ($file->attributes() as $attribute => $value) {
$singleFile[$attribute] = $value;
}
$attachments[] = $singleFile;
}
return $attachments;
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/plugins/toolbox/tools/pdf/class.tx_dlf_toolsPublicationDownload.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dlf/plugins/toolbox/tools/pdf/class.tx_dlf_toolsPublicationDownload.php']);
}

View File

@ -1,41 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<!--
Copyright notice
(c) 2011 Goobi. Digitalisieren im Verein e.V. <contact@goobi.org>
All rights reserved
This script is part of the TYPO3 project. The TYPO3 project is
free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
The GNU General Public License can be found at
http://www.gnu.org/copyleft/gpl.html.
This script is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This copyright notice MUST APPEAR in all copies of the script!
-->
<T3locallang>
<meta type="array">
<type>module</type>
<description>Language labels for tool tx_dlf_toolsPdf</description>
</meta>
<data type="array">
<languageKey index="default" type="array">
<label index="singlePage">Download single page</label>
<label index="leftPage">Download left page</label>
<label index="rightPage">Download right page</label>
</languageKey>
<languageKey index="de" type="array">
<label index="singlePage">Einzelseite herunterladen</label>
<label index="leftPage">Linke Seite herunterladen</label>
<label index="rightPage">Rechte Seite herunterladen</label>
</languageKey>
</data>
</T3locallang>

View File

@ -1,31 +0,0 @@
<!--
Copyright notice
(c) 2011 Goobi. Digitalisieren im Verein e.V. <contact@goobi.org>
All rights reserved
This script is part of the TYPO3 project. The TYPO3 project is
free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
The GNU General Public License can be found at
http://www.gnu.org/copyleft/gpl.html.
This script is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This copyright notice MUST APPEAR in all copies of the script!
-->
<!-- ###TEMPLATE### -->
<span class="tx-dlf-tools-pdf-page">
<ul>
<!-- ###DOWNLOADS### -->
<li>###FILE###</li>
<!-- ###DOWNLOADS### -->
</ul>
</span>
<!-- ###TEMPLATE### -->

View File

@ -800,49 +800,6 @@ $TCA['tx_dlf_solrcores'] = array (
),
);
$TCA['tx_dlf_elasticsearchindexes'] = array (
'ctrl' => $TCA['tx_dlf_elasticsearchindexes']['ctrl'],
'interface' => array (
'showRecordFieldList' => 'label,index_name,type_name',
),
'feInterface' => $TCA['tx_dlf_elasticsearchindexes']['feInterface'],
'columns' => array (
'label' => array (
'label' => 'LLL:EXT:dlf/locallang.xml:tx_dlf_elasticsearchindexes.label',
'config' => array (
'type' => 'input',
'size' => 30,
'max' => 255,
'eval' => 'required,trim',
),
),
'index_name' => array (
'label' => 'LLL:EXT:dlf/locallang.xml:tx_dlf_elasticsearchindexes.index_name',
'config' => array (
'type' => 'input',
'size' => 30,
'max' => 255,
'eval' => 'alphanum,unique',
),
),
'type_name' => array (
'label' => 'LLL:EXT:dlf/locallang.xml:tx_dlf_elasticsearchindexes.type_name',
'config' => array (
'type' => 'input',
'size' => 30,
'max' => 255,
'eval' => 'alphanum,unique',
),
),
),
'types' => array (
'0' => array ('showitem' => '--div--;LLL:EXT:dlf/locallang.xml:tx_dlf_elasticsearchindexes.tab1, label;;;;1-1-1, index_name;;;;2-2-2, type_name;;;;2-2-2'),
),
'palettes' => array (
'1' => array ('showitem' => ''),
),
);
$TCA['tx_dlf_collections'] = array (
'ctrl' => $TCA['tx_dlf_collections']['ctrl'],
'interface' => array (