Commit 7b57f3e2 authored by Bas de Nooijer's avatar Bas de Nooijer

Merge branch 'release/2.4.0'

parents ad6bcdbc 5438f5cb
language: php
phps:
- 5.4
- 5.3
script: phpunit -c phpunit.xml.dist
# Solarium PHP Solr client library
Solarium is a PHP Solr client that not only facilitates Solr communication but Solarium is a PHP Solr client that not only facilitates Solr communication but
also tries to accurately model Solr concepts. also tries to accurately model Solr concepts.
Please see the project website for a more detailed description. Please see the project website for a more detailed description.
Project website: ## Project website
http://www.solarium-project.org/ http://www.solarium-project.org/
GitHub project: ## License:
http://github.com/basdenooijer/solarium
License:
See the COPYING file or view online See the COPYING file or view online
https://github.com/basdenooijer/solarium/blob/master/COPYING https://github.com/basdenooijer/solarium/blob/master/COPYING
Issue tracker: ## Issue tracker
http://github.com/basdenooijer/solarium/issues http://github.com/basdenooijer/solarium/issues
Contributors: ## Contributors
https://github.com/basdenooijer/solarium/contributors https://github.com/basdenooijer/solarium/contributors
API docs: ## API docs
http://api.solarium-project.org/ http://api.solarium-project.org/
## Travis Continuous Integration status
* Develop branch [![Develop build status](https://secure.travis-ci.org/basdenooijer/solarium.png?branch=develop)](http://travis-ci.org/basdenooijer/solarium)
* Master branch [![Develop build status](https://secure.travis-ci.org/basdenooijer/solarium.png?branch=master)](http://travis-ci.org/basdenooijer/solarium)
\ No newline at end of file
...@@ -2,18 +2,14 @@ ...@@ -2,18 +2,14 @@
"name": "solarium/solarium", "name": "solarium/solarium",
"type": "library", "type": "library",
"description": "PHP Solr client", "description": "PHP Solr client",
"keywords": ["solr", "search"], "keywords": ["solr", "search", "php"],
"homepage": "http://www.solarium-project.org", "homepage": "http://www.solarium-project.org",
"version": "2.3.0", "version": "2.4.0",
"license": "NewBSD", "license": "NewBSD",
"authors": [ "authors": [
{ {
"name": "Bas de Nooijer", "name": "See GitHub contributors",
"email": "github@raspberry.nl" "homepage": "https://github.com/basdenooijer/solarium/contributors"
},
{
"name": "Gasol Wu",
"email": "gasol.wu@gmail.com"
} }
], ],
"require": { "require": {
......
...@@ -15,7 +15,7 @@ $ping = $client->createPing(); ...@@ -15,7 +15,7 @@ $ping = $client->createPing();
// execute the ping query // execute the ping query
try{ try{
$result = $client->ping($ping); $result = $client->ping($ping);
echo 'Ping query succesful'; echo 'Ping query successful';
echo '<br/><pre>'; echo '<br/><pre>';
var_dump($result->getData()); var_dump($result->getData());
}catch(Solarium_Exception $e){ }catch(Solarium_Exception $e){
......
...@@ -26,7 +26,7 @@ if ($_POST) { ...@@ -26,7 +26,7 @@ if ($_POST) {
// this executes the query and returns the result // this executes the query and returns the result
$result = $client->update($update); $result = $client->update($update);
echo '<b>Update query executed<b><br/>'; echo '<b>Update query executed</b><br/>';
echo 'Query status: ' . $result->getStatus(). '<br/>'; echo 'Query status: ' . $result->getStatus(). '<br/>';
echo 'Query time: ' . $result->getQueryTime(); echo 'Query time: ' . $result->getQueryTime();
......
...@@ -28,7 +28,7 @@ $update->addCommit(); ...@@ -28,7 +28,7 @@ $update->addCommit();
// this executes the query and returns the result // this executes the query and returns the result
$result = $client->update($update); $result = $client->update($update);
echo '<b>Update query executed<b><br/>'; echo '<b>Update query executed</b><br/>';
echo 'Query status: ' . $result->getStatus(). '<br/>'; echo 'Query status: ' . $result->getStatus(). '<br/>';
echo 'Query time: ' . $result->getQueryTime(); echo 'Query time: ' . $result->getQueryTime();
......
...@@ -16,7 +16,7 @@ $update->addCommit(); ...@@ -16,7 +16,7 @@ $update->addCommit();
// this executes the query and returns the result // this executes the query and returns the result
$result = $client->update($update); $result = $client->update($update);
echo '<b>Update query executed<b><br/>'; echo '<b>Update query executed</b><br/>';
echo 'Query status: ' . $result->getStatus(). '<br/>'; echo 'Query status: ' . $result->getStatus(). '<br/>';
echo 'Query time: ' . $result->getQueryTime(); echo 'Query time: ' . $result->getQueryTime();
......
...@@ -16,7 +16,7 @@ $update->addCommit(); ...@@ -16,7 +16,7 @@ $update->addCommit();
// this executes the query and returns the result // this executes the query and returns the result
$result = $client->update($update); $result = $client->update($update);
echo '<b>Update query executed<b><br/>'; echo '<b>Update query executed</b><br/>';
echo 'Query status: ' . $result->getStatus(). '<br/>'; echo 'Query status: ' . $result->getStatus(). '<br/>';
echo 'Query time: ' . $result->getQueryTime(); echo 'Query time: ' . $result->getQueryTime();
......
...@@ -15,7 +15,7 @@ $update->addOptimize(true, false, 5); ...@@ -15,7 +15,7 @@ $update->addOptimize(true, false, 5);
// this executes the query and returns the result // this executes the query and returns the result
$result = $client->update($update); $result = $client->update($update);
echo '<b>Update query executed<b><br/>'; echo '<b>Update query executed</b><br/>';
echo 'Query status: ' . $result->getStatus(). '<br/>'; echo 'Query status: ' . $result->getStatus(). '<br/>';
echo 'Query time: ' . $result->getQueryTime(); echo 'Query time: ' . $result->getQueryTime();
......
...@@ -15,7 +15,7 @@ $update->addRollback(); ...@@ -15,7 +15,7 @@ $update->addRollback();
// this executes the query and returns the result // this executes the query and returns the result
$result = $client->update($update); $result = $client->update($update);
echo '<b>Update query executed<b><br/>'; echo '<b>Update query executed</b><br/>';
echo 'Query status: ' . $result->getStatus(). '<br/>'; echo 'Query status: ' . $result->getStatus(). '<br/>';
echo 'Query time: ' . $result->getQueryTime(); echo 'Query time: ' . $result->getQueryTime();
......
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get a suggester query instance
$query = $client->createSuggester();
$query->setQuery('ap ip v'); //multiple terms
$query->setDictionary('suggest');
$query->setOnlyMorePopular(true);
$query->setCount(10);
$query->setCollate(true);
// this executes the query and returns the result
$resultset = $client->suggester($query);
echo '<b>Query:</b> '.$query->getQuery().'<hr/>';
// display results for each term
foreach ($resultset as $term => $termResult) {
echo '<h3>' . $term . '</h3>';
echo 'NumFound: '.$termResult->getNumFound().'<br/>';
echo 'StartOffset: '.$termResult->getStartOffset().'<br/>';
echo 'EndOffset: '.$termResult->getEndOffset().'<br/>';
echo 'Suggestions:<br/>';
foreach($termResult as $result){
echo '- '.$result.'<br/>';
}
echo '<hr/>';
}
// display collation
echo 'Collation: '.$resultset->getCollation();
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance and get a select query instance
$client = new Solarium_Client($config);
// first an example manually defining dereferenced params
$query = $client->createSelect();
$helper = $query->getHelper();
$join = $helper->qparser('join', array('from' => 'manu_id', 'to' => 'id'), true);
$queryString = $join . 'id:1';
$query->setQuery($queryString);
$request = $client->createRequest($query);
// output resulting url with dereferenced params
echo urldecode($request->getUri()) . '<hr/>';
// this second example gives the exact same result, using the special join helper
$query = $client->createSelect();
$helper = $query->getHelper();
$join = $helper->join('manu_id', 'id', true);
$queryString = $join . 'id:1';
$query->setQuery($queryString);
$request = $client->createRequest($query);
echo urldecode($request->getUri());
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance and autoload the customize request plugin
$client = new Solarium_Client($config);
$parallel = $client->getPlugin('parallelexecution');
// Add a delay param to better show the effect, as an example Solr install with
// only a dozen documents is too fast for good testing
// This param only works with the correct Solr plugin,
// see http://www.raspberry.nl/2012/01/04/solr-delay-component/
// If you don't have to plugin the example still works, just without the delay.
$customizer = $client->getPlugin('customizerequest');
$customizer->createCustomization(array(
'key' => 'delay',
'type' => 'param',
'name' => 'delay',
'value' => '500',
'persistent' => true
));
// create two queries to execute in an array. Keys are important for fetching the results later!
$queryInstock = $client->createSelect()->setQuery('inStock:true');
$queryLowprice = $client->createSelect()->setQuery('price:[1 TO 300]');
// first execute the queries the normal way and time it
$start = microtime(true);
$client->execute($queryInstock);
$client->execute($queryLowprice);
echo 'Execution time for normal "serial" execution of two queries: ' . round(microtime(true)-$start, 3);
echo '<hr/>';
// now execute the two queries parallel and time it
$start = microtime(true);
$parallel->addQuery('instock', $queryInstock);
$parallel->addQuery('lowprice', $queryLowprice);
$results = $parallel->execute();
echo 'Execution time for parallel execution of two queries: ' . round(microtime(true)-$start, 3);
htmlFooter();
// Note: for this example on a default Solr index (with a tiny index) running on localhost the performance gain is
// minimal to none, sometimes even slightly slower!
// In a realworld scenario with network latency, a bigger dataset, more complex queries or multiple solr instances the
// performance gain is much more.
\ No newline at end of file
<?php
require('init.php');
// this very simple plugin is used to show some events
class simpleDebug extends Solarium_Plugin_Abstract
{
protected $_output = array();
public function display()
{
echo implode('<br/>', $this->_output);
}
public function eventBufferedAddFlushStart($buffer) {
$this->_output[] = 'Flushing buffer (' . count($buffer) . 'docs)';
}
}
htmlHeader();
// create a client instance and autoload the buffered add plugin
$client = new Solarium_Client($config);
$buffer = $client->getPlugin('bufferedadd');
$buffer->setBufferSize(10); // this is quite low, in most cases you can use a much higher value
// also register a plugin for outputting events
$debug = new simpleDebug();
$client->registerPlugin('debugger', $debug);
// let's insert 25 docs
for ($i=1; $i<=25; $i++) {
// create a new document with dummy data and add it to the buffer
$data = array(
'id' => 'test_'.$i,
'name' => 'test for buffered add',
'price' => $i,
);
$buffer->createDocument($data);
// alternatively you could create document instances yourself and use the addDocument(s) method
}
// At this point two flushes will already have been done by the buffer automatically (at the 10th and 20th doc), now
// manually flush the remainder. Alternatively you can use the commit method if you want to include a commit command.
$buffer->flush();
// In total 3 flushes (requests) have been sent to Solr. This should be visible in this output:
$debug->display();
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get a select query instance
$query = $client->createSelect();
$query->setFields(array('id'));
// get a plugin instance and apply settings
$prefetch = $client->getPlugin('prefetchiterator');
$prefetch->setPrefetch(2); //fetch 2 rows per query (for real world use this can be way higher)
$prefetch->setQuery($query);
// display the total number of documents found by solr
echo 'NumFound: ' . count($prefetch);
// show document IDs using the resultset iterator
foreach ($prefetch as $document) {
echo '<hr/>ID: '. $document->id;
}
htmlFooter();
\ No newline at end of file
...@@ -83,6 +83,8 @@ ...@@ -83,6 +83,8 @@
</ul> </ul>
<li><a href="2.5-terms-query.php">2.5 Terms query</a></li> <li><a href="2.5-terms-query.php">2.5 Terms query</a></li>
<li><a href="2.6-suggester-query.php">2.6 Suggester query</a></li>
</ul> </ul>
<li>4. Usage modes</li> <li>4. Usage modes</li>
...@@ -113,13 +115,17 @@ ...@@ -113,13 +115,17 @@
</ul> </ul>
<li><a href="6.2-escaping.php">6.2 Escaping</a></li> <li><a href="6.2-escaping.php">6.2 Escaping</a></li>
<li><a href="6.3-placeholder-syntax.php">6.3 Placeholder syntax</a></li> <li><a href="6.3-placeholder-syntax.php">6.3 Placeholder syntax</a></li>
<li><a href="6.4-dereferenced-params.php">6.4 Dereferenced params</a></li>
</ul> </ul>
<li>7. Plugins</li> <li>7. Plugins</li>
<ul style="list-style:none;"> <ul style="list-style:none;">
<li><a href="7.1-plugin-loadbalancer.php">7.1 Loadbalancer</a></li> <li><a href="7.1-plugin-loadbalancer.php">7.1 Loadbalancer</a></li>
<li><a href="7.2-plugin-postbigrequest.php">7.2 Post Big Requests</a></li> <li><a href="7.2-plugin-postbigrequest.php">7.2 Post Big Requests</a></li>
<li><a href="7.3-plugin-customizerequest.php">7.3 customize Requests</a></li> <li><a href="7.3-plugin-customizerequest.php">7.3 Customize Requests</a></li>
<li><a href="7.4-plugin-parallelexecution.php">7.4 Parallel Execution</a></li>
<li><a href="7.5-plugin-bufferedadd.php">7.5 Buffered Add for documents</a></li>
<li><a href="7.6-plugin-prefetchiterator.php">7.6 Prefetch iterator for select queries</a></li>
</ul> </ul>
</ul> </ul>
......
...@@ -92,6 +92,11 @@ class Solarium_Client extends Solarium_Configurable ...@@ -92,6 +92,11 @@ class Solarium_Client extends Solarium_Configurable
*/ */
const QUERYTYPE_TERMS = 'terms'; const QUERYTYPE_TERMS = 'terms';
/**
* Querytype suggester
*/
const QUERYTYPE_SUGGESTER = 'suggester';
/** /**
* Default options * Default options
* *
...@@ -142,6 +147,11 @@ class Solarium_Client extends Solarium_Configurable ...@@ -142,6 +147,11 @@ class Solarium_Client extends Solarium_Configurable
'requestbuilder' => 'Solarium_Client_RequestBuilder_Terms', 'requestbuilder' => 'Solarium_Client_RequestBuilder_Terms',
'responseparser' => 'Solarium_Client_ResponseParser_Terms' 'responseparser' => 'Solarium_Client_ResponseParser_Terms'
), ),
self::QUERYTYPE_SUGGESTER => array(
'query' => 'Solarium_Query_Suggester',
'requestbuilder' => 'Solarium_Client_RequestBuilder_Suggester',
'responseparser' => 'Solarium_Client_ResponseParser_Suggester'
),
); );
/** /**
...@@ -153,6 +163,9 @@ class Solarium_Client extends Solarium_Configurable ...@@ -153,6 +163,9 @@ class Solarium_Client extends Solarium_Configurable
'loadbalancer' => 'Solarium_Plugin_Loadbalancer', 'loadbalancer' => 'Solarium_Plugin_Loadbalancer',
'postbigrequest' => 'Solarium_Plugin_PostBigRequest', 'postbigrequest' => 'Solarium_Plugin_PostBigRequest',
'customizerequest' => 'Solarium_Plugin_CustomizeRequest', 'customizerequest' => 'Solarium_Plugin_CustomizeRequest',
'parallelexecution' => 'Solarium_Plugin_ParallelExecution',
'bufferedadd' => 'Solarium_Plugin_BufferedAdd',
'prefetchiterator' => 'Solarium_Plugin_PrefetchIterator',
); );
/** /**
...@@ -378,7 +391,7 @@ class Solarium_Client extends Solarium_Configurable ...@@ -378,7 +391,7 @@ class Solarium_Client extends Solarium_Configurable
} }
/** /**
* Get all registered querytypes * Get all registered plugins
* *
* @return array * @return array
*/ */
...@@ -450,7 +463,7 @@ class Solarium_Client extends Solarium_Configurable ...@@ -450,7 +463,7 @@ class Solarium_Client extends Solarium_Configurable
* @param bool $resultOverride * @param bool $resultOverride
* @return void|mixed * @return void|mixed
*/ */
public function triggerEvent($event, $params, $resultOverride = false) public function triggerEvent($event, $params = array(), $resultOverride = false)
{ {
// Add namespacing // Add namespacing
$event = 'event'.$event; $event = 'event'.$event;
...@@ -690,6 +703,20 @@ class Solarium_Client extends Solarium_Configurable ...@@ -690,6 +703,20 @@ class Solarium_Client extends Solarium_Configurable
return $this->execute($query); return $this->execute($query);
} }
/**
* Execute a suggester 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_Suggester $query
* @return Solarium_Result_Suggester
*/
public function suggester($query)
{
return $this->execute($query);
}
/** /**
* Create a query instance * Create a query instance
* *
...@@ -792,4 +819,15 @@ class Solarium_Client extends Solarium_Configurable ...@@ -792,4 +819,15 @@ class Solarium_Client extends Solarium_Configurable
{ {
return $this->createQuery(self::QUERYTYPE_TERMS, $options); return $this->createQuery(self::QUERYTYPE_TERMS, $options);
} }
/**
* Create a suggester query instance
*
* @param mixed $options
* @return Solarium_Query_Suggester
*/
public function createSuggester($options = null)
{
return $this->createQuery(self::QUERYTYPE_SUGGESTER, $options);
}
} }
...@@ -70,9 +70,7 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter ...@@ -70,9 +70,7 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter
*/ */
public function execute($request) public function execute($request)
{ {
list($data, $headers) = $this->_getData($request); return $this->_getData($request);
$this->check($data, $headers);
return new Solarium_Client_Response($data, $headers);
} }
/** /**
...@@ -82,57 +80,84 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter ...@@ -82,57 +80,84 @@ class Solarium_Client_Adapter_Curl extends Solarium_Client_Adapter
* @return array * @return array
*/ */
protected function _getData($request) protected function _getData($request)
{
// @codeCoverageIgnoreStart
$handle = $this->createHandle($request);
$httpResponse = curl_exec($handle);
return $this->getResponse($handle, $httpResponse);
// @codeCoverageIgnoreEnd
}
/**
* Get the response for a curl handle
*
* @param resource $handle
* @param string $httpResponse
* @return Solarium_Client_Response
*/
public function getResponse($handle, $httpResponse)
{
// @codeCoverageIgnoreStart
if ($httpResponse !== false) {
$data = $httpResponse;
$info = curl_getinfo($handle);
$headers = array();
$headers[] = 'HTTP/1.1 ' . $info['http_code']. ' OK';
} else {
$headers = array();
$data = '';
}
curl_close($handle);
$this->check($data, $headers);
return new Solarium_Client_Response($data, $headers);
// @codeCoverageIgnoreEnd
}
/**
* Create curl handle for a request
*
* @param Solarium_Client_Request $request
* @return resource
*/
public function createHandle($request)
{ {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$uri = $this->getBaseUri() . $request->getUri(); $uri = $this->getBaseUri() . $request->getUri();
$method = $request->getMethod(); $method = $request->getMethod();
$options = $this->_createOptions($request); $options = $this->_createOptions($request);
$ch = curl_init(); $handler = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($handler, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($handler, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $options['timeout']); curl_setopt($handler, CURLOPT_TIMEOUT, $options['timeout']);
if (!isset($options['headers']['Content-Type'])) {
$options['headers']['Content-Type'] = 'text/xml; charset=utf-8';
}
if (!isset($options['headers']['Content-Type'])) { if (!isset($options['headers']['Content-Type'])) {
$options['headers']['Content-Type'] = 'text/xml; charset=utf-8'; $options['headers']['Content-Type'] = 'text/xml; charset=utf-8';
} }
if (count($options['headers'])) { if (count($options['headers'])) {
$arr = array(); $headers = array();
foreach ($options['headers'] as $k => $v) { foreach ($options['headers'] as $key => $value) {
$arr[] = $k . ": " . $v; $headers[] = $key . ": " . $value;
} }
curl_setopt($ch, CURLOPT_HTTPHEADER, $arr); curl_setopt($handler, CURLOPT_HTTPHEADER, $headers);
} }
if ($method == Solarium_Client_Request::METHOD_POST) { if ($method == Solarium_Client_Request::METHOD_POST) {
curl_setopt($ch, CURLOPT_POST, true); curl_setopt($handler, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getRawData()); curl_setopt($handler, CURLOPT_POSTFIELDS, $request->getRawData());
$httpResponse = curl_exec($ch);
} else if ($method == Solarium_Client_Request::METHOD_GET) { } else if ($method == Solarium_Client_Request::METHOD_GET) {
curl_setopt($ch, CURLOPT_HTTPGET, true); curl_setopt($handler, CURLOPT_HTTPGET, true);
$httpResponse = curl_exec($ch);
} else if ($method == Solarium_Client_Request::METHOD_HEAD) { } else if ($method == Solarium_Client_Request::METHOD_HEAD) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); curl_setopt($handler, CURLOPT_CUSTOMREQUEST, 'HEAD');
$httpResponse = curl_exec($ch);
} else { } else {
throw new Solarium_Exception("unsupported method: $method"); throw new Solarium_Exception("unsupported method: $method");
} }
$headers = array(); $data = ''; return $handler;
if ($httpResponse !== false) {
$data = $httpResponse;
$info = curl_getinfo($ch);
$headers = array();
$headers[] = 'HTTP/1.1 ' . $info['http_code']. ' OK';
}
return array($data, $headers);
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
......
...@@ -385,4 +385,25 @@ class Solarium_Client_Request extends Solarium_Configurable ...@@ -385,4 +385,25 @@ class Solarium_Client_Request extends Solarium_Configurable
return $queryString; return $queryString;
} }
/**
* Magic method enables a object to be transformed to a string
*
* Get a summary showing significant variables in the object
* note: uri resource is decoded for readability
*
* @return string
*/
public function __toString()
{
$output = __CLASS__ . '::toString' . "\n"
. 'method: ' . $this->getMethod() . "\n"
. 'header: ' . print_r($this->getHeaders(), 1) //don't add newline when using print_r
. 'resource: ' . $this->getUri() . "\n"
. 'resource urldecoded: ' . urldecode($this->getUri()) . "\n"
. 'raw data: ' . $this->getRawData() . "\n";
return $output;
}
} }
\ No newline at end of file
...@@ -45,6 +45,22 @@ ...@@ -45,6 +45,22 @@
abstract class Solarium_Client_RequestBuilder abstract class Solarium_Client_RequestBuilder
{ {
/**
* Build request for a select query
*
* @param Solarium_Query $query
* @return Solarium_Client_Request
*/
public function build($query)
{
$request = new Solarium_Client_Request;
$request->setHandler($query->getHandler());
$request->addParams($query->getParams());
$request->addParam('wt', 'json');
return $request;
}
/** /**
* Render a param with localParams * Render a param with localParams
* *
......
...@@ -53,10 +53,7 @@ class Solarium_Client_RequestBuilder_Analysis extends Solarium_Client_RequestBui ...@@ -53,10 +53,7 @@ class Solarium_Client_RequestBuilder_Analysis extends Solarium_Client_RequestBui
*/ */
public function build($query) public function build($query)
{ {
$request = new Solarium_Client_Request; $request = parent::build($query);
$request->setHandler($query->getHandler());
$request->addParam('wt', 'json');
$request->addParam('analysis.query', $query->getQuery()); $request->addParam('analysis.query', $query->getQuery());
$request->addParam('analysis.showmatch', $query->getShowMatch()); $request->addParam('analysis.showmatch', $query->getShowMatch());
......
...@@ -53,10 +53,8 @@ class Solarium_Client_RequestBuilder_Ping extends Solarium_Client_RequestBuilder ...@@ -53,10 +53,8 @@ class Solarium_Client_RequestBuilder_Ping extends Solarium_Client_RequestBuilder
*/ */
public function build($query) public function build($query)
{ {
$request = new Solarium_Client_Request; $request = parent::build($query);
$request->setHandler($query->getHandler());
$request->setMethod(Solarium_Client_Request::METHOD_GET); $request->setMethod(Solarium_Client_Request::METHOD_GET);
$request->addParam('wt', 'json');
return $request; return $request;
} }
......
...@@ -53,15 +53,13 @@ class Solarium_Client_RequestBuilder_Select extends Solarium_Client_RequestBuild ...@@ -53,15 +53,13 @@ class Solarium_Client_RequestBuilder_Select extends Solarium_Client_RequestBuild
*/ */
public function build($query) public function build($query)
{ {
$request = new Solarium_Client_Request; $request = parent::build($query);
$request->setHandler($query->getHandler());
// add basic params to request // add basic params to request
$request->addParam('q', $query->getQuery()); $request->addParam('q', $query->getQuery());
$request->addParam('start', $query->getStart()); $request->addParam('start', $query->getStart());
$request->addParam('rows', $query->getRows()); $request->addParam('rows', $query->getRows());
$request->addParam('fl', implode(',', $query->getFields())); $request->addParam('fl', implode(',', $query->getFields()));
$request->addParam('wt', 'json');
$request->addParam('q.op', $query->getQueryDefaultOperator()); $request->addParam('q.op', $query->getQueryDefaultOperator());
$request->addParam('df', $query->getQueryDefaultField()); $request->addParam('df', $query->getQueryDefaultField());
...@@ -92,7 +90,7 @@ class Solarium_Client_RequestBuilder_Select extends Solarium_Client_RequestBuild ...@@ -92,7 +90,7 @@ class Solarium_Client_RequestBuilder_Select extends Solarium_Client_RequestBuild
$componentBuilderClass = $types[$component->getType()]['requestbuilder']; $componentBuilderClass = $types[$component->getType()]['requestbuilder'];
if (!empty($componentBuilderClass)) { if (!empty($componentBuilderClass)) {
$componentBuilder = new $componentBuilderClass; $componentBuilder = new $componentBuilderClass;
$request = $componentBuilder->build($component, $request); $request = $componentBuilder->buildComponent($component, $request);
} }
} }
......
...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_Debug ...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_Debug
* @param Solarium_Client_Request $request * @param Solarium_Client_Request $request
* @return Solarium_Client_Request * @return Solarium_Client_Request
*/ */
public function build($component, $request) public function buildComponent($component, $request)
{ {
$request->addParam('debugQuery', 'true'); $request->addParam('debugQuery', 'true');
$request->addParam('debug.explain.structured', 'true'); $request->addParam('debug.explain.structured', 'true');
......
...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DisMax ...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DisMax
* @param Solarium_Client_Request $request * @param Solarium_Client_Request $request
* @return Solarium_Client_Request * @return Solarium_Client_Request
*/ */
public function build($component, $request) public function buildComponent($component, $request)
{ {
// enable dismax // enable dismax
$request->addParam('defType', $component->getQueryParser()); $request->addParam('defType', $component->getQueryParser());
......
...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DistributedSearch ...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DistributedSearch
* @param Solarium_Client_Request $request * @param Solarium_Client_Request $request
* @return Solarium_Client_Request * @return Solarium_Client_Request
*/ */
public function build($component, $request) public function buildComponent($component, $request)
{ {
// add shard fields to request // add shard fields to request
$shards = array_values($component->getShards()); $shards = array_values($component->getShards());
......
...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSet extends Solarium_ ...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSet extends Solarium_
* @param Solarium_Client_Request $request * @param Solarium_Client_Request $request
* @return Solarium_Client_Request * @return Solarium_Client_Request
*/ */
public function build($component, $request) public function buildComponent($component, $request)
{ {
$facets = $component->getFacets(); $facets = $component->getFacets();
if (count($facets) !== 0) { if (count($facets) !== 0) {
...@@ -175,14 +175,18 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSet extends Solarium_ ...@@ -175,14 +175,18 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSet extends Solarium_
$request->addParam("f.$field.facet.range.gap", $facet->getGap()); $request->addParam("f.$field.facet.range.gap", $facet->getGap());
$request->addParam("f.$field.facet.range.hardend", $facet->getHardend()); $request->addParam("f.$field.facet.range.hardend", $facet->getHardend());
if (null !== $facet->getOther()) {
$other = explode(',', $facet->getOther()); $other = explode(',', $facet->getOther());
foreach ($other AS $otherValue) { foreach ($other AS $otherValue) {
$request->addParam("f.$field.facet.range.other", trim($otherValue)); $request->addParam("f.$field.facet.range.other", trim($otherValue));
} }
}
if (null !== $facet->getOther()) {
$include = explode(',', $facet->getInclude()); $include = explode(',', $facet->getInclude());
foreach ($include AS $includeValue) { foreach ($include AS $includeValue) {
$request->addParam("f.$field.facet.range.include", trim($includeValue)); $request->addParam("f.$field.facet.range.include", trim($includeValue));
} }
} }
}
} }
\ No newline at end of file
...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_Grouping ...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_Grouping
* @param Solarium_Client_Request $request * @param Solarium_Client_Request $request
* @return Solarium_Client_Request * @return Solarium_Client_Request
*/ */
public function build($component, $request) public function buildComponent($component, $request)
{ {
// enable grouping // enable grouping
$request->addParam('group', 'true'); $request->addParam('group', 'true');
......
...@@ -52,7 +52,9 @@ class Solarium_Client_RequestBuilder_Select_Component_Highlighting ...@@ -52,7 +52,9 @@ class Solarium_Client_RequestBuilder_Select_Component_Highlighting
* @param Solarium_Client_Request $request * @param Solarium_Client_Request $request
* @return Solarium_Client_Request * @return Solarium_Client_Request
*/ */
public function build(Solarium_Query_Select_Component_Highlighting $component, Solarium_Client_Request $request) public function buildComponent(
Solarium_Query_Select_Component_Highlighting $component,
Solarium_Client_Request $request)
{ {
// enable highlighting // enable highlighting
$request->addParam('hl', 'true'); $request->addParam('hl', 'true');
...@@ -78,6 +80,8 @@ class Solarium_Client_RequestBuilder_Select_Component_Highlighting ...@@ -78,6 +80,8 @@ class Solarium_Client_RequestBuilder_Select_Component_Highlighting
$request->addParam('hl.regex.slop', $component->getRegexSlop()); $request->addParam('hl.regex.slop', $component->getRegexSlop());
$request->addParam('hl.regex.pattern', $component->getRegexPattern()); $request->addParam('hl.regex.pattern', $component->getRegexPattern());
$request->addParam('hl.regex.maxAnalyzedChars', $component->getRegexMaxAnalyzedChars()); $request->addParam('hl.regex.maxAnalyzedChars', $component->getRegexMaxAnalyzedChars());
$request->addParam('hl.q', $component->getQuery());
$request->addParam('hl.phraseLimit', $component->getPhraseLimit());
// set per-field highlighting params // set per-field highlighting params
foreach ($component->getFields() as $field) { foreach ($component->getFields() as $field) {
......
...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_MoreLikeThis ...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_MoreLikeThis
* @param Solarium_Client_Request $request * @param Solarium_Client_Request $request
* @return Solarium_Client_Request * @return Solarium_Client_Request
*/ */
public function build($component, $request) public function buildComponent($component, $request)
{ {
// enable morelikethis // enable morelikethis
$request->addParam('mlt', 'true'); $request->addParam('mlt', 'true');
......
...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_Spellcheck ...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_Spellcheck
* @param Solarium_Client_Request $request * @param Solarium_Client_Request $request
* @return Solarium_Client_Request * @return Solarium_Client_Request
*/ */
public function build($component, $request) public function buildComponent($component, $request)
{ {
// enable spellcheck // enable spellcheck
$request->addParam('spellcheck', 'true'); $request->addParam('spellcheck', 'true');
......
...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_Stats ...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_Stats
* @param Solarium_Client_Request $request * @param Solarium_Client_Request $request
* @return Solarium_Client_Request * @return Solarium_Client_Request
*/ */
public function build($component, $request) public function buildComponent($component, $request)
{ {
// enable stats // enable stats
$request->addParam('stats', 'true'); $request->addParam('stats', 'true');
......
<?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 Suggester query request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Suggester extends Solarium_Client_RequestBuilder
{
/**
* Build request for a Suggester query
*
* @param Solarium_Query_Suggester $query
* @return Solarium_Client_Request
*/
public function build($query)
{
$request = parent::build($query);
$request->addParam('spellcheck', 'true');
$request->addParam('q', $query->getQuery());
$request->addParam('spellcheck.dictionary', $query->getDictionary());
$request->addParam('spellcheck.count', $query->getCount());
$request->addParam('spellcheck.onlyMorePopular', $query->getOnlyMorePopular());
$request->addParam('spellcheck.collate', $query->getCollate());
return $request;
}
}
...@@ -56,10 +56,8 @@ class Solarium_Client_RequestBuilder_Terms extends Solarium_Client_RequestBuilde ...@@ -56,10 +56,8 @@ class Solarium_Client_RequestBuilder_Terms extends Solarium_Client_RequestBuilde
*/ */
public function build($query) public function build($query)
{ {
$request = new Solarium_Client_Request; $request = parent::build($query);
$request->setHandler($query->getHandler());
$request->addParam('terms', true); $request->addParam('terms', true);
$request->addParam('wt', 'json');
$request->addParam('terms.lower', $query->getLowerbound()); $request->addParam('terms.lower', $query->getLowerbound());
$request->addParam('terms.lower.incl', $query->getLowerboundInclude()); $request->addParam('terms.lower.incl', $query->getLowerboundInclude());
$request->addParam('terms.mincount', $query->getMinCount()); $request->addParam('terms.mincount', $query->getMinCount());
......
...@@ -53,10 +53,8 @@ class Solarium_Client_RequestBuilder_Update extends Solarium_Client_RequestBuild ...@@ -53,10 +53,8 @@ class Solarium_Client_RequestBuilder_Update extends Solarium_Client_RequestBuild
*/ */
public function build($query) public function build($query)
{ {
$request = new Solarium_Client_Request; $request = parent::build($query);
$request->setHandler($query->getHandler());
$request->setMethod(Solarium_Client_Request::METHOD_POST); $request->setMethod(Solarium_Client_Request::METHOD_POST);
$request->addParam('wt', 'json');
$request->setRawData($this->getRawData($query)); $request->setRawData($this->getRawData($query));
return $request; return $request;
......
...@@ -110,12 +110,31 @@ class Solarium_Client_ResponseParser_Analysis_Field extends Solarium_Client_Resp ...@@ -110,12 +110,31 @@ class Solarium_Client_ResponseParser_Analysis_Field extends Solarium_Client_Resp
$class = $typeData[$counter]; $class = $typeData[$counter];
$analysis = $typeData[$counter+1]; $analysis = $typeData[$counter+1];
if (is_string($analysis)) {
$item = new Solarium_Result_Analysis_Item(
array(
'text' => $analysis,
'start' => null,
'end' => null,
'position' => null,
'positionHistory' => null,
'type' => null,
)
);
$classes[] = new Solarium_Result_Analysis_List($class, array($item));
} else {
$items = array(); $items = array();
foreach ($analysis AS $itemData) { foreach ($analysis as $itemData) {
$items[] = new Solarium_Result_Analysis_Item($itemData); $items[] = new Solarium_Result_Analysis_Item($itemData);
} }
$classes[] = new Solarium_Result_Analysis_List($class, $items); $classes[] = new Solarium_Result_Analysis_List($class, $items);
}
$counter += 2; $counter += 2;
} }
......
<?php
/**
* Copyright 2011 Gasol Wu. PIXNET Digital Media Corporation.
* 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 Gasol Wu <gasol.wu@gmail.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Parse Suggester response data
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_ResponseParser_Suggester extends Solarium_Client_ResponseParser
{
/**
* Get result data for the response
*
* @param Solarium_Result_Terms $result
* @return array
*/
public function parse($result)
{
$data = $result->getData();
$query = $result->getQuery();
$status = null;
$queryTime = null;
if (isset($data['responseHeader'])) {
$status = $data['responseHeader']['status'];
$queryTime = $data['responseHeader']['QTime'];
}
$suggestions = array();
$collation = null;
if (isset($data['spellcheck']['suggestions']) && is_array($data['spellcheck']['suggestions'])) {
$suggestResults = $data['spellcheck']['suggestions'];
$termClass = $query->getOption('termclass');
for ($i = 0; $i < count($suggestResults); $i += 2) {
$term = $suggestResults[$i];
$termData = $suggestResults[$i+1];
if ($term == 'collation'&& $i == count($suggestResults)-2) {
$collation = $termData;
} else {
$suggestions[$term] = new $termClass(
$termData['numFound'],
$termData['startOffset'],
$termData['endOffset'],
$termData['suggestion']
);
}
}
}
return array(
'status' => $status,
'queryTime' => $queryTime,
'results' => $suggestions,
'collation' => $collation,
);
}
}
...@@ -70,7 +70,7 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable ...@@ -70,7 +70,7 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
/** /**
* Plugin init function * Plugin init function
* *
* This is an extension point for plugin implemenations. * This is an extension point for plugin implementations.
* Will be called as soon as $this->_client and options have been set. * Will be called as soon as $this->_client and options have been set.
* *
* @return void * @return void
......
<?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
*/
/**
* Buffered add plugin
*
* If you need to add (or update) a big number of documents to Solr it's much more efficient to do so in batches.
* This plugin makes this as easy as possible.
*
* @package Solarium
* @subpackage Plugin
*/
class Solarium_Plugin_BufferedAdd extends Solarium_Plugin_Abstract
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
'buffersize' => 100,
);
/**
* Update query instance
*
* @var Solarium_Query_Update
*/
protected $_updateQuery;
/**
* Buffered documents
*
* @var array
*/
protected $_buffer = array();
/**
* Plugin init function
*
* This is an extension point for plugin implementations.
* Will be called as soon as $this->_client and options have been set.
*
* @return void
*/
protected function _initPlugin()
{
$this->_updateQuery = $this->_client->createUpdate();
}
/**
* Set buffer size option
*
* @param int $size
* @return Solarium_Configurable
*/
public function setBufferSize($size)
{
return $this->_setOption('buffersize', $size);
}
/**
* Get buffer size option value
*
* @return int
*/
public function getBufferSize()
{
return $this->getOption('buffersize');
}
/**
* Create a document object instance and add it to the buffer
*
* @param array $fields
* @param array $boosts
* @return self Provides fluent interface
*/
public function createDocument($fields, $boosts = array())
{
$doc = $this->_updateQuery->createDocument($fields, $boosts);
$this->addDocument($doc);
return $this;
}
/**
* Add a document
*
* @param Solarium_Document_ReadOnly $document
* @return self Provides fluent interface
*/
public function addDocument($document)
{
$this->_buffer[] = $document;
if (count($this->_buffer) == $this->_options['buffersize']) {
$this->flush();
}
return $this;
}
/**
* Add multiple documents
*
* @param array
* @return self Provides fluent interface
*/
public function addDocuments($documents)
{
foreach ($documents as $document) {
$this->addDocument($document);
}
return $this;
}
/**
* Get all documents currently in the buffer
*
* Any previously flushed documents will not be included!
*
* @return array
*/
public function getDocuments()
{
return $this->_buffer;
}
/**
* Clear any buffered documents
*
* @return self Provides fluent interface
*/
public function clear()
{
$this->_updateQuery = $this->_client->createUpdate();
$this->_buffer = array();
return $this;
}
/**
* Flush any buffered documents to Solr
*
* @param boolean $overwrite
* @param int $commitWithin
* @return boolean|Solarium_Result_Update
*/
public function flush($overwrite = null, $commitWithin = null)
{
if (count($this->_buffer) == 0) {
// nothing to do
return false;
}
$this->_client->triggerEvent('BufferedAddFlushStart', array($this->_buffer));
$this->_updateQuery->addDocuments($this->_buffer, $overwrite, $commitWithin);
$result = $this->_client->update($this->_updateQuery);
$this->clear();
$this->_client->triggerEvent('BufferedAddFlushEnd', array($result));
return $result;
}
/**
* Commit changes
*
* Any remaining documents in the buffer will also be flushed
*
* @param boolean $overwrite
* @param boolean $waitFlush
* @param boolean $waitSearcher
* @param boolean $expungeDeletes
* @return Solarium_Result_Update
*/
public function commit($overwrite = null, $waitFlush = null, $waitSearcher = null, $expungeDeletes = null)
{
$this->_client->triggerEvent('BufferedAddCommitStart', array($this->_buffer));
$this->_updateQuery->addDocuments($this->_buffer, $overwrite);
$this->_updateQuery->addCommit($waitFlush, $waitSearcher, $expungeDeletes);
$result = $this->_client->update($this->_updateQuery);
$this->clear();
$this->_client->triggerEvent('BufferedAddCommitEnd', array($result));
return $result;
}
}
\ No newline at end of file
...@@ -45,9 +45,13 @@ class Solarium_Plugin_CustomizeRequest_Customization extends Solarium_Configurab ...@@ -45,9 +45,13 @@ class Solarium_Plugin_CustomizeRequest_Customization extends Solarium_Configurab
{ {
/** /**
* Type definitions * Type definition for params
*/ */
const TYPE_PARAM = 'param'; const TYPE_PARAM = 'param';
/**
* Type definition for headers
*/
const TYPE_HEADER = 'header'; const TYPE_HEADER = 'header';
/** /**
......
<?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
*/
/**
* ParallelExecution plugin
*
* You can use this plugin to run multiple queries parallel. This functionality depends on the curl adapter so you
* do need to have curl available in your PHP environment.
*
* While query execution is parallel, the results only become available as soon as all requests have finished. So the
* time of the slowest query will be the effective execution time for all queries.
*
* @package Solarium
* @subpackage Plugin
*/
class Solarium_Plugin_ParallelExecution extends Solarium_Plugin_Abstract
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
'curlmultiselecttimeout' => 0.1,
);
/**
* Queries (and optionally clients) to execute
*
* @var array
*/
protected $_queries = array();
/**
* Add a query to execute
*
* @param string $key
* @param Solarium_Query $query
* @param null|Solarium_Client $client
* @return Solarium_Plugin_ParallelExecution
*/
public function addQuery($key, $query, $client = null)
{
if($client == null) $client = $this->_client;
$this->_queries[$key] = array(
'query' => $query,
'client' => $client,
);
return $this;
}
/**
* Get queries (and coupled client instances)
*
* @return array
*/
public function getQueries()
{
return $this->_queries;
}
/**
* Clear all queries
*
* @return self Provides fluent interface
*/
public function clearQueries()
{
$this->_queries = array();
return $this;
}
// @codeCoverageIgnoreStart
/**
* Execute queries parallel
*
* Use an array of Solarium_Query objects as input. The keys of the array are important, as they are also used in
* the result array. You can mix all querytypes in the input array.
*
* @param array $queries (deprecated, use addQuery instead)
* @return array
*/
public function execute($queries = null)
{
// this is for backwards compatibility
if (is_array($queries)) {
foreach ($queries as $key => $query) {
$this->addQuery($key, $query);
}
}
// create handles and add all handles to the multihandle
$multiHandle = curl_multi_init();
$handles = array();
foreach ($this->_queries as $key => $data) {
$request = $this->_client->createRequest($data['query']);
$adapter = $data['client']->setAdapter('Solarium_Client_Adapter_Curl')->getAdapter();
$handle = $adapter->createHandle($request);
curl_multi_add_handle($multiHandle, $handle);
$handles[$key] = $handle;
}
// executing multihandle (all requests)
$this->_client->triggerEvent('ParallelExecutionStart');
do {
$mrc = curl_multi_exec($multiHandle, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
$timeout = $this->getOption('curlmultiselecttimeout');
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($multiHandle, $timeout) != -1) {
do {
$mrc = curl_multi_exec($multiHandle, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
$this->_client->triggerEvent('ParallelExecutionEnd');
// get the results
$results = array();
foreach ($handles as $key => $handle) {
try {
curl_multi_remove_handle($multiHandle, $handle);
$response = $adapter->getResponse($handle, curl_multi_getcontent($handle));
$results[$key] = $this->_client->createResult($this->_queries[$key]['query'], $response);
} catch(Solarium_Client_HttpException $e) {
$results[$key] = $e;
}
}
curl_multi_close($multiHandle);
return $results;
}
// @codeCoverageIgnoreEnd
}
<?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
*/
/**
* Prefetch plugin
*
* This plugin can be used to create an 'endless' iterator over a complete resultset. The iterator will take care of
* fetching the data in sets (sequential prefetching).
*
* @package Solarium
* @subpackage Plugin
*/
class Solarium_Plugin_PrefetchIterator extends Solarium_Plugin_Abstract implements Iterator, Countable
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
'prefetch' => 100,
);
/**
* Query instance to execute
*
* @var Solarium_Query_Select
*/
protected $_query;
/**
* Start position (offset)
*
* @var int
*/
protected $_start = 0;
/**
* Last resultset from the query instance
*
* @var Solarium_Result_Select
*/
protected $_result;
/**
* Iterator position
*
* @var int
*/
protected $_position;
/**
* Documents from the last resultset
*
* @var array
*/
protected $_documents;
/**
* Set prefetch option
*
* @param integer $value
* @return self Provides fluent interface
*/
public function setPrefetch($value)
{
return $this->_setOption('prefetch', $value);
}
/**
* Get prefetch option
*
* @return integer
*/
public function getPrefetch()
{
return $this->getOption('prefetch');
}
/**
* Set query to use for prefetching
*
* @param Solarium_Query_Select $query
* @return self Provides fluent interface
*/
public function setQuery($query)
{
$this->_query = $query;
return $this;
}
/**
* Get the query object used
*
* @return Solarium_Query_Select
*/
public function getQuery()
{
return $this->_query;
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
// if no results are available yet, get them now
if (null == $this->_result) $this->_fetchNext();
return $this->_result->getNumFound();
}
/**
* Iterator implementation
*/
function rewind()
{
$this->_position = 0;
// this condition prevent useless re-fetching of data if a count is done before the iterator is used
if ($this->_start !== $this->_options['prefetch']) {
$this->_start = 0;
}
}
/**
* Iterator implementation
*/
function current()
{
$adjustedIndex = $this->_position % $this->_options['prefetch'];
return $this->_documents[$adjustedIndex];
}
/**
* Iterator implementation
*
* @return int
*/
function key()
{
return $this->_position;
}
/**
* Iterator implementation
*/
function next()
{
++$this->_position;
}
/**
* Iterator implementation
*
* @return boolean
*/
function valid()
{
$adjustedIndex = $this->_position % $this->_options['prefetch'];
// this condition prevent useless re-fetching of data if a count is done before the iterator is used
if ($adjustedIndex == 0 && ($this->_position !== 0 || null == $this->_result)) {
$this->_fetchNext();
}
return isset($this->_documents[$adjustedIndex]);
}
/**
* Fetch the next set of results
*
* @return void
*/
protected function _fetchNext()
{
$this->_query->setStart($this->_start)->setRows($this->getPrefetch());
$this->_result = $this->_client->execute($this->_query);
$this->_documents = $this->_result->getDocuments();
$this->_start += $this->getPrefetch();
}
}
\ No newline at end of file
...@@ -52,6 +52,13 @@ abstract class Solarium_Query extends Solarium_Configurable ...@@ -52,6 +52,13 @@ abstract class Solarium_Query extends Solarium_Configurable
*/ */
protected $_helper; protected $_helper;
/**
* Extra query params (e.g. dereferenced params)
*
* @var array
*/
protected $_params = array();
/** /**
* Get type for this query * Get type for this query
* *
...@@ -118,10 +125,36 @@ abstract class Solarium_Query extends Solarium_Configurable ...@@ -118,10 +125,36 @@ abstract class Solarium_Query extends Solarium_Configurable
public function getHelper() public function getHelper()
{ {
if (null === $this->_helper) { if (null === $this->_helper) {
$this->_helper = new Solarium_Query_Helper; $this->_helper = new Solarium_Query_Helper($this);
} }
return $this->_helper; return $this->_helper;
} }
/**
* Add extra params to the request
*
* Only intended for internal use, for instance with dereferenced params.
* Therefore the params are limited in functionality. Only add and get
*
* @param string $name
* @param string $value
* @return self Provides fluent interface
*/
public function addParam($name, $value)
{
$this->_params[$name] = $value;
return $this;
}
/**
* Get extra params
*
* @return array
*/
public function getParams()
{
return $this->_params;
}
} }
\ No newline at end of file
...@@ -61,6 +61,31 @@ class Solarium_Query_Helper ...@@ -61,6 +61,31 @@ class Solarium_Query_Helper
*/ */
protected $_assembleParts; protected $_assembleParts;
/**
* Counter to keep dereferenced params unique (within a single query instance)
*
* @var int
*/
protected $_derefencedParamsLastKey = 0;
/**
* Solarium_Query instance, optional.
* Used for dereferenced params.
*
* @var Solarium_Query
*/
protected $_query;
/**
* Constructor
*
* @param Solarium_Query $query
*/
public function __construct($query = null)
{
$this->_query = $query;
}
/** /**
* Escape a term * Escape a term
* *
...@@ -102,6 +127,68 @@ class Solarium_Query_Helper ...@@ -102,6 +127,68 @@ class Solarium_Query_Helper
return '"' . preg_replace('/("|\\\)/', '\\\$1', $input) . '"'; return '"' . preg_replace('/("|\\\)/', '\\\$1', $input) . '"';
} }
/**
* Format a date to the expected formatting used in SOLR
*
* This format was derived to be standards compliant (ISO 8601)
* A date field shall be of the form 1995-12-31T23:59:59Z The trailing "Z" designates UTC time and is mandatory
*
* @see http://lucene.apache.org/solr/api/org/apache/solr/schema/DateField.html
*
* @param int|string|DateTime $input accepted formats: timestamp, date string or DateTime
* @return string|false false is returned in case of invalid input
*/
public function formatDate($input)
{
switch(true){
// input of datetime object
case $input instanceof DateTime:
// no work needed
break;
// input of timestamp or date/time string
case is_string($input) || is_numeric($input):
// if date/time string: convert to timestamp first
if (is_string($input)) $input = strtotime($input);
// now try converting the timestamp to a datetime instance, on failure return false
try {
$input = new DateTime('@' . $input);
} catch (Exception $e) {
$input = false;
}
break;
// any other input formats can be added in additional cases here...
// case $input instanceof Zend_Date:
// unsupported input format
default:
$input = false;
break;
}
// handle the filtered input
if ($input) {
// when we get here the input is always a datetime object
$input->setTimezone(new DateTimeZone('UTC'));
$iso8601 = $input->format(DateTime::ISO8601);
$iso8601 = strstr($iso8601, '+', true); //strip timezone
$iso8601 .= 'Z';
return $iso8601;
} else {
// unsupported input
return false;
}
}
/** /**
* Render a range query * Render a range query
* *
...@@ -110,7 +197,6 @@ class Solarium_Query_Helper ...@@ -110,7 +197,6 @@ class Solarium_Query_Helper
* Example: rangeQuery('store', '45,-94', '46,-93') * Example: rangeQuery('store', '45,-94', '46,-93')
* Returns: store:[45,-94 TO 46,-93] * Returns: store:[45,-94 TO 46,-93]
* *
* @static
* @param string $field * @param string $field
* @param string $from * @param string $from
* @param string $to * @param string $to
...@@ -131,7 +217,6 @@ class Solarium_Query_Helper ...@@ -131,7 +217,6 @@ class Solarium_Query_Helper
* *
* Find all entries within the distance of a certain point. * Find all entries within the distance of a certain point.
* *
* @static
* @param $pointX * @param $pointX
* @param $pointY * @param $pointY
* @param $field * @param $field
...@@ -158,7 +243,6 @@ class Solarium_Query_Helper ...@@ -158,7 +243,6 @@ class Solarium_Query_Helper
* guaranteed to encompass all of the points of interest, but it may also * guaranteed to encompass all of the points of interest, but it may also
* include other points that are slightly outside of the required distance. * include other points that are slightly outside of the required distance.
* *
* @static
* @param string $pointX * @param string $pointX
* @param string $pointY * @param string $pointY
* @param string $field * @param string $field
...@@ -186,7 +270,6 @@ class Solarium_Query_Helper ...@@ -186,7 +270,6 @@ class Solarium_Query_Helper
* or combining the distance with the relevancy score, * or combining the distance with the relevancy score,
* such as boosting by the inverse of the distance. * such as boosting by the inverse of the distance.
* *
* @static
* @param $pointX * @param $pointX
* @param $pointY * @param $pointY
* @param $field * @param $field
...@@ -203,15 +286,32 @@ class Solarium_Query_Helper ...@@ -203,15 +286,32 @@ class Solarium_Query_Helper
/** /**
* Render a qparser plugin call * Render a qparser plugin call
* *
* @static
* @param string $name * @param string $name
* @param array $params * @param array $params
* @param boolean $dereferenced
* @return string * @return string
*/ */
public function qparser($name, $params = array()) public function qparser($name, $params = array(), $dereferenced = false)
{ {
if ($dereferenced) {
if (!$this->_query) {
throw new Solarium_Exception(
'Dereferenced params can only be used in a Solarium_Query_Helper instance retrieved from the query '
. 'by using the getHelper() method, this instance was manually created'
);
}
foreach ($params as $paramKey => $paramValue) {
$this->_derefencedParamsLastKey++;
$derefKey = 'deref_' . $this->_derefencedParamsLastKey;
$this->_query->addParam($derefKey, $paramValue);
$params[$paramKey] = '$'.$derefKey;
}
}
$output = '{!'.$name; $output = '{!'.$name;
foreach ($params AS $key=>$value) { foreach ($params as $key=>$value) {
$output .= ' ' . $key . '=' . $value; $output .= ' ' . $key . '=' . $value;
} }
$output .= '}'; $output .= '}';
...@@ -222,7 +322,6 @@ class Solarium_Query_Helper ...@@ -222,7 +322,6 @@ class Solarium_Query_Helper
/** /**
* Render a functionCall * Render a functionCall
* *
* @static
* @param string $name * @param string $name
* @param array $params * @param array $params
* @return string * @return string
...@@ -297,4 +396,20 @@ class Solarium_Query_Helper ...@@ -297,4 +396,20 @@ class Solarium_Query_Helper
return $value; return $value;
} }
/**
* Render join localparams syntax
*
* @see http://wiki.apache.org/solr/Join
* @since 2.4.0
*
* @param string $from
* @param string $to
* @param boolean $dereferenced
* @return string
*/
public function join($from, $to, $dereferenced = false)
{
return $this->qparser('join', array('from' => $from, 'to' => $to), $dereferenced);
}
} }
...@@ -628,4 +628,48 @@ class Solarium_Query_Select_Component_Highlighting extends Solarium_Query_Select ...@@ -628,4 +628,48 @@ class Solarium_Query_Select_Component_Highlighting extends Solarium_Query_Select
return $this->getOption('regexmaxanalyzedchars'); return $this->getOption('regexmaxanalyzedchars');
} }
/**
* Set highlight query option
*
* Overrides the q parameter for highlighting
*
* @param string $query
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setQuery($query)
{
return $this->_setOption('query', $query);
}
/**
* Get query option
*
* @return string|null
*/
public function getQuery()
{
return $this->getOption('query');
}
/**
* Set phraselimit option
*
* @param int $maximum
* @return Solarium_Query_Select_Component_Highlighting Provides fluent interface
*/
public function setPhraseLimit($maximum)
{
return $this->_setOption('phraselimit', $maximum);
}
/**
* Get phraselimit option
*
* @return int|null
*/
public function getPhraseLimit()
{
return $this->getOption('phraselimit');
}
} }
\ 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
*/
/**
* Suggester Query
*
* Can be used for an autocomplete feature. See http://wiki.apache.org/solr/Suggester for more info.
*
* @package Solarium
* @subpackage Query
*/
class Solarium_Query_Suggester extends Solarium_Query
{
/**
* Get type for this query
*
* @return string
*/
public function getType()
{
return Solarium_Client::QUERYTYPE_SUGGESTER;
}
/**
* Default options
*
* @var array
*/
protected $_options = array(
'handler' => 'suggest',
'resultclass' => 'Solarium_Result_Suggester',
'termclass' => 'Solarium_Result_Suggester_Term',
);
/**
* Set query option
*
* Query to spellcheck
*
* @param string $query
* @return self Provides fluent interface
*/
public function setQuery($query)
{
return $this->_setOption('query', $query);
}
/**
* Get query option
*
* @return string|null
*/
public function getQuery()
{
return $this->getOption('query');
}
/**
* Set dictionary option
*
* The name of the dictionary to use
*
* @param string $dictionary
* @return self Provides fluent interface
*/
public function setDictionary($dictionary)
{
return $this->_setOption('dictionary', $dictionary);
}
/**
* Get dictionary option
*
* @return string|null
*/
public function getDictionary()
{
return $this->getOption('dictionary');
}
/**
* Set count option
*
* The maximum number of suggestions to return
*
* @param int $count
* @return self Provides fluent interface
*/
public function setCount($count)
{
return $this->_setOption('count', $count);
}
/**
* Get count option
*
* @return int|null
*/
public function getCount()
{
return $this->getOption('count');
}
/**
* Set onlyMorePopular option
*
* Only return suggestions that result in more hits for the query than the existing query
*
* @param boolean $onlyMorePopular
* @return self Provides fluent interface
*/
public function setOnlyMorePopular($onlyMorePopular)
{
return $this->_setOption('onlymorepopular', $onlyMorePopular);
}
/**
* Get onlyMorePopular option
*
* @return boolean|null
*/
public function getOnlyMorePopular()
{
return $this->getOption('onlymorepopular');
}
/**
* Set collate option
*
* @param boolean $collate
* @return self Provides fluent interface
*/
public function setCollate($collate)
{
return $this->_setOption('collate', $collate);
}
/**
* Get collate option
*
* @return boolean|null
*/
public function getCollate()
{
return $this->getOption('collate');
}
}
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
*/ */
/** /**
* Terns query * Terms query
* *
* A terms query provides access to the indexed terms in a field and the number of documents that match each term. * A terms query provides access to the indexed terms in a field and the number of documents that match each term.
* This can be useful for doing auto-suggest or other things that operate at the term level instead of the search * This can be useful for doing auto-suggest or other things that operate at the term level instead of the search
......
...@@ -72,6 +72,8 @@ class Solarium_Result ...@@ -72,6 +72,8 @@ class Solarium_Result
protected $_query; protected $_query;
/** /**
* Solarium client instance
*
* @var Solarium_Client * @var Solarium_Client
*/ */
protected $_client; protected $_client;
......
...@@ -46,41 +46,57 @@ class Solarium_Result_Analysis_Item ...@@ -46,41 +46,57 @@ class Solarium_Result_Analysis_Item
{ {
/** /**
* Text string
*
* @var string * @var string
*/ */
protected $_text; protected $_text;
/** /**
* RawText string
*
* @var string * @var string
*/ */
protected $_rawText; protected $_rawText;
/** /**
* Start
*
* @var int * @var int
*/ */
protected $_start; protected $_start;
/** /**
* End
*
* @var int * @var int
*/ */
protected $_end; protected $_end;
/** /**
* Position
*
* @var int * @var int
*/ */
protected $_position; protected $_position;
/** /**
* Position history
*
* @var array * @var array
*/ */
protected $_positionHistory; protected $_positionHistory;
/** /**
* Type
*
* @var string * @var string
*/ */
protected $_type; protected $_type;
/** /**
* Match
*
* @var boolean * @var boolean
*/ */
protected $_match = false; protected $_match = false;
......
...@@ -46,11 +46,15 @@ class Solarium_Result_Analysis_List implements IteratorAggregate, Countable ...@@ -46,11 +46,15 @@ class Solarium_Result_Analysis_List implements IteratorAggregate, Countable
{ {
/** /**
* List name
*
* @var string * @var string
*/ */
protected $_name; protected $_name;
/** /**
* List items
*
* @var array * @var array
*/ */
protected $_items; protected $_items;
......
...@@ -46,36 +46,50 @@ class Solarium_Result_Select_Debug implements IteratorAggregate, Countable ...@@ -46,36 +46,50 @@ class Solarium_Result_Select_Debug implements IteratorAggregate, Countable
{ {
/** /**
* QueryString
*
* @var string * @var string
*/ */
protected $_queryString; protected $_queryString;
/** /**
* ParsedQuery
*
* @var string * @var string
*/ */
protected $_parsedQuery; protected $_parsedQuery;
/** /**
* QueryParser
*
* @var string * @var string
*/ */
protected $_queryParser; protected $_queryParser;
/** /**
* OtherQuery
*
* @var string * @var string
*/ */
protected $_otherQuery; protected $_otherQuery;
/** /**
* Explain instance
*
* @var Solarium_Result_Select_Debug_DocumentSet * @var Solarium_Result_Select_Debug_DocumentSet
*/ */
protected $_explain; protected $_explain;
/** /**
* ExplainOther instance
*
* @var Solarium_Result_Select_Debug_DocumentSet * @var Solarium_Result_Select_Debug_DocumentSet
*/ */
protected $_explainOther; protected $_explainOther;
/** /**
* Timing instance
*
* @var Solarium_Result_Select_Debug_Timing * @var Solarium_Result_Select_Debug_Timing
*/ */
protected $_timing; protected $_timing;
......
...@@ -46,16 +46,22 @@ class Solarium_Result_Select_Debug_Detail ...@@ -46,16 +46,22 @@ class Solarium_Result_Select_Debug_Detail
{ {
/** /**
* Value
*
* @var float * @var float
*/ */
protected $_value; protected $_value;
/** /**
* Match
*
* @var boolean * @var boolean
*/ */
protected $_match; protected $_match;
/** /**
* Description
*
* @var string * @var string
*/ */
protected $_description; protected $_description;
......
...@@ -47,11 +47,15 @@ class Solarium_Result_Select_Debug_Document extends Solarium_Result_Select_Debug ...@@ -47,11 +47,15 @@ class Solarium_Result_Select_Debug_Document extends Solarium_Result_Select_Debug
{ {
/** /**
* Key
*
* @var string * @var string
*/ */
protected $_key; protected $_key;
/** /**
* Details
*
* @var array * @var array
*/ */
protected $_details; protected $_details;
...@@ -63,6 +67,7 @@ class Solarium_Result_Select_Debug_Document extends Solarium_Result_Select_Debug ...@@ -63,6 +67,7 @@ class Solarium_Result_Select_Debug_Document extends Solarium_Result_Select_Debug
* @param boolean $match * @param boolean $match
* @param float $value * @param float $value
* @param string $description * @param string $description
* @param array $details
*/ */
public function __construct($key, $match, $value, $description, $details) public function __construct($key, $match, $value, $description, $details)
{ {
......
...@@ -46,6 +46,8 @@ class Solarium_Result_Select_Debug_Timing implements IteratorAggregate, Countabl ...@@ -46,6 +46,8 @@ class Solarium_Result_Select_Debug_Timing implements IteratorAggregate, Countabl
{ {
/** /**
* Time
*
* @var float * @var float
*/ */
protected $_time; protected $_time;
......
...@@ -47,11 +47,15 @@ class Solarium_Result_Select_Debug_TimingPhase ...@@ -47,11 +47,15 @@ class Solarium_Result_Select_Debug_TimingPhase
{ {
/** /**
* Phase name
*
* @var string * @var string
*/ */
protected $_name; protected $_name;
/** /**
* Phase time
*
* @var float * @var float
*/ */
protected $_time; protected $_time;
......
...@@ -60,6 +60,8 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable ...@@ -60,6 +60,8 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
protected $_collation; protected $_collation;
/** /**
* Correctly spelled?
*
* @var boolean * @var boolean
*/ */
protected $_correctlySpelled; protected $_correctlySpelled;
......
...@@ -46,16 +46,22 @@ class Solarium_Result_Select_Spellcheck_Collation implements IteratorAggregate, ...@@ -46,16 +46,22 @@ class Solarium_Result_Select_Spellcheck_Collation implements IteratorAggregate,
{ {
/** /**
* Query
*
* @var string * @var string
*/ */
protected $_query; protected $_query;
/** /**
* Hit count
*
* @var int * @var int
*/ */
protected $_hits; protected $_hits;
/** /**
* Corrections
*
* @var array * @var array
*/ */
protected $_corrections; protected $_corrections;
......
<?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
*/
/**
* Suggester query result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Suggester extends Solarium_Result_QueryType implements IteratorAggregate, Countable
{
/**
* 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;
/**
* Suggester results
*
* @var array
*/
protected $_results;
/**
* Collation result
*
* Only available when collate is enabled in the suggester query
*
* @var string
*/
protected $_collation;
/**
* 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 results
*
* @return array
*/
public function getResults()
{
$this->_parseResponse();
return $this->_results;
}
/**
* Get results for a specific term
*
* @param string $term
* @return array
*/
public function getTerm($term)
{
$this->_parseResponse();
if (isset($this->_results[$term])) {
return $this->_results[$term];
} else {
return array();
}
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
$this->_parseResponse();
return new ArrayIterator($this->_results);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
$this->_parseResponse();
return count($this->_results);
}
/**
* Get collation
*
* @return null|string
*/
public function getCollation()
{
$this->_parseResponse();
return $this->_collation;
}
}
\ 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
*/
/**
* Suggester query term result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Suggester_Term implements IteratorAggregate, Countable
{
/**
* NumFound
*
* @var int
*/
protected $_numFound;
/**
* StartOffset
*
* @var int
*/
protected $_startOffset;
/**
* EndOffset
*
* @var int
*/
protected $_endOffset;
/**
* Suggestions
*
* @var array
*/
protected $_suggestions;
/**
* Constructor
*
* @param int $numFound
* @param int $startOffset
* @param int $endOffset
* @param array $suggestions
*/
public function __construct($numFound, $startOffset, $endOffset, $suggestions)
{
$this->_numFound = $numFound;
$this->_startOffset = $startOffset;
$this->_endOffset = $endOffset;
$this->_suggestions = $suggestions;
}
/**
* Get NumFound
*
* @return int
*/
public function getNumFound()
{
return $this->_numFound;
}
/**
* Get StartOffset
*
* @return int
*/
public function getStartOffset()
{
return $this->_startOffset;
}
/**
* Get EndOffset
*
* @return int
*/
public function getEndOffset()
{
return $this->_endOffset;
}
/**
* Get suggestions
*
* @return array
*/
public function getSuggestions()
{
return $this->_suggestions;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_suggestions);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_suggestions);
}
}
\ No newline at end of file
...@@ -70,7 +70,7 @@ class Solarium_Version ...@@ -70,7 +70,7 @@ class Solarium_Version
* *
* @var string * @var string
*/ */
const VERSION = '2.3.0'; const VERSION = '2.4.0';
/** /**
......
The buildphar.php will generate a solarium.phar PHAR file that is ready for distribution.
<?php
/**
* Copyright 2012 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 2012 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
// Check phar.readonly ini setting
if (ini_get('phar.readonly') == '1') {
exit("Your php.ini has phar.readonly enabled. Phar cannot be created. Please alter your php.ini first.\n");
}
// You can optionally use arguments to enable compression and whitespace/comment stripping.
// Example: "php buildphar.php -s 1 -c 1"
// -c with a value of 1 enables compression, multiple phars will be created
// -s with a value of 1 enables stripping
$options = getopt('s:c:');
$compress = (isset($options['c']) && $options['c'] == '1');
$strip = (isset($options['s']) && $options['s'] == '1');
$start = microtime(true);
// Create a new Solarium phar file
@unlink('solarium.phar');
$phar = new Phar('solarium.phar', 0, 'solarium.phar');
$phar->setStub(file_get_contents("stub.php"));
$phar->setSignatureAlgorithm(Phar::SHA1);
// Add files to the phar
$basePath = realpath(__DIR__."/../library/Solarium");
if ($strip) {
$directoryIterator = new RecursiveIteratorIterator (new RecursiveDirectoryIterator ($basePath), RecursiveIteratorIterator::SELF_FIRST);
foreach ($directoryIterator as $file) {
if ( preg_match ('/\\.php$/i', $file) ) {
$phar->addFromString (substr ($file, strlen ($basePath) + 1), php_strip_whitespace ($file));
}
}
} else {
$phar->buildFromDirectory($basePath, '/\.php$/');
}
// Create compressed versions
if ($compress) {
$phar->compress(Phar::BZ2);
$phar->compress(Phar::GZ);
}
$time = round(microtime(true)-$start,5);
echo "\nDONE ($time seconds)\n\n";
<?php
/**
* Copyright 2012 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 2012 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
Phar::mapPhar("solarium.phar");
require_once 'phar://solarium.phar/Autoloader.php';
Solarium_Autoloader::register();
if ('cli' === php_sapi_name() && basename(__FILE__) === basename($_SERVER['argv'][0]) && isset($_SERVER['argv'][1])) {
switch ($_SERVER['argv'][1]) {
case 'version':
echo "Solarium version " . Solarium_Version::VERSION ."\n";
break;
default:
echo "Unknown command '" . $_SERVER['argv'][1] . "' (Supported commands: version)\n";
}
exit(0);
}
__HALT_COMPILER();
?>
\ No newline at end of file
...@@ -76,8 +76,7 @@ class Solarium_Client_Adapter_CurlTest extends PHPUnit_Framework_TestCase ...@@ -76,8 +76,7 @@ class Solarium_Client_Adapter_CurlTest extends PHPUnit_Framework_TestCase
$response = $mock->execute($request); $response = $mock->execute($request);
$this->assertEquals($body,$response->getBody()); $this->assertEquals($data, $response);
$this->assertEquals($headers,$response->getHeaders());
} }
} }
\ No newline at end of file
...@@ -62,6 +62,8 @@ class Solarium_Client_Adapter_PeclHttpTest extends PHPUnit_Framework_TestCase ...@@ -62,6 +62,8 @@ class Solarium_Client_Adapter_PeclHttpTest extends PHPUnit_Framework_TestCase
public function requestProvider() public function requestProvider()
{ {
// prevents undefined constants errors
if (function_exists('http_get')) {
$methods = array( $methods = array(
Solarium_Client_Request::METHOD_GET => array( Solarium_Client_Request::METHOD_GET => array(
'method' => HTTP_METH_GET, 'method' => HTTP_METH_GET,
...@@ -93,6 +95,7 @@ class Solarium_Client_Adapter_PeclHttpTest extends PHPUnit_Framework_TestCase ...@@ -93,6 +95,7 @@ class Solarium_Client_Adapter_PeclHttpTest extends PHPUnit_Framework_TestCase
return $data; return $data;
} }
}
public function testToHttpRequestWithHeaders() public function testToHttpRequestWithHeaders()
{ {
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
class Solarium_Client_RequestBuilder_Select_Component_DebugTest extends PHPUnit_Framework_TestCase class Solarium_Client_RequestBuilder_Select_Component_DebugTest extends PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new Solarium_Client_RequestBuilder_Select_Component_Debug(); $builder = new Solarium_Client_RequestBuilder_Select_Component_Debug();
$request = new Solarium_Client_Request(); $request = new Solarium_Client_Request();
...@@ -40,12 +40,12 @@ class Solarium_Client_RequestBuilder_Select_Component_DebugTest extends PHPUnit_ ...@@ -40,12 +40,12 @@ class Solarium_Client_RequestBuilder_Select_Component_DebugTest extends PHPUnit_
$component = new Solarium_Query_Select_Component_Debug(); $component = new Solarium_Query_Select_Component_Debug();
$component->setExplainOther('id:45'); $component->setExplainOther('id:45');
$request = $builder->build($component, $request); $request = $builder->buildComponent($component, $request);
$this->assertEquals( $this->assertEquals(
array( array(
'debugQuery' => true, 'debugQuery' => 'true',
'debug.explain.structured' => true, 'debug.explain.structured' => 'true',
'explainOther' => 'id:45', 'explainOther' => 'id:45',
), ),
$request->getParams() $request->getParams()
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
class Solarium_Client_RequestBuilder_Select_Component_DisMaxTest extends PHPUnit_Framework_TestCase class Solarium_Client_RequestBuilder_Select_Component_DisMaxTest extends PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new Solarium_Client_RequestBuilder_Select_Component_DisMax; $builder = new Solarium_Client_RequestBuilder_Select_Component_DisMax;
$request = new Solarium_Client_Request(); $request = new Solarium_Client_Request();
...@@ -49,7 +49,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DisMaxTest extends PHPUnit ...@@ -49,7 +49,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DisMaxTest extends PHPUnit
$component->setBoostQuery('cat:1'); $component->setBoostQuery('cat:1');
$component->setBoostFunctions('functionX(price)'); $component->setBoostFunctions('functionX(price)');
$request = $builder->build($component, $request); $request = $builder->buildComponent($component, $request);
$this->assertEquals( $this->assertEquals(
array( array(
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
class Solarium_Client_RequestBuilder_Select_Component_DistributedSearchTest extends PHPUnit_Framework_TestCase class Solarium_Client_RequestBuilder_Select_Component_DistributedSearchTest extends PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new Solarium_Client_RequestBuilder_Select_Component_DistributedSearch; $builder = new Solarium_Client_RequestBuilder_Select_Component_DistributedSearch;
$request = new Solarium_Client_Request(); $request = new Solarium_Client_Request();
...@@ -45,7 +45,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DistributedSearchTest exte ...@@ -45,7 +45,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DistributedSearchTest exte
)); ));
$component->setShardRequestHandler('dummy'); $component->setShardRequestHandler('dummy');
$request = $builder->build($component, $request); $request = $builder->buildComponent($component, $request);
$this->assertEquals( $this->assertEquals(
array( array(
......
...@@ -57,7 +57,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn ...@@ -57,7 +57,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn
public function testBuildEmptyFacetSet() public function testBuildEmptyFacetSet()
{ {
$request = $this->_builder->build($this->_component, $this->_request); $request = $this->_builder->buildComponent($this->_component, $this->_request);
$this->assertEquals( $this->assertEquals(
array(), array(),
...@@ -71,7 +71,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn ...@@ -71,7 +71,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn
$this->_component->addFacet(new Solarium_Query_Select_Component_Facet_Field(array('key' => 'f1', 'field' => 'owner'))); $this->_component->addFacet(new Solarium_Query_Select_Component_Facet_Field(array('key' => 'f1', 'field' => 'owner')));
$this->_component->addFacet(new Solarium_Query_Select_Component_Facet_Query(array('key' => 'f2', 'query' => 'category:23'))); $this->_component->addFacet(new Solarium_Query_Select_Component_Facet_Query(array('key' => 'f2', 'query' => 'category:23')));
$this->_component->addFacet(new Solarium_Query_Select_Component_Facet_MultiQuery(array('key' => 'f3', 'query' => array('f4' => array('query' => 'category:40'))))); $this->_component->addFacet(new Solarium_Query_Select_Component_Facet_MultiQuery(array('key' => 'f3', 'query' => array('f4' => array('query' => 'category:40')))));
$request = $this->_builder->build($this->_component, $this->_request); $request = $this->_builder->buildComponent($this->_component, $this->_request);
$this->assertEquals( $this->assertEquals(
null, null,
...@@ -98,7 +98,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn ...@@ -98,7 +98,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn
) )
)); ));
$request = $this->_builder->build($this->_component, $this->_request); $request = $this->_builder->buildComponent($this->_component, $this->_request);
$this->assertEquals( $this->assertEquals(
null, null,
...@@ -111,6 +111,31 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn ...@@ -111,6 +111,31 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn
); );
} }
public function testBuildWithRangeFacetExcludingOptionalParams()
{
$this->_component->addFacet(new Solarium_Query_Select_Component_Facet_Range(
array(
'key' => 'f1',
'field' => 'price',
'start' => '1',
'end' => 100,
'gap' => 10,
)
));
$request = $this->_builder->buildComponent($this->_component, $this->_request);
$this->assertEquals(
null,
$request->getRawData()
);
$this->assertEquals(
'?facet=true&facet.range={!key=f1}price&f.price.facet.range.start=1&f.price.facet.range.end=100&f.price.facet.range.gap=10',
urldecode($request->getUri())
);
}
public function testBuildWithFacetsAndGlobalFacetSettings() public function testBuildWithFacetsAndGlobalFacetSettings()
{ {
$this->_component->setMissing(true); $this->_component->setMissing(true);
...@@ -118,7 +143,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn ...@@ -118,7 +143,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn
$this->_component->addFacet(new Solarium_Query_Select_Component_Facet_Field(array('key' => 'f1', 'field' => 'owner'))); $this->_component->addFacet(new Solarium_Query_Select_Component_Facet_Field(array('key' => 'f1', 'field' => 'owner')));
$this->_component->addFacet(new Solarium_Query_Select_Component_Facet_Query(array('key' => 'f2', 'query' => 'category:23'))); $this->_component->addFacet(new Solarium_Query_Select_Component_Facet_Query(array('key' => 'f2', 'query' => 'category:23')));
$this->_component->addFacet(new Solarium_Query_Select_Component_Facet_MultiQuery(array('key' => 'f3', 'query' => array('f4' =>array('query' => 'category:40'))))); $this->_component->addFacet(new Solarium_Query_Select_Component_Facet_MultiQuery(array('key' => 'f3', 'query' => array('f4' =>array('query' => 'category:40')))));
$request = $this->_builder->build($this->_component, $this->_request); $request = $this->_builder->buildComponent($this->_component, $this->_request);
$this->assertEquals( $this->assertEquals(
null, null,
...@@ -135,7 +160,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn ...@@ -135,7 +160,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn
{ {
$this->_component->addFacet(new UnknownFacet(array('key' => 'f1', 'field' => 'owner'))); $this->_component->addFacet(new UnknownFacet(array('key' => 'f1', 'field' => 'owner')));
$this->setExpectedException('Solarium_Exception'); $this->setExpectedException('Solarium_Exception');
$request = $this->_builder->build($this->_component, $this->_request); $request = $this->_builder->buildComponent($this->_component, $this->_request);
$request->getUri(); $request->getUri();
} }
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
class Solarium_Client_RequestBuilder_Select_Component_GroupingTest extends PHPUnit_Framework_TestCase class Solarium_Client_RequestBuilder_Select_Component_GroupingTest extends PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new Solarium_Client_RequestBuilder_Select_Component_Grouping; $builder = new Solarium_Client_RequestBuilder_Select_Component_Grouping;
$request = new Solarium_Client_Request(); $request = new Solarium_Client_Request();
...@@ -48,7 +48,7 @@ class Solarium_Client_RequestBuilder_Select_Component_GroupingTest extends PHPUn ...@@ -48,7 +48,7 @@ class Solarium_Client_RequestBuilder_Select_Component_GroupingTest extends PHPUn
$component->setCachePercentage(50); $component->setCachePercentage(50);
$component->setTruncate(true); $component->setTruncate(true);
$request = $builder->build($component, $request); $request = $builder->buildComponent($component, $request);
$this->assertEquals( $this->assertEquals(
array( array(
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends PHPUnit_Framework_TestCase class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new Solarium_Client_RequestBuilder_Select_Component_Highlighting; $builder = new Solarium_Client_RequestBuilder_Select_Component_Highlighting;
$request = new Solarium_Client_Request(); $request = new Solarium_Client_Request();
...@@ -70,8 +70,10 @@ class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends P ...@@ -70,8 +70,10 @@ class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends P
$component->setRegexSlop(1.3); $component->setRegexSlop(1.3);
$component->setRegexPattern('mypattern'); $component->setRegexPattern('mypattern');
$component->setMaxAnalyzedChars(100); $component->setMaxAnalyzedChars(100);
$component->setQuery('text:myvalue');
$component->setPhraseLimit(40);
$request = $builder->build($component, $request); $request = $builder->buildComponent($component, $request);
$this->assertEquals( $this->assertEquals(
array( array(
...@@ -95,6 +97,8 @@ class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends P ...@@ -95,6 +97,8 @@ class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends P
'hl.highlightMultiTerm' => 'true', 'hl.highlightMultiTerm' => 'true',
'hl.regex.slop' => 1.3, 'hl.regex.slop' => 1.3,
'hl.regex.pattern' => 'mypattern', 'hl.regex.pattern' => 'mypattern',
'hl.q' => 'text:myvalue',
'hl.phraseLimit' => 40,
'f.fieldB.hl.snippets' => 3, 'f.fieldB.hl.snippets' => 3,
'f.fieldB.hl.fragsize' => 25, 'f.fieldB.hl.fragsize' => 25,
'f.fieldB.hl.mergeContiguous' => 'true', 'f.fieldB.hl.mergeContiguous' => 'true',
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
class Solarium_Client_RequestBuilder_Select_Component_MoreLikeThisTest extends PHPUnit_Framework_TestCase class Solarium_Client_RequestBuilder_Select_Component_MoreLikeThisTest extends PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new Solarium_Client_RequestBuilder_Select_Component_MoreLikeThis; $builder = new Solarium_Client_RequestBuilder_Select_Component_MoreLikeThis;
$request = new Solarium_Client_Request(); $request = new Solarium_Client_Request();
...@@ -49,7 +49,7 @@ class Solarium_Client_RequestBuilder_Select_Component_MoreLikeThisTest extends P ...@@ -49,7 +49,7 @@ class Solarium_Client_RequestBuilder_Select_Component_MoreLikeThisTest extends P
$component->setQueryFields('description'); $component->setQueryFields('description');
$component->setCount(6); $component->setCount(6);
$request = $builder->build($component, $request); $request = $builder->buildComponent($component, $request);
$this->assertEquals( $this->assertEquals(
array( array(
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
class Solarium_Client_RequestBuilder_Select_Component_SpellcheckTest extends PHPUnit_Framework_TestCase class Solarium_Client_RequestBuilder_Select_Component_SpellcheckTest extends PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new Solarium_Client_RequestBuilder_Select_Component_Spellcheck(); $builder = new Solarium_Client_RequestBuilder_Select_Component_Spellcheck();
$request = new Solarium_Client_Request(); $request = new Solarium_Client_Request();
...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_SpellcheckTest extends PHP ...@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_SpellcheckTest extends PHP
$component->setCollateExtendedResults(true); $component->setCollateExtendedResults(true);
$component->setAccuracy(.2); $component->setAccuracy(.2);
$request = $builder->build($component, $request); $request = $builder->buildComponent($component, $request);
$this->assertEquals( $this->assertEquals(
array( array(
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
class Solarium_Client_RequestBuilder_Select_Component_StatsTest extends PHPUnit_Framework_TestCase class Solarium_Client_RequestBuilder_Select_Component_StatsTest extends PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new Solarium_Client_RequestBuilder_Select_Component_Stats(); $builder = new Solarium_Client_RequestBuilder_Select_Component_Stats();
$request = new Solarium_Client_Request(); $request = new Solarium_Client_Request();
...@@ -42,7 +42,7 @@ class Solarium_Client_RequestBuilder_Select_Component_StatsTest extends PHPUnit_ ...@@ -42,7 +42,7 @@ class Solarium_Client_RequestBuilder_Select_Component_StatsTest extends PHPUnit_
$component->createField('fieldB'); $component->createField('fieldB');
$component->addFacets(array('facetA', 'facetB')); $component->addFacets(array('facetA', 'facetB'));
$request = $builder->build($component, $request); $request = $builder->buildComponent($component, $request);
$this->assertEquals( $this->assertEquals(
array( array(
......
...@@ -67,7 +67,7 @@ class Solarium_Client_RequestBuilder_SelectTest extends PHPUnit_Framework_TestCa ...@@ -67,7 +67,7 @@ class Solarium_Client_RequestBuilder_SelectTest extends PHPUnit_Framework_TestCa
); );
$this->assertEquals( $this->assertEquals(
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json', 'select?wt=json&q=*:*&start=0&rows=10&fl=*,score',
urldecode($request->getUri()) urldecode($request->getUri())
); );
} }
...@@ -84,7 +84,7 @@ class Solarium_Client_RequestBuilder_SelectTest extends PHPUnit_Framework_TestCa ...@@ -84,7 +84,7 @@ class Solarium_Client_RequestBuilder_SelectTest extends PHPUnit_Framework_TestCa
); );
$this->assertEquals( $this->assertEquals(
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json&sort=id asc,name desc', 'select?wt=json&q=*:*&start=0&rows=10&fl=*,score&sort=id asc,name desc',
urldecode($request->getUri()) urldecode($request->getUri())
); );
} }
...@@ -101,7 +101,7 @@ class Solarium_Client_RequestBuilder_SelectTest extends PHPUnit_Framework_TestCa ...@@ -101,7 +101,7 @@ class Solarium_Client_RequestBuilder_SelectTest extends PHPUnit_Framework_TestCa
); );
$this->assertEquals( $this->assertEquals(
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json&q.op=AND&df=mydefault', 'select?wt=json&q=*:*&start=0&rows=10&fl=*,score&q.op=AND&df=mydefault',
urldecode($request->getUri()) urldecode($request->getUri())
); );
} }
...@@ -120,7 +120,7 @@ class Solarium_Client_RequestBuilder_SelectTest extends PHPUnit_Framework_TestCa ...@@ -120,7 +120,7 @@ class Solarium_Client_RequestBuilder_SelectTest extends PHPUnit_Framework_TestCa
); );
$this->assertEquals( $this->assertEquals(
'select?q=*:*&start=0&rows=10&fl=*,score&wt=json&sort=id asc,name desc&fq=published:true&fq={!tag=t1,t2}category:23', 'select?wt=json&q=*:*&start=0&rows=10&fl=*,score&sort=id asc,name desc&fq=published:true&fq={!tag=t1,t2}category:23',
urldecode($request->getUri()) urldecode($request->getUri())
); );
} }
......
<?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_SuggesterTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Suggester
*/
protected $_query;
/**
* @var Solarium_Client_RequestBuilder_Suggester
*/
protected $_builder;
public function setUp()
{
$this->_query = new Solarium_Query_Suggester;
$this->_builder = new Solarium_Client_RequestBuilder_Suggester;
}
public function testBuildParams()
{
$this->_query->setCollate(true);
$this->_query->setCount(13);
$this->_query->setDictionary('suggest');
$this->_query->setQuery('ap ip');
$this->_query->setOnlyMorePopular(true);
$request = $this->_builder->build($this->_query);
$this->assertEquals(
array(
'spellcheck' => 'true',
'q' => 'ap ip',
'spellcheck.dictionary' => 'suggest',
'spellcheck.count' => 13,
'spellcheck.onlyMorePopular' => 'true',
'spellcheck.collate' => 'true',
'wt' => 'json',
),
$request->getParams()
);
$this->assertEquals(
Solarium_Client_Request::METHOD_GET,
$request->getMethod()
);
}
}
\ No newline at end of file
...@@ -31,7 +31,9 @@ ...@@ -31,7 +31,9 @@
class Solarium_Client_RequestBuilderTest extends PHPUnit_Framework_TestCase class Solarium_Client_RequestBuilderTest extends PHPUnit_Framework_TestCase
{ {
/**
* @var TestRequestBuilder
*/
protected $_builder; protected $_builder;
public function setup() public function setup()
...@@ -39,6 +41,19 @@ class Solarium_Client_RequestBuilderTest extends PHPUnit_Framework_TestCase ...@@ -39,6 +41,19 @@ class Solarium_Client_RequestBuilderTest extends PHPUnit_Framework_TestCase
$this->_builder = new TestRequestBuilder; $this->_builder = new TestRequestBuilder;
} }
public function testBuild()
{
$query = new Solarium_Query_Select;
$query->addParam('p1','v1');
$query->addParam('p2','v2');
$request = $this->_builder->build($query);
$this->assertEquals(
'select?p1=v1&p2=v2&wt=json',
urldecode($request->getUri())
);
}
public function testRenderLocalParams() public function testRenderLocalParams()
{ {
$myParams = array('tag' => 'mytag', 'ex' => array('exclude1','exclude2')); $myParams = array('tag' => 'mytag', 'ex' => array('exclude1','exclude2'));
......
...@@ -439,4 +439,37 @@ class Solarium_Client_RequestTest extends PHPUnit_Framework_TestCase ...@@ -439,4 +439,37 @@ class Solarium_Client_RequestTest extends PHPUnit_Framework_TestCase
); );
} }
public function testToString()
{
$options = array(
'method' => Solarium_Client_Request::METHOD_POST,
'handler' => '/myHandler',
'param' => array(
'param1' => 1,
'param2' => 'test content',
),
'rawdata' => 'post data',
'header' => array(
'myHeader1' => 'X-myHeader1: value1',
'myHeader2' => 'X-myHeader2: value2',
),
);
$this->_request->setOptions($options);
$this->assertEquals(
'Solarium_Client_Request::toString
method: POST
header: Array
(
[0] => X-myHeader1: value1
[1] => X-myHeader2: value2
)
resource: /myHandler?param1=1&param2=test+content
resource urldecoded: /myHandler?param1=1&param2=test content
raw data: post data
',
(string)$this->_request
);
}
} }
\ No newline at end of file
...@@ -40,6 +40,8 @@ class Solarium_Client_ResponseParser_Analysis_FieldTest extends PHPUnit_Framewor ...@@ -40,6 +40,8 @@ class Solarium_Client_ResponseParser_Analysis_FieldTest extends PHPUnit_Framewor
'field1' => array( 'field1' => array(
'type1' => array( 'type1' => array(
array( array(
'org.apache.solr.analysis.PatternReplaceCharFilter',
'string value',
'analysisClass', 'analysisClass',
array( array(
array( array(
...@@ -81,9 +83,11 @@ class Solarium_Client_ResponseParser_Analysis_FieldTest extends PHPUnit_Framewor ...@@ -81,9 +83,11 @@ class Solarium_Client_ResponseParser_Analysis_FieldTest extends PHPUnit_Framewor
$docs = $result['items'][0]->getItems(); $docs = $result['items'][0]->getItems();
$fields = $docs[0]->getItems(); $fields = $docs[0]->getItems();
$types = $fields[0]->getItems(); $types = $fields[0]->getItems();
$classes = $types[0]->getItems(); $class1items = $types[0]->getItems();
$class2items = $types[1]->getItems();
$this->assertEquals('test2', $classes[1]->getText()); $this->assertEquals('string value', $class1items[0]->getText());
$this->assertEquals('test2', $class2items[1]->getText());
} }
public function testParseNoData() public function testParseNoData()
......
<?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_ResponseParser_SuggesterTest extends PHPUnit_Framework_TestCase
{
public function testParse()
{
$data = array(
'responseHeader' => array(
'status' => 1,
'QTime' => 13,
),
'spellcheck' => array(
'suggestions' => array(
'd',
array(
'numFound' => 2,
'startOffset' => 3,
'endOffset' => 7,
'suggestion' => array(
'disk',
'ddr'
)
),
'vid',
array(
'numFound' => 1,
'startOffset' => 2,
'endOffset' => 5,
'suggestion' => array(
'video',
)
),
'collation',
'disk video'
),
),
);
$query = new Solarium_Query_Suggester();
$resultStub = $this->getMock('Solarium_Result_Suggester', array(), array(), '', false);
$resultStub->expects($this->any())
->method('getData')
->will($this->returnValue($data));
$resultStub->expects($this->any())
->method('getQuery')
->will($this->returnValue($query));
$parser = new Solarium_Client_ResponseParser_Suggester;
$result = $parser->parse($resultStub);
$expected = array(
'd' => new Solarium_Result_Suggester_Term(2,3,7,array('disk','ddr')),
'vid' => new Solarium_Result_Suggester_Term(1,2,5,array('video'))
);
$this->assertEquals($expected, $result['results']);
$this->assertEquals('disk video', $result['collation']);
}
}
...@@ -656,6 +656,18 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase ...@@ -656,6 +656,18 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$observer->terms($query); $observer->terms($query);
} }
public function testSuggester()
{
$query = new Solarium_Query_Suggester();
$observer = $this->getMock('Solarium_Client', array('execute'));
$observer->expects($this->once())
->method('execute')
->with($this->equalTo($query));
$observer->suggester($query);
}
public function testCreateQuery() public function testCreateQuery()
{ {
$options = array('optionA' => 1, 'optionB' => 2); $options = array('optionA' => 1, 'optionB' => 2);
...@@ -812,6 +824,18 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase ...@@ -812,6 +824,18 @@ class Solarium_ClientTest extends PHPUnit_Framework_TestCase
$observer->createTerms($options); $observer->createTerms($options);
} }
public function testCreateSuggester()
{
$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_SUGGESTER), $this->equalTo($options));
$observer->createSuggester($options);
}
public function testTriggerEvent() public function testTriggerEvent()
{ {
$eventName = 'Test'; $eventName = 'Test';
......
<?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_Plugin_BufferedAddTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Plugin_BufferedAdd
*/
protected $_plugin;
public function setUp()
{
$this->_plugin = new Solarium_Plugin_BufferedAdd();
$this->_plugin->init(new Solarium_Client(), array());
}
public function testSetAndGetBufferSize()
{
$this->_plugin->setBufferSize(500);
$this->assertEquals(500, $this->_plugin->getBufferSize());
}
public function testAddDocument()
{
$doc = new Solarium_Document_ReadWrite();
$doc->id = '123';
$doc->name = 'test';
$this->_plugin->addDocument($doc);
$this->assertEquals(array($doc), $this->_plugin->getDocuments());
}
public function testCreateDocument()
{
$data = array('id' => '123', 'name' => 'test');
$doc = new Solarium_Document_ReadWrite($data);
$this->_plugin->createDocument($data);
$this->assertEquals(array($doc), $this->_plugin->getDocuments());
}
public function testAddDocuments()
{
$doc1 = new Solarium_Document_ReadWrite();
$doc1->id = '123';
$doc1->name = 'test';
$doc2 = new Solarium_Document_ReadWrite();
$doc2->id = '234';
$doc2->name = 'test2';
$docs = array($doc1, $doc2);
$this->_plugin->addDocuments($docs);
$this->assertEquals($docs, $this->_plugin->getDocuments());
}
public function testAddDocumentAutoFlush()
{
$observer = $this->getMock('Solarium_Plugin_BufferedAdd', array('flush'));
$observer->expects($this->once())->method('flush');
$observer->setBufferSize(1);
$doc1 = new Solarium_Document_ReadWrite();
$doc1->id = '123';
$doc1->name = 'test';
$doc2 = new Solarium_Document_ReadWrite();
$doc2->id = '234';
$doc2->name = 'test2';
$docs = array($doc1, $doc2);
$observer->addDocuments($docs);
}
public function testClear()
{
$doc = new Solarium_Document_ReadWrite();
$doc->id = '123';
$doc->name = 'test';
$this->_plugin->addDocument($doc);
$this->_plugin->clear();
$this->assertEquals(array(), $this->_plugin->getDocuments());
}
public function testFlushEmptyBuffer()
{
$this->assertEquals(false, $this->_plugin->flush());
}
public function testFlush()
{
$data = array('id' => '123', 'name' => 'test');
$doc = new Solarium_Document_ReadWrite($data);
$mockUpdate = $this->getMock('Solarium_Query_Update', array('addDocuments'));
$mockUpdate->expects($this->once())->method('addDocuments')->with($this->equalTo(array($doc)),$this->equalTo(true),$this->equalTo(12));
$mockClient = $this->getMock('Solarium_Client', array('createUpdate', 'update', 'triggerEvent'));
$mockClient->expects($this->exactly(2))->method('createUpdate')->will($this->returnValue($mockUpdate));
$mockClient->expects($this->once())->method('update')->will($this->returnValue('dummyResult'));
$mockClient->expects($this->exactly(2))->method('triggerEvent');
$plugin = new Solarium_Plugin_BufferedAdd();
$plugin->init($mockClient, array());
$plugin->addDocument($doc);
$this->assertEquals('dummyResult', $plugin->flush(true,12));
}
public function testCommit()
{
$data = array('id' => '123', 'name' => 'test');
$doc = new Solarium_Document_ReadWrite($data);
$mockUpdate = $this->getMock('Solarium_Query_Update', array('addDocuments', 'addCommit'));
$mockUpdate->expects($this->once())->method('addDocuments')->with($this->equalTo(array($doc)),$this->equalTo(true));
$mockUpdate->expects($this->once())->method('addCommit')->with($this->equalTo(false),$this->equalTo(true),$this->equalTo(false));
$mockClient = $this->getMock('Solarium_Client', array('createUpdate', 'update', 'triggerEvent'));
$mockClient->expects($this->exactly(2))->method('createUpdate')->will($this->returnValue($mockUpdate));
$mockClient->expects($this->once())->method('update')->will($this->returnValue('dummyResult'));
$mockClient->expects($this->exactly(2))->method('triggerEvent');
$plugin = new Solarium_Plugin_BufferedAdd();
$plugin->init($mockClient, array());
$plugin->addDocument($doc);
$this->assertEquals('dummyResult', $plugin->commit(true, false, true, false));
}
}
\ 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_Plugin_ParallelExecutionTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Plugin_ParallelExecution
*/
protected $_plugin;
public function setUp()
{
$this->_plugin = new Solarium_Plugin_ParallelExecution();
}
public function testAddAndGetQueries()
{
$client1 = new Solarium_Client();
$client2 = new Solarium_Client(array(
'adapter' => 'MyAdapter',
'adapteroptions' => array(
'host' => 'myhost',
)
)
);
$this->_plugin->init($client1, array());
$query1 = $client1->createSelect()->setQuery('test1');
$query2 = $client1->createSelect()->setQuery('test2');
$this->_plugin->addQuery(1, $query1);
$this->_plugin->addQuery(2, $query2, $client2);
$this->assertEquals(
array(
1 => array('query' => $query1, 'client' => $client1),
2 => array('query' => $query2, 'client' => $client2),
),
$this->_plugin->getQueries()
);
}
public function testClearQueries()
{
$client = new Solarium_Client();
$this->_plugin->init($client, array());
$query1 = $client->createSelect()->setQuery('test1');
$query2 = $client->createSelect()->setQuery('test2');
$this->_plugin->addQuery(1, $query1);
$this->_plugin->addQuery(2, $query2);
$this->_plugin->clearQueries();
$this->assertEquals(
array(),
$this->_plugin->getQueries()
);
}
}
\ 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_Plugin_PrefetchIteratorTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Plugin_PrefetchIterator
*/
protected $_plugin;
/**
* @var Solarium_Client
*/
protected $_client;
/**
* @var Solarium_Query_Select
*/
protected $_query;
public function setUp()
{
$this->_plugin = new Solarium_Plugin_PrefetchIterator();
$this->_client = new Solarium_Client();
$this->_query = $this->_client->createSelect();
}
public function testSetAndGetPrefetch()
{
$this->_plugin->setPrefetch(120);
$this->assertEquals(120, $this->_plugin->getPrefetch());
}
public function testSetAndGetQuery()
{
$this->_plugin->setQuery($this->_query);
$this->assertEquals($this->_query, $this->_plugin->getQuery());
}
public function testCount()
{
$result = $this->_getResult();
$mockClient = $this->getMock('Solarium_Client', array('execute'));
$mockClient->expects($this->exactly(1))->method('execute')->will($this->returnValue($result));
$this->_plugin->init($mockClient, array());
$this->_plugin->setQuery($this->_query);
$this->assertEquals(5, count($this->_plugin));
}
public function testIteratorAndRewind()
{
$result = $this->_getResult();
$mockClient = $this->getMock('Solarium_Client', array('execute'));
$mockClient->expects($this->exactly(1))->method('execute')->will($this->returnValue($result));
$this->_plugin->init($mockClient, array());
$this->_plugin->setQuery($this->_query);
$results1 = array();
foreach($this->_plugin as $doc) {
$results1[] = $doc;
}
// the second foreach will trigger a rewind, this time include keys
$results2 = array();
foreach($this->_plugin as $key => $doc) {
$results2[$key] = $doc;
}
$this->assertEquals($result->getDocuments(), $results1);
$this->assertEquals($result->getDocuments(), $results2);
}
public function _getResult()
{
$numFound = 5;
$docs = array(
new Solarium_Document_ReadOnly(array('id'=>1,'title'=>'doc1')),
new Solarium_Document_ReadOnly(array('id'=>2,'title'=>'doc2')),
new Solarium_Document_ReadOnly(array('id'=>3,'title'=>'doc3')),
new Solarium_Document_ReadOnly(array('id'=>4,'title'=>'doc4')),
new Solarium_Document_ReadOnly(array('id'=>5,'title'=>'doc5')),
);
return new Solarium_Result_SelectDummy(1, 12, $numFound, $docs, array());
}
}
\ No newline at end of file
...@@ -31,11 +31,20 @@ ...@@ -31,11 +31,20 @@
class Solarium_Query_HelperTest extends PHPUnit_Framework_TestCase class Solarium_Query_HelperTest extends PHPUnit_Framework_TestCase
{ {
/**
* @var Solarium_Query_Helper
*/
protected $_helper; protected $_helper;
/**
* @var Solarium_Query_Select
*/
protected $_query;
public function setUp() public function setUp()
{ {
$this->_helper = new Solarium_Query_Helper; $this->_query = new Solarium_Query_Select;
$this->_helper = new Solarium_Query_Helper($this->_query);
} }
public function testRangeQueryInclusive() public function testRangeQueryInclusive()
...@@ -104,6 +113,38 @@ class Solarium_Query_HelperTest extends PHPUnit_Framework_TestCase ...@@ -104,6 +113,38 @@ class Solarium_Query_HelperTest extends PHPUnit_Framework_TestCase
); );
} }
public function testQparserDereferencedNoQuery()
{
$helper = new Solarium_Query_Helper();
$this->setExpectedException('Solarium_Exception');
$helper->qparser('join', array('from' => 'manu_id', 'to' => 'id'), true);
}
public function testQparserDereferenced()
{
$this->assertEquals(
'{!join from=$deref_1 to=$deref_2}',
$this->_helper->qparser('join', array('from' => 'manu_id', 'to' => 'id'), true)
);
$this->assertEquals(
array('deref_1' => 'manu_id', 'deref_2' => 'id'),
$this->_query->getParams()
);
// second call, params should have updated counts
$this->assertEquals(
'{!join from=$deref_3 to=$deref_4}',
$this->_helper->qparser('join', array('from' => 'cat_id', 'to' => 'prod_id'), true)
);
// previous params should also still be there
$this->assertEquals(
array('deref_1' => 'manu_id', 'deref_2' => 'id', 'deref_3' => 'cat_id', 'deref_4' => 'prod_id'),
$this->_query->getParams()
);
}
public function testFunctionCallNoParams() public function testFunctionCallNoParams()
{ {
$this->assertEquals( $this->assertEquals(
...@@ -152,6 +193,83 @@ class Solarium_Query_HelperTest extends PHPUnit_Framework_TestCase ...@@ -152,6 +193,83 @@ class Solarium_Query_HelperTest extends PHPUnit_Framework_TestCase
); );
} }
public function testFormatDateInputTimestamp()
{
$this->assertFalse(
$this->_helper->formatDate(strtotime('2011---')),
'Expects invalid strtotime/timestamp input (false) not to be accepted'
);
//allow negative dates.
$this->assertNotEquals(
false,
$this->_helper->formatDate(strtotime('2011-10-01')),
'Expects negative timestamp input to be accepted'
);
//@todo find out if we need to any test for php versions / platforms which do not support negative timestamp
$this->assertFalse(
$this->_helper->formatDate(strtotime('2010-31-02')),
'Expects invalid timestamp input (not in calendar) not to be accepted'
);
$this->assertEquals(
$this->_mockFormatDateOutput(strtotime('2011-10-01')),
$this->_helper->formatDate(strtotime('2011-10-01')),
'Expects formatDate with Timstamp input to output ISO8601 with stripped timezone'
);
}
public function testFormatDateInputString()
{
$this->assertFalse(
$this->_helper->formatDate('2011-13-31'),
'Expects an invalid date string input not to be accepted'
);
$this->assertEquals(
$this->_mockFormatDateOutput(strtotime('2011-10-01')),
$this->_helper->formatDate('2011-10-01'),
'Expects formatDate with String input to output ISO8601 with stripped timezone'
);
}
public function testFormatDateInputDateTime()
{
date_default_timezone_set("UTC"); // prevent timezone differences
$this->assertFalse(
$this->_helper->formatDate(new stdClass()),
'Expect any other object not to be accepted'
);
$this->assertEquals(
$this->_mockFormatDateOutput(strtotime('2011-10-01')),
$this->_helper->formatDate(new DateTime('2011-10-01')),
'Expects formatDate with DateTime input to output ISO8601 with stripped timezone'
);
}
public function testFormatDate()
{
//check if timezone is stripped
$expected = strtoupper('Z');
$actual = substr($this->_helper->formatDate(time()), 19, 20);
$this->assertEquals($expected, $actual, 'Expects last charachter to be uppercased Z');
$this->assertEquals(
$this->_mockFormatDateOutput(time()),
$this->_helper->formatDate(time())
);
}
protected function _mockFormatDateOutput($timestamp)
{
$date = new DateTime('@'.$timestamp);
return strstr($date->format(DateTime::ISO8601), '+', true) . 'Z';
}
public function testAssemble() public function testAssemble()
{ {
// test single basic placeholder // test single basic placeholder
...@@ -197,4 +315,25 @@ class Solarium_Query_HelperTest extends PHPUnit_Framework_TestCase ...@@ -197,4 +315,25 @@ class Solarium_Query_HelperTest extends PHPUnit_Framework_TestCase
$this->_helper->assemble('cat:%1% AND content:%2%',array('value1')); $this->_helper->assemble('cat:%1% AND content:%2%',array('value1'));
} }
public function testJoin()
{
$this->assertEquals(
'{!join from=manu_id to=id}',
$this->_helper->join('manu_id', 'id')
);
}
public function testJoinDereferenced()
{
$this->assertEquals(
'{!join from=$deref_1 to=$deref_2}',
$this->_helper->join('manu_id', 'id', true)
);
$this->assertEquals(
array('deref_1' => 'manu_id', 'deref_2' => 'id'),
$this->_query->getParams()
);
}
} }
...@@ -71,6 +71,8 @@ class Solarium_Query_Select_Component_HighlightingTest extends PHPUnit_Framework ...@@ -71,6 +71,8 @@ class Solarium_Query_Select_Component_HighlightingTest extends PHPUnit_Framework
'regexslop' => .8, 'regexslop' => .8,
'regexpattern' => 'myPattern', 'regexpattern' => 'myPattern',
'regexmaxanalyzedchars' => 500, 'regexmaxanalyzedchars' => 500,
'query' => 'text:myvalue',
'phraselimit' => 35,
); );
...@@ -98,6 +100,8 @@ class Solarium_Query_Select_Component_HighlightingTest extends PHPUnit_Framework ...@@ -98,6 +100,8 @@ class Solarium_Query_Select_Component_HighlightingTest extends PHPUnit_Framework
$this->assertEquals($options['regexslop'], $this->_hlt->getRegexSlop()); $this->assertEquals($options['regexslop'], $this->_hlt->getRegexSlop());
$this->assertEquals($options['regexpattern'], $this->_hlt->getRegexPattern()); $this->assertEquals($options['regexpattern'], $this->_hlt->getRegexPattern());
$this->assertEquals($options['regexmaxanalyzedchars'], $this->_hlt->getRegexMaxAnalyzedChars()); $this->assertEquals($options['regexmaxanalyzedchars'], $this->_hlt->getRegexMaxAnalyzedChars());
$this->assertEquals($options['query'], $this->_hlt->getQuery());
$this->assertEquals($options['phraselimit'], $this->_hlt->getPhraseLimit());
} }
public function testGetType() public function testGetType()
...@@ -447,4 +451,26 @@ class Solarium_Query_Select_Component_HighlightingTest extends PHPUnit_Framework ...@@ -447,4 +451,26 @@ class Solarium_Query_Select_Component_HighlightingTest extends PHPUnit_Framework
); );
} }
public function testSetAndGetQuery()
{
$value = 'text:myvalue';
$this->_hlt->setQuery($value);
$this->assertEquals(
$value,
$this->_hlt->getQuery()
);
}
public function testSetAndGetPhraseLimit()
{
$value = 20;
$this->_hlt->setPhraseLimit($value);
$this->assertEquals(
$value,
$this->_hlt->getPhraseLimit()
);
}
} }
<?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_SuggesterTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Suggester
*/
protected $_query;
public function setUp()
{
$this->_query = new Solarium_Query_Suggester;
}
public function testGetType()
{
$this->assertEquals(Solarium_Client::QUERYTYPE_SUGGESTER, $this->_query->getType());
}
public function testSetAndGetQuery()
{
$value = 'testquery';
$this->_query->setQuery($value);
$this->assertEquals(
$value,
$this->_query->getQuery()
);
}
public function testSetAndGetDictionary()
{
$value = 'myDictionary';
$this->_query->setDictionary($value);
$this->assertEquals(
$value,
$this->_query->getDictionary()
);
}
public function testSetAndGetCount()
{
$value = 11;
$this->_query->setCount($value);
$this->assertEquals(
$value,
$this->_query->getCount()
);
}
public function testSetAndGetOnlyMorePopular()
{
$value = false;
$this->_query->setOnlyMorePopular($value);
$this->assertEquals(
$value,
$this->_query->getOnlyMorePopular()
);
}
public function testSetAndGetCollate()
{
$value = false;
$this->_query->setCollate($value);
$this->assertEquals(
$value,
$this->_query->getCollate()
);
}
}
\ No newline at end of file
...@@ -57,6 +57,19 @@ class Solarium_QueryTest extends PHPUnit_Framework_TestCase ...@@ -57,6 +57,19 @@ class Solarium_QueryTest extends PHPUnit_Framework_TestCase
); );
} }
public function testAddAndGetParams()
{
$query = new TestQuery;
$query->addParam('p1','v1');
$query->addParam('p2','v2');
$query->addParam('p2','v3'); //should overwrite previous value
$this->assertEquals(
array('p1' => 'v1', 'p2' => 'v3'),
$query->getParams()
);
}
} }
class TestQuery extends Solarium_Query class TestQuery extends Solarium_Query
......
<?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_Suggester_TermTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Suggester_Term
*/
protected $_result;
/**
* @var int
*/
protected $_numFound;
/**
* @var int
*/
protected $_startOffset;
/**
* @var int
*/
protected $_endOffset;
/**
* @var array
*/
protected $_suggestions;
public function setUp()
{
$this->_numFound = 5;
$this->_startOffset = 2;
$this->_endOffset = 6;
$this->_suggestions = array(
'suggestion1',
'suggestion2',
);
$this->_result = new Solarium_Result_Suggester_Term(
$this->_numFound, $this->_startOffset, $this->_endOffset, $this->_suggestions
);
}
public function testGetNumFound()
{
$this->assertEquals(
$this->_numFound,
$this->_result->getNumFound()
);
}
public function testGetStartOffset()
{
$this->assertEquals(
$this->_startOffset,
$this->_result->getStartOffset()
);
}
public function testGetEndOffset()
{
$this->assertEquals(
$this->_endOffset,
$this->_result->getEndOffset()
);
}
public function testGetSuggestions()
{
$this->assertEquals(
$this->_suggestions,
$this->_result->getSuggestions()
);
}
public function testCount()
{
$this->assertEquals(count($this->_suggestions), count($this->_result));
}
public function testIterator()
{
$results = array();
foreach($this->_result AS $key => $doc)
{
$results[$key] = $doc;
}
$this->assertEquals($this->_suggestions, $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.
*/
class Solarium_Result_SuggesterTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Suggester
*/
protected $_result;
/**
* @var array
*/
protected $_data;
/**
* @var string
*/
protected $_collation;
public function setUp()
{
$this->_data = array(
'term1' => 'data1',
'term2' => 'data2',
);
$this->_collation = 'collation result';
$this->_result = new Solarium_Result_SuggesterDummy($this->_data, $this->_collation);
}
public function testGetStatus()
{
$this->assertEquals(
1,
$this->_result->getStatus()
);
}
public function testGetQueryTime()
{
$this->assertEquals(
12,
$this->_result->getQueryTime()
);
}
public function testGetResults()
{
$this->assertEquals($this->_data, $this->_result->getResults());
}
public function testGetTerm()
{
$this->assertEquals($this->_data['term1'], $this->_result->getTerm('term1'));
}
public function testGetTermsWithInvalidFieldName()
{
$this->assertEquals(array(), $this->_result->getTerm('term3'));
}
public function testCount()
{
$this->assertEquals(count($this->_data), count($this->_result));
}
public function testIterator()
{
$results = array();
foreach($this->_result AS $key => $doc)
{
$results[$key] = $doc;
}
$this->assertEquals($this->_data, $results);
}
public function testGetCollation()
{
$this->assertEquals($this->_collation, $this->_result->getCollation());
}
}
class Solarium_Result_SuggesterDummy extends Solarium_Result_Suggester
{
protected $_parsed = true;
public function __construct($results, $collation)
{
$this->_results = $results;
$this->_collation = $collation;
$this->_status = 1;
$this->_queryTime = 12;
}
}
\ 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