Commit 18a6a874 authored by Bas de Nooijer's avatar Bas de Nooijer

Merge branches 'develop', 'feature/analysis' and 'master' of...

Merge branches 'develop', 'feature/analysis' and 'master' of github.com:basdenooijer/solarium into develop
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get an analysis document query
$query = $client->createAnalysisDocument();
$query->setShowMatch(true);
$query->setQuery('ipod');
$doc = new Solarium_Document_ReadWrite(
array(
'id' => 'MA147LL',
'name' => 'Apple 60 GB iPod with Video Playback Black',
'manu' => 'Apple Computer Inc.',
'cat' => 'electronics',
'cat' => 'music',
'features' => 'iTunes, Podcasts, Audiobooks',
'features' => 'Stores up to 15,000 songs, 25,000 photos, or 150 hours of video',
'features' => '2.5-inch, 320x240 color TFT LCD display with LED backlight',
'features' => 'Up to 20 hours of battery life',
'features' => 'Plays AAC, MP3, WAV, AIFF, Audible, Apple Lossless, H.264 video',
'features' => 'Notes, Calendar, Phone book, Hold button, Date display, Photo wallet, Built-in games, JPEG photo playback, Upgradeable firmware, USB 2.0 compatibility, Playback speed control, Rechargeable capability, Battery level indication',
'includes' => 'earbud headphones, USB cable',
'weight' => 5.5,
'price' => 399.00,
'popularity' => 10,
'inStock' => true,
)
);
$query->addDocument($doc);
// this executes the query and returns the result
$result = $client->analyze($query);
// show the results
foreach ($result as $document) {
echo '<hr><h2>Document: ' . $document->getName() . '</h2>';
foreach ($document as $field) {
echo '<h3>Field: ' . $field->getName() . '</h3>';
$indexAnalysis = $field->getIndexAnalysis();
if (!empty($indexAnalysis)) {
echo '<h4>Index Analysis</h4>';
foreach ($indexAnalysis as $classes) {
echo '<h5>'.$classes->getName().'</h5>';
foreach($classes as $result) {
echo 'Text: ' . $result->getText() . '<br/>';
echo 'Raw text: ' . $result->getRawText() . '<br/>';
echo 'Start: ' . $result->getStart() . '<br/>';
echo 'End: ' . $result->getEnd() . '<br/>';
echo 'Position: ' . $result->getPosition() . '<br/>';
echo 'Position history: ' . implode(', ',$result->getPositionHistory()) . '<br/>';
echo 'Type: ' . htmlspecialchars($result->getType()) . '<br/>';
echo '-----------<br/>';
}
}
}
$queryAnalysis = $field->getQueryAnalysis();
if (!empty($queryAnalysis)) {
echo '<h4>Query Analysis</h4>';
foreach ($queryAnalysis as $classes) {
echo '<h5>'.$classes->getName().'</h5>';
foreach($classes as $result) {
echo 'Text: ' . $result->getText() . '<br/>';
echo 'Raw text: ' . $result->getRawText() . '<br/>';
echo 'Start: ' . $result->getStart() . '<br/>';
echo 'End: ' . $result->getEnd() . '<br/>';
echo 'Position: ' . $result->getPosition() . '<br/>';
echo 'Position history: ' . implode(', ',$result->getPositionHistory()) . '<br/>';
echo 'Type: ' . htmlspecialchars($result->getType()) . '<br/>';
echo '-----------<br/>';
}
}
}
}
}
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get an analysis document query
$query = $client->createAnalysisField();
$query->setShowMatch(true);
$query->setFieldName('cat,title');
$query->setFieldType('text_general');
$query->setFieldValue('Apple 60 GB iPod with Video Playback Black');
$query->setQuery('ipod');
// this executes the query and returns the result
$results = $client->analyze($query);
// show the results
foreach ($results as $result) {
echo '<hr><h2>Result list: ' . $result->getName() . '</h2>';
foreach ($result as $item) {
echo '<h3>Item: ' . $item->getName() . '</h3>';
$indexAnalysis = $item->getIndexAnalysis();
if (!empty($indexAnalysis)) {
echo '<h4>Index Analysis</h4>';
foreach ($indexAnalysis as $classes) {
echo '<h5>'.$classes->getName().'</h5>';
foreach($classes as $result) {
echo 'Text: ' . $result->getText() . '<br/>';
echo 'Raw text: ' . $result->getRawText() . '<br/>';
echo 'Start: ' . $result->getStart() . '<br/>';
echo 'End: ' . $result->getEnd() . '<br/>';
echo 'Position: ' . $result->getPosition() . '<br/>';
echo 'Position history: ' . implode(', ',$result->getPositionHistory()) . '<br/>';
echo 'Type: ' . htmlspecialchars($result->getType()) . '<br/>';
echo '-----------<br/>';
}
}
}
$queryAnalysis = $item->getQueryAnalysis();
if (!empty($queryAnalysis)) {
echo '<h4>Query Analysis</h4>';
foreach ($queryAnalysis as $classes) {
echo '<h5>'.$classes->getName().'</h5>';
foreach($classes as $result) {
echo 'Text: ' . $result->getText() . '<br/>';
echo 'Raw text: ' . $result->getRawText() . '<br/>';
echo 'Start: ' . $result->getStart() . '<br/>';
echo 'End: ' . $result->getEnd() . '<br/>';
echo 'Position: ' . $result->getPosition() . '<br/>';
echo 'Position history: ' . implode(', ',$result->getPositionHistory()) . '<br/>';
echo 'Type: ' . htmlspecialchars($result->getType()) . '<br/>';
echo '-----------<br/>';
}
}
}
}
}
htmlFooter();
\ No newline at end of file
......@@ -67,6 +67,12 @@
<li><a href="2.3.1-mlt-query.php">2.3.1 MoreLikeThis query</a></li>
<li><a href="2.3.2-mlt-stream.php">2.3.2 MoreLikeThis query input as stream</a></li>
</ul>
<li>2.4. Analysis queries</li>
<ul style="list-style:none;">
<li><a href="2.4.1-analysis-document.php">2.4.1 Analysis query for a document</a></li>
<li><a href="2.4.2-analysis-field.php">2.4.2 Analysis query for a field</a></li>
</ul>
</ul>
<li>4. Usage modes</li>
......
......@@ -77,6 +77,16 @@ class Solarium_Client extends Solarium_Configurable
*/
const QUERYTYPE_MORELIKETHIS = 'mlt';
/**
* Querytype analysis field
*/
const QUERYTYPE_ANALYSIS_FIELD = 'analysis-field';
/**
* Querytype analysis document
*/
const QUERYTYPE_ANALYSIS_DOCUMENT = 'analysis-document';
/**
* Default options
*
......@@ -112,6 +122,16 @@ class Solarium_Client extends Solarium_Configurable
'requestbuilder' => 'Solarium_Client_RequestBuilder_MoreLikeThis',
'responseparser' => 'Solarium_Client_ResponseParser_MoreLikeThis'
),
self::QUERYTYPE_ANALYSIS_DOCUMENT => array(
'query' => 'Solarium_Query_Analysis_Document',
'requestbuilder' => 'Solarium_Client_RequestBuilder_Analysis_Document',
'responseparser' => 'Solarium_Client_ResponseParser_Analysis_Document'
),
self::QUERYTYPE_ANALYSIS_FIELD => array(
'query' => 'Solarium_Query_Analysis_Field',
'requestbuilder' => 'Solarium_Client_RequestBuilder_Analysis_Field',
'responseparser' => 'Solarium_Client_ResponseParser_Analysis_Field'
),
);
/**
......@@ -587,6 +607,20 @@ class Solarium_Client extends Solarium_Configurable
return $this->execute($query);
}
/**
* Execute an analysis query
*
* @internal This is a convenience method that forwards the query to the
* execute method, thus allowing for an easy to use and clean API.
*
* @param Solarium_Query_Analysis_Document|Solarium_Query_Analysis_Field $query
* @return Solarium_Result_Analysis_Document|Solarium_Result_Analysis_Field
*/
public function analyze($query)
{
return $this->execute($query);
}
/**
* Create a query instance
*
......@@ -657,5 +691,25 @@ class Solarium_Client extends Solarium_Configurable
return $this->createQuery(self::QUERYTYPE_PING, $options);
}
/**
* Create an analysis field query instance
*
* @param mixed $options
* @return Solarium_Query_Analysis_Field
*/
public function createAnalysisField($options = null)
{
return $this->createQuery(self::QUERYTYPE_ANALYSIS_FIELD, $options);
}
/**
* Create an analysis document query instance
*
* @param mixed $options
* @return Solarium_Query_Analysis_Document
*/
public function createAnalysisDocument($options = null)
{
return $this->createQuery(self::QUERYTYPE_ANALYSIS_DOCUMENT, $options);
}
}
<?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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Build an analysis request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Analysis extends Solarium_Client_RequestBuilder
{
/**
* Build request for an analysis query
*
* @param Solarium_Query_Analysis $query
* @return Solarium_Client_Request
*/
public function build($query)
{
$request = new Solarium_Client_Request;
$request->setHandler($query->getHandler());
$request->addParam('wt', 'json');
$request->addParam('analysis.query', $query->getQuery());
$request->addParam('analysis.showmatch', $query->getShowMatch());
return $request;
}
}
\ 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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Build a document analysis request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Analysis_Document extends Solarium_Client_RequestBuilder_Analysis
{
/**
* Build request for an analysis document query
*
* @param Solarium_Query_Analysis_Document $query
* @return Solarium_Client_Request
*/
public function build($query)
{
$request = parent::build($query);
$request->setRawData($this->getRawData($query));
$request->setMethod(Solarium_Client_Request::METHOD_POST);
return $request;
}
/**
* Create the raw post data (xml)
*
* @param Solarium_Query_Analysis_Document $query
* @return string
*/
public function getRawData($query)
{
$xml = '<docs>';
foreach ($query->getDocuments() AS $doc) {
$xml .= '<doc>';
foreach ($doc->getFields() AS $name => $value) {
if (is_array($value)) {
foreach ($value AS $multival) {
$xml .= $this->_buildFieldXml($name, $multival);
}
} else {
$xml .= $this->_buildFieldXml($name, $value);
}
}
$xml .= '</doc>';
}
$xml .= '</docs>';
return $xml;
}
/**
* Build XML for a field
*
* @param string $name
* @param mixed $value
* @return string
*/
protected function _buildFieldXml($name, $value)
{
return '<field name="' . $name . '">' . htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8') . '</field>';
}
}
\ 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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Build a field analysis request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Analysis_Field extends Solarium_Client_RequestBuilder_Analysis
{
/**
* Build request for an analysis field query
*
* @param Solarium_Query_Analysis_Field $query
* @return Solarium_Client_Request
*/
public function build($query)
{
$request = parent::build($query);
$request->addParam('analysis.fieldvalue', $query->getFieldValue());
$request->addParam('analysis.fieldname', $query->getFieldName());
$request->addParam('analysis.fieldtype', $query->getFieldType());
return $request;
}
}
\ 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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Parse document analysis response data
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_ResponseParser_Analysis_Document extends Solarium_Client_ResponseParser_Analysis_Field
{
/**
* Parse implementation
*
* @param array $data
* @return array
*/
protected function _parseAnalysis($data)
{
$documents = array();
foreach($data as $documentKey => $documentData) {
$fields = $this->_parseTypes($documentData);
$documents[] = new Solarium_Result_Analysis_List($documentKey, $fields);
}
return $documents;
}
}
\ 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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Parse document analysis response data
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_ResponseParser_Analysis_Field extends Solarium_Client_ResponseParser
{
/**
* Parse response data
*
* @param Solarium_Result_Update $result
* @return array
*/
public function parse($result)
{
$data = $result->getData();
if (isset($data['analysis'])) {
$items = $this->_parseAnalysis($data['analysis']);
} else {
$items = array();
}
return array(
'status' => $data['responseHeader']['status'],
'queryTime' => $data['responseHeader']['QTime'],
'items' => $items
);
}
/**
* Parser
*
* @param array $data
* @return array
*/
protected function _parseAnalysis($data)
{
$types = array();
foreach($data as $documentKey => $documentData) {
$fields = $this->_parseTypes($documentData);
$types[] = new Solarium_Result_Analysis_List($documentKey, $fields);
}
return $types;
}
/**
* Parse analysis types and items
*
* @param array $typeData
* @return array
*/
protected function _parseTypes($typeData)
{
$results = array();
foreach ($typeData as $fieldKey => $fieldData) {
$types = array();
foreach ($fieldData as $typeKey => $typeData) {
// fix for extra level for key fields
if(count($typeData) == 1){
$typeData = current($typeData);
}
$counter = 0;
$classes = array();
while(isset($typeData[$counter]) && isset($typeData[$counter+1])) {
$class = $typeData[$counter];
$analysis = $typeData[$counter+1];
$items = array();
foreach($analysis AS $itemData) {
$items[] = new Solarium_Result_Analysis_Item($itemData);
}
$classes[] = new Solarium_Result_Analysis_List($class, $items);
$counter += 2;
}
$types[] = new Solarium_Result_Analysis_List($typeKey, $classes);
}
$results[] = new Solarium_Result_Analysis_Types($fieldKey, $types);
}
return $results;
}
}
\ 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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Query
*/
/**
* Base class for Analysis queries
*
* @package Solarium
* @subpackage Query
*/
abstract class Solarium_Query_Analysis extends Solarium_Query
{
/**
* Set the query string
*
* When present, the text that will be analyzed. The analysis will mimic the query-time analysis.
*
* @param string $query
* @param array $bind Optional bind values for placeholders in the query string
* @return Solarium_Query_Analysis Provides fluent interface
*/
public function setQuery($query, $bind = null)
{
if (!is_null($bind)) {
$query = $this->getHelper()->assemble($query, $bind);
}
return $this->_setOption('query', trim($query));
}
/**
* Get the query string
*
* @return string
*/
public function getQuery()
{
return $this->getOption('query');
}
/**
* Set the showmatch option
*
* @param boolean $show
* @return Solarium_Query_Analysis Provides fluent interface
*/
public function setShowMatch($show)
{
return $this->_setOption('showmatch', $show);
}
/**
* Get the showmatch option
*
* @return mixed
*/
public function getShowMatch()
{
return $this->getOption('showmatch');
}
}
\ 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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Query
*/
/**
* Analysis document query
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Analysis_Document extends Solarium_Query_Analysis
{
/**
* Documents to analyze
*
* @var array
*/
protected $_documents = array();
/**
* Default options
*
* @var array
*/
protected $_options = array(
'handler' => 'analysis/document',
'resultclass' => 'Solarium_Result_Analysis_Document',
);
/**
* Get type for this query
*
* @return string
*/
public function getType()
{
return Solarium_Client::QUERYTYPE_ANALYSIS_DOCUMENT;
}
/**
* Add a single document
*
* @param object $document
* @return Solarium_Query_Analysis_Document Provides fluent interface
*/
public function addDocument($document)
{
$this->_documents[] = $document;
return $this;
}
/**
* Add multiple documents
*
* @param array $documents
* @return Solarium_Query_Analysis_Document fluent interface
*/
public function addDocuments($documents)
{
$this->_documents = array_merge($this->_documents, $documents);
return $this;
}
/**
* Get all documents
*
* @return array
*/
public function getDocuments()
{
return $this->_documents;
}
}
\ 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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Query
*/
/**
* Analysis document query
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Analysis_Field extends Solarium_Query_Analysis
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
'handler' => 'analysis/field',
'resultclass' => 'Solarium_Result_Analysis_Field',
);
/**
* Get type for this query
*
* @return string
*/
public function getType()
{
return Solarium_Client::QUERYTYPE_ANALYSIS_FIELD;
}
/**
* Set the field value option
*
* The text that will be analyzed. The analysis will mimic the index-time analysis.
*
* @param string $value
* @return Solarium_Query_Analysis_Field Provides fluent interface
*/
public function setFieldValue($value)
{
return $this->_setOption('fieldvalue', $value);
}
/**
* Get the field value option
*
* @return string
*/
public function getFieldValue()
{
return $this->getOption('fieldvalue');
}
/**
* Set the field type option
*
* When present, the text will be analyzed based on the specified type
*
* @param string $type
* @return Solarium_Query_Analysis_Field Provides fluent interface
*/
public function setFieldType($type)
{
return $this->_setOption('fieldtype', $type);
}
/**
* Get the fieldtype option
*
* @return string
*/
public function getFieldType()
{
return $this->getOption('fieldtype');
}
/**
* Set the field name option
*
* When present, the text will be analyzed based on the type of this field name
*
* @param string $name
* @return Solarium_Query_Analysis_Field Provides fluent interface
*/
public function setFieldName($name)
{
return $this->_setOption('fieldname', $name);
}
/**
* Get the fieldname option
*
* @return string
*/
public function getFieldName()
{
return $this->getOption('fieldname');
}
}
\ 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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Analysis document query result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Analysis_Document extends Solarium_Result_QueryType
implements IteratorAggregate, Countable
{
/**
* Document instances array
*
* @var array
*/
protected $_items;
/**
* Status code returned by Solr
*
* @var int
*/
protected $_status;
/**
* Solr index queryTime
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @var int
*/
protected $_queryTime;
/**
* Get Solr status code
*
* This is not the HTTP status code! The normal value for success is 0.
*
* @return int
*/
public function getStatus()
{
$this->_parseResponse();
return $this->_status;
}
/**
* Get Solr query time
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @return int
*/
public function getQueryTime()
{
$this->_parseResponse();
return $this->_queryTime;
}
/**
* Get all documents
*
* @return array
*/
public function getDocuments()
{
$this->_parseResponse();
return $this->_items;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
$this->_parseResponse();
return new ArrayIterator($this->_items);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
$this->_parseResponse();
return count($this->_items);
}
/**
* Get a document by uniquekey value
*
* @param string $key
* @return Solarium_Result_Analysis_List|null
*/
public function getDocument($key)
{
$this->_parseResponse();
if(isset($this->_items[$key])) {
return $this->_items[$key];
} else {
return null;
}
}
}
\ 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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Analysis field query result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Analysis_Field extends Solarium_Result_QueryType
implements IteratorAggregate, Countable
{
/**
* List instances array
*
* @var array
*/
protected $_items;
/**
* Status code returned by Solr
*
* @var int
*/
protected $_status;
/**
* Solr index queryTime
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @var int
*/
protected $_queryTime;
/**
* Get Solr status code
*
* This is not the HTTP status code! The normal value for success is 0.
*
* @return int
*/
public function getStatus()
{
$this->_parseResponse();
return $this->_status;
}
/**
* Get Solr query time
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @return int
*/
public function getQueryTime()
{
$this->_parseResponse();
return $this->_queryTime;
}
/**
* Get all lists
*
* @return array
*/
public function getLists()
{
$this->_parseResponse();
return $this->_items;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
$this->_parseResponse();
return new ArrayIterator($this->_items);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
$this->_parseResponse();
return count($this->_items);
}
}
\ 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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Analysis item
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Analysis_Item
{
/**
* @var string
*/
protected $_text;
/**
* @var string
*/
protected $_rawText;
/**
* @var int
*/
protected $_start;
/**
* @var int
*/
protected $_end;
/**
* @var int
*/
protected $_position;
/**
* @var array
*/
protected $_positionHistory;
/**
* @var string
*/
protected $_type;
/**
* Constructor
*
* @param array $analysis
*/
public function __construct($analysis)
{
$this->_text = $analysis['text'];
$this->_start = $analysis['start'];
$this->_end = $analysis['end'];
$this->_position = $analysis['position'];
$this->_positionHistory = $analysis['positionHistory'];
$this->_type = $analysis['type'];
if (isset($analysis['raw_text'])) {
$this->_rawText = $analysis['raw_text'];
}
}
/**
* Get text value
*
* @return string
*/
public function getText()
{
return $this->_text;
}
/**
* Get raw text value
*
* This values is not available in all cases
*
* @return string
*/
public function getRawText()
{
return $this->_rawText;
}
/**
* Get start value
*
* @return int
*/
public function getStart()
{
return $this->_start;
}
/**
* Get end value
*
* @return int
*/
public function getEnd()
{
return $this->_end;
}
/**
* Get postion value
*
* @return int
*/
public function getPosition()
{
return $this->_position;
}
/**
* Get position history value
*
* @return array
*/
public function getPositionHistory()
{
return $this->_positionHistory;
}
/**
* Get type value
*
* @return string
*/
public function getType()
{
return $this->_type;
}
}
\ 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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Analysis list result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Analysis_List implements IteratorAggregate, Countable
{
/**
* @var string
*/
protected $_name;
/**
* @var array
*/
protected $_items;
/**
* Constructor
*
* @param string $name
* @param array $items
*/
public function __construct($name, $items)
{
$this->_name = $name;
$this->_items = $items;
}
/**
* Get type value
*
* @return string
*/
public function getName()
{
return $this->_name;
}
/**
* Get all items
*
* @return array
*/
public function getItems()
{
return $this->_items;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_items);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_items);
}
}
\ 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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Analysis types result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Analysis_Types extends Solarium_Result_Analysis_List
{
/**
* Get index analysis list
*
* @return Solarium_Result_Analysis_List|null
*/
public function getIndexAnalysis()
{
foreach($this->_items AS $item)
{
if ($item->getName() == 'index') {
return $item;
}
}
return null;
}
/**
* Get query analysis list
*
* @return Solarium_Result_Analysis_List|null
*/
public function getQueryAnalysis()
{
foreach($this->_items AS $item)
{
if ($item->getName() == 'query') {
return $item;
}
}
return null;
}
}
\ 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_RequestBuilder_Analysis_DocumentTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Analysis_Document
*/
protected $_query;
/**
* @var Solarium_Client_RequestBuilder_Analysis_Document
*/
protected $_builder;
public function setUp()
{
$this->_query = new Solarium_Query_Analysis_Document();
$this->_builder = new Solarium_Client_RequestBuilder_Analysis_Document;
}
public function testBuild()
{
$request = $this->_builder->build($this->_query);
$this->assertEquals(Solarium_Client_Request::METHOD_POST, $request->getMethod());
$this->assertEquals($this->_builder->getRawData($this->_query), $request->getRawData());
}
public function testGetRawData()
{
// this doc tests data escaping
$doc1 = new Solarium_Document_ReadWrite(array('id' => 1, 'name' => 'doc1', 'cat' => 'my > cat'));
// this doc tests a multivalue field
$doc2 = new Solarium_Document_ReadWrite(array('id' => 2, 'name' => 'doc2', 'cat' => array(1,2,3)));
$this->_query->addDocuments(array($doc1, $doc2));
$this->assertEquals(
'<docs><doc><field name="id">1</field><field name="name">doc1</field><field name="cat">my &gt; cat</field></doc><doc><field name="id">2</field><field name="name">doc2</field><field name="cat">1</field><field name="cat">2</field><field name="cat">3</field></doc></docs>',
$this->_builder->getRawData($this->_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_Client_RequestBuilder_Analysis_FieldTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Analysis_Field
*/
protected $_query;
/**
* @var Solarium_Client_RequestBuilder_Analysis_Field
*/
protected $_builder;
public function setUp()
{
$this->_query = new Solarium_Query_Analysis_Field();
$this->_builder = new Solarium_Client_RequestBuilder_Analysis_Field;
}
public function testBuild()
{
$fieldValue = 'myvalue';
$fieldName = 'myfield';
$fieldType = 'text';
$this->_query->setFieldValue($fieldValue)
->setFieldName($fieldName)
->setFieldType($fieldType);
$request = $this->_builder->build($this->_query);
$this->assertEquals($fieldValue, $request->getParam('analysis.fieldvalue'));
$this->assertEquals($fieldName, $request->getParam('analysis.fieldname'));
$this->assertEquals($fieldType, $request->getParam('analysis.fieldtype'));
}
}
\ 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_RequestBuilder_AnalysisTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Analysis_Field
*/
protected $_query;
/**
* @var Solarium_Client_RequestBuilder_Analysis
*/
protected $_builder;
public function setUp()
{
$this->_query = new Solarium_Query_Analysis_Field();
$this->_builder = new Solarium_Client_RequestBuilder_Analysis;
}
public function testBuild()
{
$query = 'cat:1';
$showMatch = true;
$handler = 'myhandler';
$this->_query->setQuery($query)
->setShowMatch($showMatch)
->setHandler($handler);
$request = $this->_builder->build($this->_query);
$this->assertEquals(
array(
'wt' => 'json',
'analysis.query' => $query,
'analysis.showmatch' => $showMatch,
),
$request->getParams()
);
$this->assertEquals($handler, $request->getHandler());
}
}
\ No newline at end of file
......@@ -617,6 +617,18 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$observer->moreLikeThis($query);
}
public function testAnalyze()
{
$query = new Solarium_Query_Analysis_Field();
$observer = $this->getMock('Solarium_Client', array('execute'));
$observer->expects($this->once())
->method('execute')
->with($this->equalTo($query));
$observer->analyze($query);
}
public function testCreateQuery()
{
$options = array('optionA' => 1, 'optionB' => 2);
......@@ -737,6 +749,30 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$observer->createMoreLikeThis($options);
}
public function testCreateAnalysisField()
{
$options = array('optionA' => 1, 'optionB' => 2);
$observer = $this->getMock('Solarium_Client', array('createQuery'));
$observer->expects($this->once())
->method('createQuery')
->with($this->equalTo(Solarium_Client::QUERYTYPE_ANALYSIS_FIELD), $this->equalTo($options));
$observer->createAnalysisField($options);
}
public function testCreateAnalysisDocument()
{
$options = array('optionA' => 1, 'optionB' => 2);
$observer = $this->getMock('Solarium_Client', array('createQuery'));
$observer->expects($this->once())
->method('createQuery')
->with($this->equalTo(Solarium_Client::QUERYTYPE_ANALYSIS_DOCUMENT), $this->equalTo($options));
$observer->createAnalysisDocument($options);
}
}
class MyAdapter extends Solarium_Client_Adapter_Http{
......
<?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_Analysis_DocumentTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Analysis_Document
*/
protected $_query;
public function setUp()
{
$this->_query = new Solarium_Query_Analysis_Document;
}
public function testGetType()
{
$this->assertEquals(Solarium_Client::QUERYTYPE_ANALYSIS_DOCUMENT, $this->_query->getType());
}
public function testAddAndGetDocument()
{
$doc = new Solarium_Document_ReadWrite(array('id' => 1));
$this->_query->addDocument($doc);
$this->assertEquals(
array($doc),
$this->_query->getDocuments()
);
}
public function testAddAndGetDocuments()
{
$doc1 = new Solarium_Document_ReadWrite(array('id' => 1));
$doc2 = new Solarium_Document_ReadWrite(array('id' => 2));
$this->_query->addDocuments(array($doc1, $doc2));
$this->assertEquals(
array($doc1, $doc2),
$this->_query->getDocuments()
);
}
}
\ 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_Query_Analysis_FieldTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Analysis_Field
*/
protected $_query;
public function setUp()
{
$this->_query = new Solarium_Query_Analysis_Field;
}
public function testGetType()
{
$this->assertEquals(Solarium_Client::QUERYTYPE_ANALYSIS_FIELD, $this->_query->getType());
}
public function testSetAndGetFieldValue()
{
$data = 'testdata';
$this->_query->setFieldValue($data);
$this->assertEquals($data, $this->_query->getFieldValue());
}
public function testSetAndGetFieldType()
{
$data = 'testdata';
$this->_query->setFieldType($data);
$this->assertEquals($data, $this->_query->getFieldType());
}
public function testSetAndGetFieldName()
{
$data = 'testdata';
$this->_query->setFieldName($data);
$this->assertEquals($data, $this->_query->getFieldName());
}
}
\ 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_Query_AnalysisTest extends PHPUnit_Framework_TestCase
{
protected $_query;
public function setUp()
{
$this->_query = new TestAnalysisQuery;
}
public function testSetAndGetQuery()
{
$querystring = 'test query values';
$this->_query->setQuery($querystring);
$this->assertEquals($querystring, $this->_query->getQuery());
}
public function testSetAndGetQueryWithBind()
{
$this->_query->setQuery('id:%1%', array(678));
$this->assertEquals('id:678', $this->_query->getQuery());
}
public function testSetAndGetShowMatch()
{
$show = true;
$this->_query->setShowMatch($show);
$this->assertEquals($show, $this->_query->getShowMatch());
}
}
class TestAnalysisQuery extends Solarium_Query_Analysis{
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.
*/
class Solarium_Result_Analysis_DocumentTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Analysis_Document
*/
protected $_result;
protected $_items;
public function setUp()
{
$this->_items = array('key1' => 'dummy1', 'key2' => 'dummy2', 'key3' => 'dummy3');
$this->_result = new Solarium_Result_Analysis_DocumentDummy(1, 12, $this->_items);
}
public function testGetDocuments()
{
$this->assertEquals($this->_items, $this->_result->getDocuments());
}
public function testCount()
{
$this->assertEquals(count($this->_items), count($this->_result));
}
public function testIterator()
{
$docs = array();
foreach($this->_result AS $key => $doc)
{
$docs[$key] = $doc;
}
$this->assertEquals($this->_items, $docs);
}
public function testGetStatus()
{
$this->assertEquals(
1,
$this->_result->getStatus()
);
}
public function testGetQueryTime()
{
$this->assertEquals(
12,
$this->_result->getQueryTime()
);
}
public function testGetDocument()
{
$this->assertEquals(
$this->_items['key2'],
$this->_result->getDocument('key2')
);
}
public function testGetInvalidDocument()
{
$this->assertEquals(
null,
$this->_result->getDocument('invalidkey')
);
}
}
class Solarium_Result_Analysis_DocumentDummy extends Solarium_Result_Analysis_Document
{
protected $_parsed = true;
public function __construct($status, $queryTime, $items)
{
$this->_items = $items;
$this->_queryTime = $queryTime;
$this->_status = $status;
}
}
\ 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_Analysis_FieldTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Analysis_Field
*/
protected $_result;
protected $_items;
public function setUp()
{
$this->_items = array('key1' => 'dummy1', 'key2' => 'dummy2', 'key3' => 'dummy3');
$this->_result = new Solarium_Result_Analysis_FieldDummy(1, 12, $this->_items);
}
public function testGetLists()
{
$this->assertEquals($this->_items, $this->_result->getLists());
}
public function testCount()
{
$this->assertEquals(count($this->_items), count($this->_result));
}
public function testIterator()
{
$lists = array();
foreach($this->_result AS $key => $list)
{
$lists[$key] = $list;
}
$this->assertEquals($this->_items, $lists);
}
public function testGetStatus()
{
$this->assertEquals(
1,
$this->_result->getStatus()
);
}
public function testGetQueryTime()
{
$this->assertEquals(
12,
$this->_result->getQueryTime()
);
}
}
class Solarium_Result_Analysis_FieldDummy extends Solarium_Result_Analysis_Field
{
protected $_parsed = true;
public function __construct($status, $queryTime, $items)
{
$this->_items = $items;
$this->_queryTime = $queryTime;
$this->_status = $status;
}
}
\ 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_Analysis_ItemTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Analysis_Item
*/
protected $_item;
protected $_data;
public function setUp()
{
$this->_data = array(
'text' => 'dummytest',
'start' => 10,
'end' => 22,
'position' => 2,
'positionHistory' => array(2,1),
'type' => '<dummytype>',
'raw_text' => 'dummy raw text'
);
$this->_item = new Solarium_Result_Analysis_Item($this->_data);
}
public function testGetText()
{
$this->assertEquals($this->_data['text'], $this->_item->getText());
}
public function testGetStart()
{
$this->assertEquals($this->_data['start'], $this->_item->getStart());
}
public function testGetEnd()
{
$this->assertEquals($this->_data['end'], $this->_item->getEnd());
}
public function testGetPosition()
{
$this->assertEquals($this->_data['position'], $this->_item->getPosition());
}
public function testGetPositionHistory()
{
$this->assertEquals($this->_data['positionHistory'], $this->_item->getPositionHistory());
}
public function testGetRawText()
{
$this->assertEquals($this->_data['raw_text'], $this->_item->getRawText());
}
public function testGetType()
{
$this->assertEquals($this->_data['type'], $this->_item->getType());
}
public function testGetRawTextEmpty()
{
$data = array(
'text' => 'dummytest',
'start' => 10,
'end' => 22,
'position' => 2,
'positionHistory' => array(2,1),
'type' => '<dummytype>',
);
$item = new Solarium_Result_Analysis_Item($data);
$this->assertEquals(null, $item->getRawText());
}
}
\ 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_Analysis_ListTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Analysis_List
*/
protected $_result;
protected $_items, $_name;
public function setUp()
{
$this->_name = 'testname';
$this->_items = array('key1' => 'dummy1', 'key2' => 'dummy2', 'key3' => 'dummy3');
$this->_result = new Solarium_Result_Analysis_List($this->_name, $this->_items);
}
public function testGetItems()
{
$this->assertEquals($this->_items, $this->_result->getItems());
}
public function testCount()
{
$this->assertEquals(count($this->_items), count($this->_result));
}
public function testIterator()
{
$lists = array();
foreach($this->_result AS $key => $list)
{
$lists[$key] = $list;
}
$this->assertEquals($this->_items, $lists);
}
public function testGetName()
{
$this->assertEquals(
$this->_name,
$this->_result->getName()
);
}
}
\ 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_Analysis_TypesTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Analysis_Types
*/
protected $_result;
protected $_items, $_name;
public function setUp()
{
$this->_name = 'testname';
$this->_items = array(
'index' => new testAnalysisTypeIndexDummy(),
'query' => new testAnalysisTypeQueryDummy()
);
$this->_result = new Solarium_Result_Analysis_Types($this->_name, $this->_items);
}
public function testGetItems()
{
$this->assertEquals($this->_items, $this->_result->getItems());
}
public function testCount()
{
$this->assertEquals(count($this->_items), count($this->_result));
}
public function testIterator()
{
$lists = array();
foreach($this->_result AS $key => $list)
{
$lists[$key] = $list;
}
$this->assertEquals($this->_items, $lists);
}
public function testGetName()
{
$this->assertEquals(
$this->_name,
$this->_result->getName()
);
}
public function testGetIndexAnalysis()
{
$this->assertEquals(
$this->_items['index'],
$this->_result->getIndexAnalysis()
);
}
public function testGetIndexAnalysisNoData()
{
$items = array(
'index' => new testAnalysisTypeInvalidDummy(),
'query' => new testAnalysisTypeQueryDummy()
);
$result = new Solarium_Result_Analysis_Types($this->_name, $items);
$this->assertEquals(
null,
$result->getIndexAnalysis()
);
}
public function testGetQueryAnalysis()
{
$this->assertEquals(
$this->_items['query'],
$this->_result->getQueryAnalysis()
);
}
public function testGetQueryAnalysisNoData()
{
$items = array(
'index' => new testAnalysisTypeIndexDummy(),
'query' => new testAnalysisTypeInvalidDummy()
);
$result = new Solarium_Result_Analysis_Types($this->_name, $items);
$this->assertEquals(
null,
$result->getQueryAnalysis()
);
}
}
class testAnalysisTypeIndexDummy{
public function getName(){
return 'index';
}
}
class testAnalysisTypeQueryDummy{
public function getName(){
return 'query';
}
}
class testAnalysisTypeInvalidDummy{
public function getName(){
return 'invalid';
}
}
\ 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