Commit a801ec93 authored by Bas de Nooijer's avatar Bas de Nooijer

initial import

parents
Copyright 2011 Bas de Nooijer. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of the copyright holder.
\ No newline at end of file
Solarium is a PHP Solr client that not only facilitates Solr communication but
also tries to accurately model Solr concepts.
For Docs, License, Issues, and pre-packed downloads, see:
http://github.com/basdenooijer/solarium
Contributors:
http://github.com/basdenooijer/solarium/contributors
<project name="solarium" default="build" basedir=".">
<target name="clean">
<!-- Clean up -->
<delete dir="build"/>
<!-- Create build directories -->
<mkdir dir="${basedir}/build/api"/>
<mkdir dir="${basedir}/build/code-browser"/>
<mkdir dir="${basedir}/build/coverage"/>
<mkdir dir="${basedir}/build/logs"/>
<mkdir dir="${basedir}/build/pdepend"/>
</target>
<!-- Run unit tests and generate junit.xml and clover.xml
(This is done in the phpunit.xml.dist,
you could also write the switches here)
-->
<target name="phpunit">
<exec executable="phpunit" failonerror="true" />
</target>
<!-- Run pdepend, phpmd, phpcpd, and phpcs in parallel -->
<target name="parallelTasks">
<parallel>
<antcall target="pdepend"/>
<antcall target="phpmd"/>
<antcall target="phpcpd"/>
<antcall target="phpcs"/>
<antcall target="phpdoc"/>
</parallel>
</target>
<!-- Generate jdepend.xml and software metrics charts -->
<target name="pdepend">
<exec executable="pdepend">
<arg line="--jdepend-xml=${basedir}/build/logs/jdepend.xml libraru" />
</exec>
</target>
<!-- Generate pmd.xml -->
<target name="phpmd">
<exec executable="phpmd">
<arg line="library xml codesize,unusedcode --reportfile ${basedir}/build/logs/pmd.xml" />
</exec>
</target>
<!-- Generate pmd-cpd.xml -->
<target name="phpcpd">
<exec executable="phpcpd">
<arg line="--log-pmd ${basedir}/build/logs/pmd-cpd.xml library" />
</exec>
</target>
<!-- Generate checkstyle.xml -->
<target name="phpcs">
<exec executable="phpcs" output="/dev/null">
<arg line="--report=checkstyle --report-file=${basedir}/build/logs/checkstyle.xml --standard=Zend library" />
</exec>
</target>
<!-- Generate API documentation -->
<target name="phpdoc">
<exec executable="phpdoc">
<arg line="-d library -t build/api" />
</exec>
</target>
<target name="phpcb">
<exec executable="phpcb">
<arg line="--log ${basedir}/build/logs --source ${basedir}/library --output ${basedir}/build/code-browser" />
</exec>
</target>
<target name="build" depends="clean,phpunit,parallelTasks,phpcb"/>
</project>
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* The Solarium Client is the main accesspoint for interaction with Solr
*/
class Solarium_Client extends Solarium_Configurable
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
'host' => '127.0.0.1',
'port' => 80,
'path' => '/solr',
'core' => null,
'adapter' => 'Solarium_Client_Adapter_Stream',
);
/**
* Adapter instance
*
* @var Solarium_Client_Adapter
*/
protected $_adapter;
/**
* Init options array. Some options might need some extra checks or setup
* work.
*
* @return void
*/
protected function _init()
{
foreach ($this->_options AS $name => $value) {
switch ($name) {
case 'path':
$this->setPath($value);
break;
}
}
}
/**
* Set an option
*
* @param string $name
* @param mixed $value
* @return void
*/
protected function _setOption($name, $value)
{
parent::_setOption($name, $value);
if (null !== $this->_adapter) {
$this->_adapter->setOptions($this->_options);
}
return $this;
}
/**
* Set host option
*
* @param string $host
* @return Solarium_Client Provides fluent interface
*/
public function setHost($host)
{
return $this->_setOption('host', $host);
}
/**
* Get host option
*
* @return string
*/
public function getHost()
{
return $this->getOption('host');
}
/**
* Set port option
*
* @param int $port
* @return Solarium_Client Provides fluent interface
*/
public function setPort($port)
{
return $this->_setOption('port', $port);
}
/**
* Get port option
* @return int
*/
public function getPort()
{
return $this->getOption('port');
}
/**
* Set path option
*
* @param string $path
* @return Solarium_Client Provides fluent interface
*/
public function setPath($path)
{
// remove trailing slashes
if (substr($path, -1) == '/') $path = substr($path, 0, -1);
return $this->_setOption('path', $path);
}
/**
* Get path option
*
* @return void
*/
public function getPath()
{
return $this->getOption('path');
}
/**
* Set core option
*
* @param string $core
* @return Solarium_Client Provides fluent interface
*/
public function setCore($core)
{
return $this->_setOption('core', $core);
}
/**
* Get core option
*
* @return string
*/
public function getCore()
{
return $this->getOption('core');
}
/**
* Set the adapter
*
* @param string|Solarium_Client_Adapter $adapter
* @return Solarium_Client Provides fluent interface
*/
public function setAdapter($adapter)
{
if (is_string($adapter)) {
$adapter = new $adapter;
}
$adapter->setOptions($this->_options);
$this->_adapter = $adapter;
return $this;
}
/**
* Get the adapter instance
*
* @return Solarium_Client_Adapter
*/
public function getAdapter()
{
if (null === $this->_adapter) {
$this->setAdapter($this->_options['adapter']);
}
return $this->_adapter;
}
/**
* Execute a ping query
*
* @param Solarium_Query_Ping $query
* @return Solarium_Result_Ping
*/
public function ping($query)
{
return $this->getAdapter()->ping($query);
}
/**
* Execute an update query
*
* @param Solarium_Query_Update $query
* @return Solarium_Result_Select
*/
public function update($query)
{
return $this->getAdapter()->update($query);
}
/**
* Execute a select query
*
* @param Solarium_Query_Select $query
* @return Solarium_Result_Select
*/
public function select($query)
{
return $this->getAdapter()->select($query);
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Base class for all adapters
*/
abstract class Solarium_Client_Adapter extends Solarium_Configurable
{
/**
* Set options (overrides any existing values)
*
* @param array $options
* @return void
*/
public function setOptions($options)
{
$this->_options = $options;
}
/**
* Abstract method to require an implementation inside all adapters.
* If the adapter cannot support this method it should implement a method
* that throws an exception.
*
* @abstract
* @param Solarium_Query_Select $query
* @return Solarium_Result_Select
*/
abstract public function select($query);
/**
* Abstract method to require an implementation inside all adapters.
* If the adapter cannot support this method it should implement a method
* that throws an exception.
*
* @abstract
* @param Solarium_Query_Ping $query
* @return Solarium_Result_Ping
*/
abstract public function ping($query);
/**
* Abstract method to require an implementation inside all adapters.
* If the adapter cannot support this method it should implement a method
* that throws an exception.
*
* @abstract
* @param Solarium_Query_Update $query
* @return Solarium_Result_Update
*/
abstract public function update($query);
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* A very basic adapter using file_get_contents for retrieving data from Solr
*/
class Solarium_Client_Adapter_Stream extends Solarium_Client_Adapter
{
/**
* Execute a select query and return a result object
*
* @param Solarium_Query_Select $query
* @return Solarium_Result_Select
*/
public function select($query)
{
$data = $this->_getSolrData(
new Solarium_Client_Request_Select($this->_options, $query)
);
$documentClass = $query->getOption('documentclass');
$documents = array();
if (isset($data['response']['docs'])) {
foreach ($data['response']['docs'] AS $doc) {
$fields = (array)$doc;
$documents[] = new $documentClass($fields);
}
}
$numFound = $data['response']['numFound'];
$resultClass = $query->getOption('resultclass');
return new $resultClass($numFound, $documents);
}
/**
* Execute a ping query and return a result object
*
* @param Solarium_Query_Ping $query
* @return Solarium_Result_Ping
*/
public function ping($query)
{
$this->_getSolrData(
new Solarium_Client_Request($this->_options, $query)
);
$resultClass = $query->getOption('resultclass');
return new $resultClass;
}
/**
* Execute an update query and return a result object
*
* @param Solarium_Query_Update $query
* @return Solarium_Result_Update
*/
public function update($query)
{
$data = $this->_getSolrData(
new Solarium_Client_Request_Update($this->_options, $query)
);
$resultClass = $query->getOption('resultclass');
return new $resultClass(
$data['responseHeader']['status'],
$data['responseHeader']['QTime']
);
}
/**
* Handle Solr communication and JSON decode
*
* @throws Solarium_Exception
* @param Solarium_Client_Request
* @return array
*/
protected function _getSolrData($request)
{
if (null !== $request && null !== $request->getPostData()) {
$context = stream_context_create(
array(
'http' => array(
'method' => 'POST',
'content' => $request->getPostData(),
'header' => 'Content-Type: text/xml; charset=UTF-8',
),
)
);
} else {
$context = null;
}
$data = @file_get_contents($request->getUrl(), false, $context);
if (false === $data) {
$error = error_get_last();
throw new Solarium_Exception($error['message']);
}
$data = json_decode($data, true);
if (null === $data) {
throw new Solarium_Exception(
'Solr JSON response could not be decoded');
}
return $data;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
*
*/
class Solarium_Client_Request
{
protected $_postData = null;
protected $_params = array();
protected $_options;
public function __construct($options, $query)
{
$this->_options = $options;
$this->_query = $query;
$this->_init();
}
protected function _init()
{
}
/**
* Build a URL for this request
*
* @return string
*/
public function getUrl()
{
$queryString = '';
if (count($this->_params) > 0) {
$queryString = http_build_query($this->_params, null, '&');
$queryString = preg_replace(
'/%5B(?:[0-9]|[1-9][0-9]+)%5D=/',
'=',
$queryString
);
}
if (null !== $this->_options['core']) {
$core = '/' . $this->_options['core'];
} else {
$core = '';
}
return 'http://' . $this->_options['host'] . ':'
. $this->_options['port'] . $this->_options['path']
. $core . $this->_query->getOption('path') . '?'
. $queryString;
}
public function getPostData()
{
return $this->_postData;
}
/**
* Render a boolean attribute
*
* @param string $name
* @param boolean $value
* @return string
*/
public function boolAttrib($name, $value)
{
if (null !== $value) {
$value = (true == $value) ? 'true' : 'false';
return $this->attrib($name, $value);
} else {
return '';
}
}
/**
* Render an attribute
*
* @param string $name
* @param striung $value
* @return string
*/
public function attrib($name, $value)
{
if (null !== $value) {
return ' ' . $name . '="' . $value . '"';
} else {
return '';
}
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Builds select request, for use in adapters.
*/
class Solarium_Client_Request_Select extends Solarium_Client_Request
{
public function _init()
{
$sort = array();
foreach ($this->_query->getSortFields() AS $field => $order) {
$sort[] = $field . ' ' . $order;
}
$this->_params = array(
'q' => $this->_query->getQuery(),
'start' => $this->_query->getStart(),
'rows' => $this->_query->getRows(),
'fl' => implode(',', $this->_query->getFields()),
'sort' => implode(',', $sort),
'wt' => 'json',
);
if (count($this->_query->getFilterQueries()) !== 0) {
$fq = array();
foreach ($this->_query->getFilterQueries()
AS $tag => $filterQuery) {
$fq[] = '{!tag='. $tag . '}' . $filterQuery;
}
$this->_params['fq'] = $fq;
}
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Builds XML messages from update queries, for use in adapters.
*/
class Solarium_Client_Request_Update extends Solarium_Client_Request
{
/**
* @throws Solarium_Exception
* @return void
*/
public function _init()
{
$this->_params = array('wt' => 'json');
$xml = '<update>';
foreach ($this->_query->getCommands() AS $command) {
switch ($command->getType()) {
case Solarium_Query_Update_Command::ADD:
$xml .= $this->buildAddXml($command);
break;
case Solarium_Query_Update_Command::DELETE:
$xml .= $this->buildDeleteXml($command);
break;
case Solarium_Query_Update_Command::OPTIMIZE:
$xml .= $this->buildOptimizeXml($command);
break;
case Solarium_Query_Update_Command::COMMIT:
$xml .= $this->buildCommitXml($command);
break;
case Solarium_Query_Update_Command::ROLLBACK:
$xml .= $this->buildRollbackXml();
break;
default:
throw new Solarium_Exception('Unsupported command type');
break;
}
}
$xml .= '</update>';
$this->_postData = $xml;
}
/**
* @param Solarium_Query_Update_Command_Add $command
* @return string
*/
public function buildAddXml($command)
{
$xml = '<add';
$xml .= $this->boolAttrib('overwrite', $command->getOverwrite());
$xml .= $this->attrib('commitWithin', $command->getCommitWithin());
$xml .= '>';
foreach ($command->getDocuments() AS $doc) {
$xml .= '<doc';
$xml .= $this->attrib('boost', $doc->getBoost());
$xml .= '>';
foreach ($doc->getFields() AS $name => $value) {
$xml .= '<field name="' . $name . '"';
$xml .= $this->attrib('boost', $doc->getFieldBoost($name));
$xml .= '>' . htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8')
. '</field>';
}
$xml .= '</doc>';
}
$xml .= '</add>';
return $xml;
}
/**
* @param Solarium_Query_Update_Command_Delete $command
* @return string
*/
public function buildDeleteXml($command)
{
$xml = '<delete>';
foreach ($command->getIds() AS $id) {
$xml .= '<id>' . htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8')
. '</id>';
}
foreach ($command->getQueries() AS $query) {
$xml .= '<query>' . htmlspecialchars($query, ENT_NOQUOTES, 'UTF-8')
. '</query>';
}
$xml .= '</delete>';
return $xml;
}
/**
* @param Solarium_Query_Update_Command_Optimize $command
* @return string
*/
public function buildOptimizeXml($command)
{
$xml = '<optimize';
$xml .= $this->boolAttrib('waitFlush', $command->getWaitFlush());
$xml .= $this->boolAttrib('waitSearcher', $command->getWaitSearcher());
$xml .= $this->attrib('maxSegments', $command->getMaxSegments());
$xml .= '/>';
return $xml;
}
/**
* @param Solarium_Query_Update_Command_Commit $command
* @return string
*/
public function buildCommitXml($command)
{
$xml = '<commit';
$xml .= $this->boolAttrib('waitFlush', $command->getWaitFlush());
$xml .= $this->boolAttrib('waitSearcher', $command->getWaitSearcher());
$xml .= $this->boolAttrib(
'expungeDeletes',
$command->getExpungeDeletes()
);
$xml .= '/>';
return $xml;
}
/**
* @return string
*/
public function buildRollbackXml()
{
return '<rollback/>';
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Base class for creating a class that is configurable using the constructor or
* setOption calls. Used by many solarium classes.
*/
class Solarium_Configurable
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
);
/**
* Constructor
*
* @throws Solarium_Exception
* @param array|Zend_Config $options
* @return void
*/
public function __construct($options = null)
{
if (null !== $options) {
// first convert to array if needed
if (!is_array($options)) {
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else {
throw new Solarium_Exception('Options must be an '
. 'array or a Zend_Config object');
}
}
// merge with default values, new values overwrite defaults
$this->_options = array_merge($this->_options, $options);
}
// Hook for extending classes (for end user classes)
$this->_init();
}
/**
* Init method for extra checks or setup work. Can be implemented in
* extending classes.
*
* @return void
*/
protected function _init()
{
}
/**
* Set an option
*
* @param string $name
* @param mixed $value
* @return Solarium_Configurable
*/
protected function _setOption($name, $value)
{
$this->_options[$name] = $value;
return $this;
}
/**
* Get an option value
*
* @param string $name
* @return mixed
*/
public function getOption($name)
{
if (isset($this->_options[$name])) {
return $this->_options[$name];
} else {
return null;
}
}
/**
* Get all options
*
* @return array
*/
public function getOptions()
{
return $this->_options;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Solr query result read-only document
*/
class Solarium_Document_ReadOnly
{
/**
* All fields in this document
*
* @var array
*/
protected $_fields;
/**
* Constructor.
*
* @param array $fields
*/
public function __construct(array $fields)
{
$this->_fields = $fields;
}
/**
* Return the complete array of fields
*
* @return array
*/
public function getFields()
{
return $this->_fields;
}
/**
* Magic access method for accessing fields as properties of this document
* object, by field name.
*
* @param string $name
* @return mixed
*/
public function __get($name)
{
if (!isset($this->_fields[$name])) {
return null;
}
return $this->_fields[$name];
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Updateable Solr document
*/
class Solarium_Document_ReadWrite extends Solarium_Document_ReadOnly
{
/**
* Document boost value
*
* @var float
*/
protected $_boost = null;
/**
* Field boosts
*
* @var array
*/
protected $_fieldBoosts;
/**
* Constructor.
*
* @param array $fields
*/
public function __construct($fields = array(), $boosts = array())
{
$this->_fields = $fields;
$this->_fieldBoosts = $boosts;
}
/**
* Add a field value. If a field already has a value it will be converted
* to a multivalue field.
*
* @param string $key
* @param mixed $value
* @param float $boost
* @return Solarium_Document_ReadWrite Provides fluent interface
*/
public function addField($key, $value, $boost = null)
{
if (!isset($this->_fields[$key])) {
$this->setField($key, $value, $boost);
} else {
// convert single value to array if needed
if (!is_array($this->_fields[$key])) {
$this->_fields[$key] = array($this->_fields[$key]);
}
$this->_fields[$key][] = $value;
$this->setFieldBoost($key, $boost);
}
return $this;
}
/**
* Set a field value. If a field already has a value it will be overwritten.
*
* @param string $key
* @param mixed $value
* @param float $boost
* @return Solarium_Document_ReadWrite Provides fluent interface
*/
public function setField($key, $value, $boost = null)
{
$this->_fields[$key] = $value;
$this->setFieldBoost($key, $boost);
return $this;
}
/**
* Remove a field from this document
*
* @param string $key
* @return Solarium_Document_ReadWrite Provides fluent interface
*/
public function removeField($key)
{
if (isset($this->_fields[$key])) {
unset($this->_fields[$key]);
}
if (isset($this->_fieldBoosts[$key])) {
unset($this->_fieldBoosts[$key]);
}
return $this;
}
/**
* Get the boost value for a single document field
*
* @param string $key
* @return float
*/
public function getFieldBoost($key)
{
if (isset($this->_fieldBoosts[$key])) {
return $this->_fieldBoosts[$key];
} else {
return null;
}
}
/**
* Set the boost value for a single field
*
* @param string $key
* @param float $boost
* @return Solarium_Document_ReadWrite Provides fluent interface
*/
public function setFieldBoost($key, $boost)
{
$this->_fieldBoosts[$key] = $boost;
return $this;
}
/**
* Set the boost value for this document
*
* @param float $boost
* @return Solarium_Document_ReadWrite Provides fluent interface
*/
public function setBoost($boost)
{
$this->_boost = $boost;
return $this;
}
/**
* Get the boost value for this document
*
* @return float
*/
public function getBoost()
{
return $this->_boost;
}
/**
* Magic access method for accessing fields as properties of this document
* object, by field name.
*
* @param string $name
* @param string $value
* @return void
*/
public function __set($name, $value)
{
$this->setField($name, $value);
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Custom exception case to allow for catching specific exceptions
*/
class Solarium_Exception extends Exception
{
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Base class for all queries
*/
class Solarium_Query extends Solarium_Configurable
{
/**
* Set path option
*
* @param string $path
* @return Solarium_Query Provides fluent interface
*/
public function setPath($path)
{
return $this->_setOption('path', $path);
}
/**
* Get path option
*
* @return string
*/
public function getPath()
{
return $this->getOption('path');
}
/**
* Set resultclass option
*
* @param string $classname
* @return Solarium_Query Provides fluent interface
*/
public function setResultClass($classname)
{
return $this->_setOption('resultclass', $classname);
}
/**
* Get resultclass option
*
* @return string
*/
public function getResultClass()
{
return $this->getOption('resultclass');
}
/**
* Escape special Solr characters in a value
* @param string $string
* @return string
*/
public function escapeValue($string)
{
$match = array('\\', '+', '-', '&', '|', '!', '(', ')', '{', '}', '[',
']', '^', '~', '*', '?', ':', '"', ';', ' ');
$replace = array('\\\\', '\\+', '\\-', '\\&', '\\|', '\\!', '\\(',
'\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\~', '\\*',
'\\?', '\\:', '\\"', '\\;', '\\ ');
$string = str_replace($match, $replace, $string);
return $string;
}
/**
* Render a param with localParams
*
* @param string $value
* @param array $localParams in key => value format
* @return string with Solr localparams syntax
*/
public function renderLocalParams($value, $localParams = array())
{
$prefix = '';
if (count($localParams) > 0) {
$prefix .= '{!';
foreach ($localParams AS $paramName => $paramValue) {
$prefix .= $paramName . '=' . $paramValue . ' ';
}
$prefix = rtrim($prefix) . '}';
}
return $prefix . $value;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Ping query
*/
class Solarium_Query_Ping extends Solarium_Query
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
'path' => '/admin/ping',
'resultclass' => 'Solarium_Result_Ping',
);
}
\ No newline at end of file
This diff is collapsed.
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Update Query
*/
class Solarium_Query_Update extends Solarium_Query
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
'path' => '/update',
'resultclass' => 'Solarium_Result_Update',
'override' => null,
'commitwithin' => null,
);
/**
* Array of commands that define this update query
*
* @var array
*/
protected $_commands = array();
/**
* Get all commands for this update query
*
* @return array
*/
public function getCommands()
{
return $this->_commands;
}
/**
* Add a command to this update query. This must be an instance of one of
* the Solarium_Query_Update_* classes.
*
* @param string $key
* @param object $command
* @return Solarium_Query_Update Provides fluent interface
*/
public function add($key, $command)
{
if (!empty($key)) {
$this->_commands[$key] = $command;
} else {
$this->_commands[] = $command;
}
return $this;
}
/**
* Remove a command, by key
*
* @param string $key
* @return Solarium_Query_Update Provides fluent interface
*/
public function remove($key)
{
if (isset($this->_commands[$key])) {
unset($this->_commands[$key]);
}
return $this;
}
/**
* Convenience method for adding a rollback.
* If you need more control, like choosing a key for the command you need to
* create you own command instances and you the add method.
*
* @return Solarium_Query_Update Provides fluent interface
*/
public function addRollback()
{
return $this->add(null, new Solarium_Query_Update_Command_Rollback);
}
/**
* Convenience method for adding a delete query.
* If you need more control, like choosing a key for the command you need to
* create you own command instances and you the add method.
*
* @param string $query
* @return Solarium_Query_Update Provides fluent interface
*/
public function addDeleteQuery($query)
{
$delete = new Solarium_Query_Update_Command_Delete;
$delete->addQuery($query);
return $this->add(null, $delete);
}
/**
* Convenience method to add multiple delete queries to the update
* If you need more control, like choosing a key for the command you need to
* create you own command instances and you the add method.
*
* @param string $key
* @param array $queries
* @return Solarium_Query_Update Provides fluent interface
*/
public function addDeleteQueries($queries)
{
$delete = new Solarium_Query_Update_Command_Delete;
$delete->addQueries($queries);
return $this->add(null, $delete);
}
/**
* Convenience method to add a delete by ID to the update
* If you need more control, like choosing a key for the command you need to
* create you own command instances and you the add method.
*
* @param int|string $id
* @return Solarium_Query_Update Provides fluent interface
*/
public function addDeleteById($id)
{
$delete = new Solarium_Query_Update_Command_Delete;
$delete->addId($id);
return $this->add(null, $delete);
}
/**
* Convenience method to add delete by multiple IDs to the update
* If you need more control, like choosing a key for the command you need to
* create you own command instances and you the add method.
*
* @param array $id
* @return Solarium_Query_Update Provides fluent interface
*/
public function addDeleteByIds($ids)
{
$delete = new Solarium_Query_Update_Command_Delete;
$delete->addIds($ids);
return $this->add(null, $delete);
}
/**
* Convenience method to add a document to the update.
* If you need more control, like choosing a key for the command you need to
* create you own command instances and you the add method.
*
* @param Solarium_Document_ReadWrite $document
* @param boolean $overwrite
* @param int $commitWithin
* @return Solarium_Query_Update Provides fluent interface
*/
public function addDocument($document, $override = null,
$commitWithin = null)
{
return $this->addDocuments(array($document), $override, $commitWithin);
}
/**
* Convenience method to add multiple documents to the update.
* If you need more control, like choosing a key for the command you need to
* create you own command instances and you the add method.
*
* @param array $documents
* @param boolean $overwrite
* @param int $commitWithin
* @return Solarium_Query_Update Provides fluent interface
*/
public function addDocuments($documents, $overwrite = null,
$commitWithin = null)
{
$add = new Solarium_Query_Update_Command_Add;
if (null !== $overwrite) $add->setOverwrite($overwrite);
if (null !== $commitWithin) $add->setCommitWithin($commitWithin);
$add->addDocuments($documents);
return $this->add(null, $add);
}
/**
* Convenience method to add a commit command to the update
* If you need more control, like choosing a key for the command you need to
* create you own command instances and you the add method.
*
* @param boolean $waitFlush
* @param boolean $waitSearcher
* @param boolean $expungeDeletes
* @return Solarium_Query_Update Provides fluent interface
*/
public function addCommit($waitFlush = null, $waitSearcher = null,
$expungeDeletes = null)
{
$commit = new Solarium_Query_Update_Command_Commit();
if (null !== $waitFlush) $commit->setWaitFlush($waitFlush);
if (null !== $waitSearcher) $commit->setWaitSearcher($waitSearcher);
if (null !== $expungeDeletes)
$commit->setExpungeDeletes($expungeDeletes);
return $this->add(null, $commit);
}
/**
* Convenience method to add an optimize command to the update
* If you need more control, like choosing a key for the command you need to
* create you own command instances and you the add method.
*
* @param boolean $waitFlush
* @param boolean $waitSearcher
* @param boolean $maxSegments
* @return Solarium_Query_Update Provides fluent interface
*/
public function addOptimize($waitFlush = null, $waitSearcher = null,
$maxSegments = null)
{
$optimize = new Solarium_Query_Update_Command_Optimize();
if (null !== $waitFlush) $optimize->setWaitFlush($waitFlush);
if (null !== $waitSearcher) $optimize->setWaitSearcher($waitSearcher);
if (null !== $maxSegments) $optimize->setMaxSegments($maxSegments);
return $this->add(null, $optimize);
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Update query add (documents) command
*/
abstract class Solarium_Query_Update_Command extends Solarium_Configurable
{
/**
* Command types
*/
const ADD = 'add';
const DELETE = 'delete';
const COMMIT = 'commit';
const OPTIMIZE = 'optimize';
const ROLLBACK = 'rollback';
/**
* Returns command type, for use in adapters
*
* @return string
*/
abstract public function getType();
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Update query add (documents) command
*/
class Solarium_Query_Update_Command_Add extends Solarium_Query_Update_Command
{
/**
* Documents to add
*
* @var array
*/
protected $_documents = array();
public function getType()
{
return Solarium_Query_Update_Command::ADD;
}
/**
* Add a single document
*
* @param object $document
* @return Solarium_Query_Update_Add Provides fluent interface
*/
public function addDocument($document)
{
$this->_documents[] = $document;
return $this;
}
/**
* Add multiple documents
*
* @param array $documents
* @return Solarium_Query_Update_Add Provides fluent interface
*/
public function addDocuments($documents)
{
$this->_documents = array_merge($this->_documents, $documents);
return $this;
}
public function getDocuments()
{
return $this->_documents;
}
/**
* @param boolean $overwrite
* @return Solarium_Query_Update_Add Provides fluent interface
*/
public function setOverwrite($overwrite)
{
return $this->_setOption('overwrite', $overwrite);
}
/**
* @return boolean
*/
public function getOverwrite()
{
return $this->getOption('overwrite');
}
/**
* @param boolean $commitWithin
* @return Solarium_Query_Update_Add Provides fluent interface
*/
public function setCommitWithin($commitWithin)
{
return $this->_setOption('commitwithin', $commitWithin);
}
/**
* @return boolean
*/
public function getCommitWithin()
{
return $this->getOption('commitwithin');
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Update query commit command
*/
class Solarium_Query_Update_Command_Commit extends Solarium_Query_Update_Command
{
public function getType()
{
return Solarium_Query_Update_Command::COMMIT;
}
/**
* @return boolean
*/
public function getWaitFlush()
{
return $this->getOption('waitflush');
}
/**
* @param boolean $waitFlush
* @return Solarium_Query_Update_Commit Provides fluent interface
*/
public function setWaitFlush($waitFlush)
{
return $this->_setOption('waitflush', $waitFlush);
}
/**
* @return boolean
*/
public function getWaitSearcher()
{
return $this->getOption('waitsearcher');
}
/**
* @param boolean $waitSearcher
* @return Solarium_Query_Update_Commit Provides fluent interface
*/
public function setWaitSearcher($waitSearcher)
{
return $this->_setOption('waitsearcher', $waitSearcher);
}
/**
* @return boolean
*/
public function getExpungeDeletes()
{
return $this->getOption('expungedeletes');
}
/**
* @param boolean $expungeDeletes
* @return Solarium_Query_Update_Commit Provides fluent interface
*/
public function setExpungeDeletes($expungeDeletes)
{
return $this->_setOption('expungedeletes', $expungeDeletes);
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Update query delete command
*/
class Solarium_Query_Update_Command_Delete extends Solarium_Query_Update_Command
{
/**
* Ids to delete
*
* @var array
*/
protected $_ids = array();
/**
* Delete queries
*
* @var array
*/
protected $_queries = array();
public function getType()
{
return Solarium_Query_Update_Command::DELETE;
}
/**
* Build ids/queries based on options
* @return void
*/
protected function _init()
{
$id = $this->getOption('id');
if (null !== $id) {
if (is_array($id)) {
$this->addIds($id);
} else {
$this->addId($id);
}
}
$queries = $this->getOption('query');
if (null !== $queries) {
if (is_array($queries)) {
$this->addQueries($queries);
} else {
$this->addQuery($queries);
}
}
}
/**
* Add a single ID to the delete command
*
* @param int|string $id
* @return Solarium_Query_Update_Delete Provides fluent interface
*/
public function addId($id)
{
$this->_ids[] = $id;
return $this;
}
/**
* Add multiple IDs to the delete command
*
* @param array $id
* @return Solarium_Query_Update_Delete Provides fluent interface
*/
public function addIds($ids)
{
$this->_ids = array_merge($this->_ids, $ids);
return $this;
}
/**
* Add a single query to the delete command
*
* @param string $query
* @return Solarium_Query_Update_Delete Provides fluent interface
*/
public function addQuery($query)
{
$this->_queries[] = $query;
return $this;
}
/**
* Add multiple queries to the delete command
*
* @param array $queries
* @return Solarium_Query_Update_Delete Provides fluent interface
*/
public function addQueries($queries)
{
$this->_queries = array_merge($this->_queries, $queries);
return $this;
}
/**
* Get all queries of this delete command
*
* @return array
*/
public function getQueries()
{
return $this->_queries;
}
/**
* Get all qids of this delete command
*
* @return array
*/
public function getIds()
{
return $this->_ids;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Update query optimize command
*/
class Solarium_Query_Update_Command_Optimize
extends Solarium_Query_Update_Command
{
public function getType()
{
return Solarium_Query_Update_Command::OPTIMIZE;
}
/**
* @return boolean
*/
public function getWaitFlush()
{
return $this->getOption('waitflush');
}
/**
* @param boolean $waitFlush
* @return Solarium_Query_Update_Optimize Provides fluent interface
*/
public function setWaitFlush($waitFlush)
{
return $this->_setOption('waitflush', $waitFlush);
}
/**
* @return boolean
*/
public function getWaitSearcher()
{
return $this->getOption('waitsearcher');
}
/**
* @param boolean $waitSearcher
* @return Solarium_Query_Update_Optimize Provides fluent interface
*/
public function setWaitSearcher($waitSearcher)
{
return $this->_setOption('waitsearcher', $waitSearcher);
}
/**
* @return boolean
*/
public function getMaxSegments()
{
return $this->getOption('maxsegments');
}
/**
* @param boolean $maxSegments
* @return Solarium_Query_Update_Optimize Provides fluent interface
*/
public function setMaxSegments($maxSegments)
{
return $this->_setOption('maxsegments', $maxSegments);
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Update query rollback command
*/
class Solarium_Query_Update_Command_Rollback
extends Solarium_Query_Update_Command
{
public function getType()
{
return Solarium_Query_Update_Command::ROLLBACK;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Ping result, holds no data as a ping request only tests the Solr
* communication
*/
class Solarium_Result_Ping
{
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Select query result
*/
class Solarium_Result_Select implements Iterator, Countable
{
/**
* Number of documents found by Solr (this is NOT the number of document
* fetched from Solr!)
*
* @var int
*/
protected $_numFound;
/**
* Document instances array
*
* @var array
*/
protected $_documents;
/**
* Pointer to document array position for iterator implementation
*
* @var int
*/
protected $_position;
/**
* Constructor. This is the only point where data can be set in this
* immutable value object.
*
* @param int $numFound
* @param array $documents
* @return void
*/
public function __construct($numFound, $documents)
{
$this->_numFound = $numFound;
$this->_documents = $documents;
}
/**
* Returns the total number of documents found by Solr (this is NOT the
* number of document fetched from Solr!)
*
* @return int
*/
public function getNumFound()
{
return $this->_numFound;
}
/**
* Return all fetched documents in an array
*
* @return array
*/
public function getDocuments()
{
return $this->_documents;
}
/**
* Count method for Countable interface
*
* @return int
*/
public function count()
{
return count($this->_documents);
}
/**
* Iterator implementation
*
* @return void
*/
public function rewind()
{
$this->_position = 0;
}
/**
* Iterator implementation
*
* @return Solarium_Result_Select_Document
*/
function current()
{
return $this->_documents[$this->_position];
}
/**
* Iterator implementation
*
* @return integer
*/
public function key()
{
return $this->_position;
}
/**
* Iterator implementation
*
* @return void
*/
public function next()
{
++$this->_position;
}
/**
* Iterator implementation
*
* @return boolean
*/
public function valid()
{
return isset($this->_documents[$this->_position]);
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* Update result
*/
class Solarium_Result_Update
{
/**
* @var int
*/
protected $_status;
/**
* @var int
*/
protected $_queryTime;
/**
* @param int $status
* @param int $queryTime
* @return void
*/
public function __construct($status, $queryTime)
{
$this->_status = $status;
$this->_queryTime = $queryTime;
}
/**
* @return int
*/
public function getStatus()
{
return $this->_status;
}
/**
* @return int
*/
public function getQueryTime()
{
return $this->_queryTime;
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
/**
* This class can be used to check the library version within your code.
* For example to check for a required version.
*/
class Solarium_Version
{
/**
* Version number
*/
const VERSION = '0.1-dev';
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
syntaxCheck="false" bootstrap="tests/bootstrap.php">
<testsuites>
<testsuite name="Solarium">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="build/coverage" title="Solarium"
charset="UTF-8" yui="true" highlight="true"
lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
</phpunit>
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
{
protected $_query;
protected $_options = array(
'host' => '127.0.0.1',
'port' => 80,
'path' => '/solr',
'core' => null,
);
public function setUp()
{
$this->_query = new Solarium_Query_Select;
}
public function testSelectUrlWithDefaultValues()
{
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$this->assertEquals(
null,
$request->getPostData()
);
$this->assertEquals(
'http://127.0.0.1:80/solr/select?q=%2A%3A%2A&start=0&rows=10&fl=%2A%2Cscore&sort=&wt=json',
$request->getUrl()
);
}
public function testSelectUrlWithSort()
{
$this->_query->addSortField('id', Solarium_Query_Select::SORT_ASC);
$this->_query->addSortField('name', Solarium_Query_Select::SORT_DESC);
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$this->assertEquals(
null,
$request->getPostData()
);
$this->assertEquals(
'http://127.0.0.1:80/solr/select?q=%2A%3A%2A&start=0&rows=10&fl=%2A%2Cscore&sort=id+asc%2Cname+desc&wt=json',
$request->getUrl()
);
}
public function testSelectUrlWithSortAndFilters()
{
$this->_query->addSortField('id', Solarium_Query_Select::SORT_ASC);
$this->_query->addSortField('name', Solarium_Query_Select::SORT_DESC);
$this->_query->addFilterQuery('f1', 'published:true');
$this->_query->addFilterQuery('f2', 'category:23');
$request = new Solarium_Client_Request_Select($this->_options, $this->_query);
$this->assertEquals(
null,
$request->getPostData()
);
$this->assertEquals(
'http://127.0.0.1:80/solr/select?q=%2A%3A%2A&start=0&rows=10&fl=%2A%2Cscore&sort=id+asc%2Cname+desc&wt=json&fq=%7B%21tag%3Df1%7Dpublished%3Atrue&fq=%7B%21tag%3Df2%7Dcategory%3A23',
$request->getUrl()
);
}
}
This diff is collapsed.
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Client_RequestTest extends PHPUnit_Framework_TestCase
{
protected $_request;
protected $_options = array(
'host' => '127.0.0.1',
'port' => 80,
'path' => '/solr',
'core' => null,
);
protected function _getRequest($options, $class = 'Solarium_Client_Request')
{
$query = new Solarium_Query;
$query->setPath('/mypath');
return new $class($options, $query);
}
public function testGetUrl()
{
$this->assertEquals(
'http://127.0.0.1:80/solr/mypath?',
$this->_getRequest($this->_options)->getUrl()
);
}
public function testGetUrlWithCore()
{
$options = $this->_options;
$options['core'] = 'core0';
$this->assertEquals(
'http://127.0.0.1:80/solr/core0/mypath?',
$this->_getRequest($options)->getUrl()
);
}
public function testBoolAttrib()
{
$this->assertEquals(
' name="false"',
$this->_getRequest($this->_options)->boolAttrib('name', false)
);
}
public function testBoolAttribNoValue()
{
$this->assertEquals(
'',
$this->_getRequest($this->_options)->boolAttrib('name', null)
);
}
public function testAttrib()
{
$this->assertEquals(
' name="myvalue"',
$this->_getRequest($this->_options)->attrib('name', 'myvalue')
);
}
public function testAttribNoValue()
{
$this->assertEquals(
'',
$this->_getRequest($this->_options)->attrib('name', null)
);
}
public function testGetUrlWithParams()
{
$this->assertEquals(
'http://127.0.0.1:80/solr/mypath?wt=json&fq=category%3A1&fq=published%3Atrue',
$this->_getRequest($this->_options, 'TestRequest')->getUrl()
);
}
public function testGetPostData()
{
$this->assertEquals(
'<data>xyz</data>',
$this->_getRequest($this->_options, 'TestRequest')->getPostdata()
);
}
}
class TestRequest extends Solarium_Client_Request
{
protected function _init()
{
$this->_postData = '<data>xyz</data>';
$this->_params = array(
'wt' => 'json',
'fq' => array('category:1','published:true')
);
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_ClientTest extends PHPUnit_Framework_TestCase
{
public function testSetAndGetHost()
{
$client = new Solarium_Client();
$client->setHost('myhost');
$this->assertEquals('myhost', $client->getHost());
}
public function testSetAndGetPort()
{
$client = new Solarium_Client();
$client->setPort(8080);
$this->assertEquals(8080, $client->getPort());
}
public function testSetAndGetPath()
{
$client = new Solarium_Client();
$client->setPath('/mysolr');
$this->assertEquals('/mysolr', $client->getPath());
}
public function testSetAndGetPathWithTrailingSlash()
{
$client = new Solarium_Client();
$client->setPath('/mysolr/');
$this->assertEquals('/mysolr', $client->getPath());
}
public function testSetAndGetCore()
{
$client = new Solarium_Client();
$client->setCore('core1');
$this->assertEquals('core1', $client->getCore());
}
public function testGetAdapterWithDefaultAdapter()
{
$client = new Solarium_Client();
$defaultAdapter = $client->getOption('adapter');
$adapter = $client->getAdapter();
$this->assertThat($adapter, $this->isInstanceOf($defaultAdapter));
}
public function testGetAdapterWithString()
{
$adapterClass = 'MyAdapter';
$client = new Solarium_Client();
$client->setAdapter($adapterClass);
$this->assertThat($client->getAdapter(), $this->isInstanceOf($adapterClass));
}
public function testGetAdapterWithObject()
{
$adapterClass = 'MyAdapter';
$client = new Solarium_Client();
$client->setAdapter(new $adapterClass);
$this->assertThat($client->getAdapter(), $this->isInstanceOf($adapterClass));
}
public function testOptionForwardingToAdapter()
{
$client = new Solarium_Client();
$options = $client->getOptions();
// initialising at adapter creation
$observer = $this->getMock('Solarium_Client_Adapter_Stream', array('setOptions'));
$observer->expects($this->once())
->method('setOptions')
->with($this->equalTo($options));
$client->setAdapter($observer);
}
public function testOptionForwardingToAdapterAfterChange()
{
$newHostValue = 'myCustomHost';
$client = new Solarium_Client;
$options = $client->getOptions();
$options['host'] = $newHostValue;
$observer = $this->getMock('Solarium_Client_Adapter_Stream', array('setOptions'));
$observer->expects($this->at(1))
->method('setOptions')
->with($this->equalTo($options));
$client->setAdapter($observer);
$client->setHost($newHostValue); // this change should trigger a new adapter->setOptions call
}
public function testSelect()
{
$client = new Solarium_Client;
$query = new Solarium_Query_Select;
// initialising at adapter creation
$observer = $this->getMock('Solarium_Client_Adapter_Stream', array('select'));
$observer->expects($this->once())
->method('select')
->with($this->equalTo($query));
$client->setAdapter($observer);
$client->select($query);
}
public function testPing()
{
$client = new Solarium_Client;
$query = new Solarium_Query_Ping;
// initialising at adapter creation
$observer = $this->getMock('Solarium_Client_Adapter_Stream', array('ping'));
$observer->expects($this->once())
->method('ping')
->with($this->equalTo($query));
$client->setAdapter($observer);
$client->ping($query);
}
public function testUpdate()
{
$client = new Solarium_Client;
$query = new Solarium_Query_Update;
// initialising at adapter creation
$observer = $this->getMock('Solarium_Client_Adapter_Stream', array('update'));
$observer->expects($this->once())
->method('update')
->with($this->equalTo($query));
$client->setAdapter($observer);
$client->update($query);
}
}
class MyAdapter extends Solarium_Client_Adapter_Stream{
public function select($query)
{
}
public function ping($query)
{
}
public function update($query)
{
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_ConfigurableTest extends PHPUnit_Framework_TestCase
{
public function testConstructorNoConfig()
{
$configTest = new ConfigTest;
$defaultOptions = array(
'option1' => 1,
'option2' => 'value 2',
);
$this->assertEquals($configTest->getOptions(), $defaultOptions);
}
//TODO testConstructorWithZendConfig
public function testConstructorWithArrayConfig()
{
$configTest = new ConfigTest(
array('option2' => 'newvalue2', 'option3' => 3)
);
// the default options should be merged with the constructor values,
// overwriting any default values.
$expectedOptions = array(
'option1' => 1,
'option2' => 'newvalue2',
'option3' => 3,
);
$this->assertEquals($expectedOptions, $configTest->getOptions());
}
public function testConstructorWithInvalidConfig()
{
$this->setExpectedException('Solarium_Exception');
new Solarium_Client('invalid');
}
public function testGetOption()
{
$configTest = new ConfigTest;
$this->assertEquals(1, $configTest->getOption('option1'));
}
public function testGetOptionWIthInvalidName()
{
$configTest = new ConfigTest();
$this->assertEquals(null, $configTest->getOption('invalidoptionname'));
}
public function testInitialisation()
{
$this->setExpectedException('Solarium_Exception');
new ConfigTestInit;
}
}
class ConfigTest extends Solarium_Configurable{
protected $_options = array(
'option1' => 1,
'option2' => 'value 2',
);
}
class ConfigTestInit extends ConfigTest{
protected function _init()
{
throw new Solarium_Exception('test init');
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Document_ReadOnlyTest extends PHPUnit_Framework_TestCase
{
protected $_doc;
protected $_fields = array(
'id' => 123,
'name' => 'Test document',
'categories' => array(1,2,3)
);
protected function setUp()
{
$this->_doc = new Solarium_Document_ReadOnly($this->_fields);
}
public function testGetFields()
{
$this->assertEquals($this->_fields,$this->_doc->getFields());
}
public function testGetFieldAsProperty()
{
$this->assertEquals(
$this->_fields['categories'],
$this->_doc->categories
);
}
public function testGetInvalidFieldAsProperty()
{
$this->assertEquals(
null,
$this->_doc->invalidfieldname
);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Document_ReadWriteTest extends PHPUnit_Framework_TestCase
{
protected $_doc;
protected $_fields = array(
'id' => 123,
'name' => 'Test document',
'categories' => array(1,2,3)
);
protected function setUp()
{
$this->_doc = new Solarium_Document_ReadWrite($this->_fields);
}
public function testConstructorWithFieldsAndBoosts()
{
$fields = array('id' => 1, 'name' => 'testname');
$boosts = array('name' => 2.7);
$doc = new Solarium_Document_ReadWrite($fields, $boosts);
$this->assertEquals(
$fields,
$doc->getFields()
);
$this->assertEquals(
2.7,
$doc->getFieldBoost('name')
);
}
public function testAddFieldNoBoost()
{
$this->_doc->addField('myfield', 'myvalue');
$expectedFields = $this->_fields;
$expectedFields['myfield'] = 'myvalue';
$this->assertEquals(
$expectedFields,
$this->_doc->getFields()
);
}
public function testAddFieldWithBoost()
{
$this->_doc->addField('myfield', 'myvalue', 2.3);
$expectedFields = $this->_fields;
$expectedFields['myfield'] = 'myvalue';
$this->assertEquals(
$expectedFields,
$this->_doc->getFields()
);
$this->assertEquals(
2.3,
$this->_doc->getFieldBoost('myfield')
);
}
public function testAddFieldMultivalue()
{
$this->_doc->addField('myfield', 'myvalue');
$expectedFields = $this->_fields;
$expectedFields['myfield'] = 'myvalue';
$this->assertEquals(
$expectedFields,
$this->_doc->getFields()
);
$this->_doc->addField('myfield', 'mysecondvalue');
$expectedFields['myfield'] = array('myvalue','mysecondvalue');
$this->assertEquals(
$expectedFields,
$this->_doc->getFields()
);
}
public function testSetField()
{
$this->_doc->setField('name', 'newname');
$expectedFields = $this->_fields;
$expectedFields['name'] = 'newname';
$this->assertEquals(
$expectedFields,
$this->_doc->getFields()
);
}
public function testRemoveField()
{
$this->_doc->removeField('name');
$expectedFields = $this->_fields;
unset($expectedFields['name']);
$this->assertEquals(
$expectedFields,
$this->_doc->getFields()
);
}
public function testRemoveFieldBoostRemoval()
{
$this->_doc->setFieldBoost('name',3.2);
$this->_doc->removeField('name');
$this->assertEquals(
null,
$this->_doc->getFieldBoost('name')
);
}
public function testRemoveInvalidField()
{
$this->_doc->removeField('invalidname'); //should silently continue...
$this->assertEquals(
$this->_fields,
$this->_doc->getFields()
);
}
public function testSetAndGetFieldBoost()
{
$this->_doc->setFieldBoost('name',2.5);
$this->assertEquals(
2.5,
$this->_doc->getFieldBoost('name')
);
}
public function testGetInvalidFieldBoost()
{
$this->assertEquals(
null,
$this->_doc->getFieldBoost('invalidname')
);
}
public function testSetAndGetBoost()
{
$this->_doc->setBoost(2.5);
$this->assertEquals(
2.5,
$this->_doc->getBoost()
);
}
public function testSetAndGetFieldByProperty()
{
$this->_doc->name = 'new name';
$this->assertEquals(
'new name',
$this->_doc->name
);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
{
public function testDummy()
{
$this->assertEquals(2,2);
}
/**
TODO testDefaultOptions
TODO testInitOptions
TODO testSetQueryWithEmptyQuery
TODO testSetQueryTrim
TODO testSetStartWithInvalidValues
TODO testSetAndGetStart
TODO testSetRowsWithInvalidValues
TODO testSetAndGetRows
TODO testAddFieldWithInvalidValues
TODO testAddField
TODO testAddFieldsCommaSeparated
TODO testAddFieldsArray
TODO testRemoveField
TODO testClearFields
TODO testSetFields
TODO testAddSortFieldEmptyValue
TODO testAddSortFieldInvalidOrder
TODO testAddSortField
TODO testAddSortFields
TODO testRemoveSortField
TODO testRemoveInvalidSortField
TODO testClearSortFields
TODO testSetSortFields
TODO testAddFilterQueryEmptyInput
TODO testAddFilterQuery
TODO testAddFilterQueries
TODO testGetFilterQueryInvalidTag
TODO testGetFilterQuery
TODO testRemoveFilterQueryInvalidTag
TODO testRemoveFilterQuery
TODO testClearFilterQueries
TODO testSetFilterQueries
TODO testSetAndGetResultClass
TODO testSetAndGetDocumentClass
TODO testCustomResultClass
TODO testCustomDocumentClass
*/
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_Update_Command_AddTest extends PHPUnit_Framework_TestCase
{
protected $_command;
public function setUp()
{
$this->_command = new Solarium_Query_Update_Command_Add;
}
public function testGetType()
{
$this->assertEquals(
Solarium_Query_Update_Command::ADD,
$this->_command->getType()
);
}
public function testAddDocument()
{
$doc = new Solarium_Document_ReadWrite(array('id' => 1));
$this->_command->addDocument($doc);
$this->assertEquals(
array($doc),
$this->_command->getDocuments()
);
}
public function testAddDocuments()
{
$doc1 = new Solarium_Document_ReadWrite(array('id' => 1));
$doc2 = new Solarium_Document_ReadWrite(array('id' => 2));
$this->_command->addDocuments(array($doc1, $doc2));
$this->assertEquals(
array($doc1, $doc2),
$this->_command->getDocuments()
);
}
public function testGetAndSetOverwrite()
{
$this->_command->setOverwrite(false);
$this->assertEquals(
false,
$this->_command->getOverwrite()
);
}
public function testGetAndSetCommitWithin()
{
$this->_command->setCommitWithin(100);
$this->assertEquals(
100,
$this->_command->getCommitWithin()
);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_Update_Command_CommitTest extends PHPUnit_Framework_TestCase
{
protected $_command;
public function setUp()
{
$this->_command = new Solarium_Query_Update_Command_Commit;
}
public function testGetType()
{
$this->assertEquals(
Solarium_Query_Update_Command::COMMIT,
$this->_command->getType()
);
}
public function testGetAndSetWaitFlush()
{
$this->_command->setWaitFlush(false);
$this->assertEquals(
false,
$this->_command->getWaitFlush()
);
}
public function testGetAndSetWaitSearcher()
{
$this->_command->setWaitSearcher(false);
$this->assertEquals(
false,
$this->_command->getWaitSearcher()
);
}
public function testGetAndSetExpungeDeletes()
{
$this->_command->setExpungeDeletes(true);
$this->assertEquals(
true,
$this->_command->getExpungeDeletes()
);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_Update_Command_DeleteTest extends PHPUnit_Framework_TestCase
{
protected $_command;
public function setUp()
{
$this->_command = new Solarium_Query_Update_Command_Delete;
}
public function testGetType()
{
$this->assertEquals(
Solarium_Query_Update_Command::DELETE,
$this->_command->getType()
);
}
public function testOptionsSingleValues()
{
$options = array(
'id' => 1,
'query' => '*:*',
);
$command = new Solarium_Query_Update_Command_Delete($options);
$this->assertEquals(
array(1),
$command->getIds()
);
$this->assertEquals(
array('*:*'),
$command->getQueries()
);
}
public function testOptionsMultiValue()
{
$options = array(
'id' => array(1,2),
'query' => array('id:1','id:2'),
);
$command = new Solarium_Query_Update_Command_Delete($options);
$this->assertEquals(
array(1,2),
$command->getIds()
);
$this->assertEquals(
array('id:1','id:2'),
$command->getQueries()
);
}
public function testAddId()
{
$this->_command->addId(1);
$this->assertEquals(
array(1),
$this->_command->getIds()
);
}
public function testAddIds()
{
$this->_command->addId(1);
$this->_command->addIds(array(2,3));
$this->assertEquals(
array(1,2,3),
$this->_command->getIds()
);
}
public function testAddQuery()
{
$this->_command->addQuery('*:*');
$this->assertEquals(
array('*:*'),
$this->_command->getQueries()
);
}
public function testAddQueries()
{
$this->_command->addQuery('*:*');
$this->_command->addQueries(array('id:1','id:2'));
$this->assertEquals(
array('*:*','id:1','id:2'),
$this->_command->getQueries()
);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_Update_Command_OptimizeTest extends PHPUnit_Framework_TestCase
{
protected $_command;
public function setUp()
{
$this->_command = new Solarium_Query_Update_Command_Optimize;
}
public function testGetType()
{
$this->assertEquals(
Solarium_Query_Update_Command::OPTIMIZE,
$this->_command->getType()
);
}
public function testGetAndSetWaitFlush()
{
$this->_command->setWaitFlush(false);
$this->assertEquals(
false,
$this->_command->getWaitFlush()
);
}
public function testGetAndSetWaitSearcher()
{
$this->_command->setWaitSearcher(false);
$this->assertEquals(
false,
$this->_command->getWaitSearcher()
);
}
public function testGetAndSetMaxSegments()
{
$this->_command->setMaxSegments(12);
$this->assertEquals(
12,
$this->_command->getMaxSegments()
);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Query_Update_Command_RollbackTest extends PHPUnit_Framework_TestCase
{
public function testGetType()
{
$command = new Solarium_Query_Update_Command_Rollback;
$this->assertEquals(
Solarium_Query_Update_Command::ROLLBACK,
$command->getType()
);
}
}
This diff is collapsed.
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_QueryTest extends PHPUnit_Framework_TestCase
{
public function testSetAndGetPath()
{
$query = new Solarium_Query;
$query->setPath('mypath');
$this->assertEquals('mypath', $query->getPath());
}
public function testSetAndGetResultClass()
{
$query = new Solarium_Query;
$query->setResultClass('myResultClass');
$this->assertEquals('myResultClass', $query->getResultClass());
}
public function testEscapeValue()
{
$query = new Solarium_Query();
$this->assertEquals(
'a\\+b',
$query->escapeValue('a+b')
);
}
public function testRenderLocalParamsWithoutParams()
{
$query = new Solarium_Query();
$this->assertEquals(
'myValue',
$query->renderLocalParams('myValue')
);
}
public function testRenderLocalParams()
{
$myParams = array('tag' => 'mytag', 'ex' => 'myexclude');
$query = new Solarium_Query();
$this->assertEquals(
'{!tag=mytag ex=myexclude}myValue',
$query->renderLocalParams('myValue', $myParams)
);
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
{
protected $_result;
public function setUp()
{
$this->_docs = array(
new Solarium_Document_ReadOnly(array('id'=>1,'name'=>'test1')),
new Solarium_Document_ReadOnly(array('id'=>2,'name'=>'test2')),
new Solarium_Document_ReadOnly(array('id'=>3,'name'=>'test3')),
);
$this->_result = new Solarium_Result_Select(100, $this->_docs);
}
public function testGetNumFound()
{
$this->assertEquals(100, $this->_result->getNumFound());
}
public function testGetDocuments()
{
$this->assertEquals($this->_docs, $this->_result->getDocuments());
}
public function testCount()
{
$this->assertEquals(3, $this->_result->count());
}
public function testIterator()
{
$docs = array();
foreach($this->_result AS $key => $doc)
{
$docs[$key] = $doc;
}
$this->assertEquals($this->_docs, $docs);
}
}
This diff is collapsed.
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
// Define path to application directory
$basePath = realpath(dirname(__FILE__) . '/../');
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath($basePath . '/library'),
realpath($basePath . '/tests/library'),
get_include_path(),
)));
// set up an autoload for Zend / Pear style class loading
spl_autoload_register(create_function('$class', '@include(str_replace("_", DIRECTORY_SEPARATOR, $class) . ".php");'));
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment