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

Fixes in examples and enabled header info for update queries by default

parent 72173059
...@@ -7,7 +7,7 @@ htmlHeader(); ...@@ -7,7 +7,7 @@ htmlHeader();
$client = new Solarium\Client($config); $client = new Solarium\Client($config);
// get a select query instance // get a select query instance
$query = $client->createQuery($client::QUERY_SELECT, array('responsewriter' => 'phps')); $query = $client->createQuery($client::QUERY_SELECT);
// this executes the query and returns the result // this executes the query and returns the result
$resultset = $client->execute($query); $resultset = $client->execute($query);
......
<?php <?php
require(__DIR__.'/init.php'); require(__DIR__.'/init.php');
use Solarium\QueryType\Select\Query\Query as Select;
htmlHeader(); htmlHeader();
...@@ -21,7 +20,7 @@ $query->setStart(2)->setRows(20); ...@@ -21,7 +20,7 @@ $query->setStart(2)->setRows(20);
$query->setFields(array('id','name','price')); $query->setFields(array('id','name','price'));
// sort the results by price ascending // sort the results by price ascending
$query->addSort('price', Select::SORT_ASC); $query->addSort('price', $query::SORT_ASC);
// this executes the query and returns the result // this executes the query and returns the result
$resultset = $client->select($query); $resultset = $client->select($query);
......
...@@ -13,8 +13,10 @@ $client = new Client($config); ...@@ -13,8 +13,10 @@ $client = new Client($config);
// first create a base query as a query class // first create a base query as a query class
class PriceQuery extends Select class PriceQuery extends Select
{ {
protected function _init() protected function init()
{ {
parent::init();
// set a query (all prices starting from 12) // set a query (all prices starting from 12)
$this->setQuery('price:[12 TO *]'); $this->setQuery('price:[12 TO *]');
...@@ -40,10 +42,10 @@ if(isset($_GET['start']) && is_numeric($_GET['start'])){ ...@@ -40,10 +42,10 @@ if(isset($_GET['start']) && is_numeric($_GET['start'])){
// in this example this class isn't actually used, but you can simple replace // in this example this class isn't actually used, but you can simple replace
// the var $query with an instance of this class... // the var $query with an instance of this class...
class LowerPriceQuery extends PriceQuery{ class LowerPriceQuery extends PriceQuery{
protected function _init() protected function init()
{ {
// this call makes sure we get all the settings of the parent class // this call makes sure we get all the settings of the parent class
parent::_init(); parent::init();
$this->setQuery('price:[5 TO *]'); $this->setQuery('price:[5 TO *]');
} }
......
<?php <?php
require(__DIR__.'/init.php'); require(__DIR__.'/init.php');
use Solarium\QueryType\Select\Query\Query as Select;
htmlHeader(); htmlHeader();
...@@ -15,7 +14,7 @@ $query = $client->createSelect(); ...@@ -15,7 +14,7 @@ $query = $client->createSelect();
$query->setQuery('*:*'); $query->setQuery('*:*');
$query->setStart(2)->setRows(20); $query->setStart(2)->setRows(20);
$query->setFields(array('id','name','price')); $query->setFields(array('id','name','price'));
$query->addSort('price', Select::SORT_ASC); $query->addSort('price', $query::SORT_ASC);
// create a filterquery using the API // create a filterquery using the API
$fq = $query->createFilterQuery('maxprice')->setQuery('price:[1 TO 300]'); $fq = $query->createFilterQuery('maxprice')->setQuery('price:[1 TO 300]');
......
...@@ -27,13 +27,13 @@ class ProductQuery extends Select{ ...@@ -27,13 +27,13 @@ class ProductQuery extends Select{
} }
// This query inherits all of the query params of its parent (using parent::_init) and adds some more // This query inherits all of the query params of its parent (using parent::init) and adds some more
// Ofcourse it could also alter or remove settings // Ofcourse it could also alter or remove settings
class ProductPriceLimitedQuery extends ProductQuery{ class ProductPriceLimitedQuery extends ProductQuery{
protected function _init() protected function init()
{ {
parent::_init(); parent::init();
// create a filterquery // create a filterquery
$this->createFilterQuery('maxprice')->setQuery('price:[1 TO 300]'); $this->createFilterQuery('maxprice')->setQuery('price:[1 TO 300]');
......
...@@ -10,6 +10,8 @@ htmlHeader(); ...@@ -10,6 +10,8 @@ htmlHeader();
$client = new Solarium\Client($config); $client = new Solarium\Client($config);
// set the adapter to curl // set the adapter to curl
// note that this is only shown for documentation purposes, normally you don't need
// to do this as curl is the default adapter
$client->setAdapter('Solarium\Core\Client\Adapter\Curl'); $client->setAdapter('Solarium\Core\Client\Adapter\Curl');
// get a select query instance // get a select query instance
......
<?php
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
require(__DIR__.'/init.php');
htmlHeader();
// create a client instance
$client = new Solarium\Client($config);
// set the adapter to curl
$client->setAdapter('Solarium\Core\Client\Adapter\Http');
// get a select query instance
$query = $client->createSelect();
// this executes the query and returns the result
$resultset = $client->select($query);
// display the total number of documents found by solr
echo 'NumFound: '.$resultset->getNumFound();
// show documents using the resultset iterator
foreach ($resultset as $document) {
echo '<hr/><table>';
// the documents are also iterable, to get all fields
foreach($document AS $field => $value)
{
// this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}
echo '</table>';
}
htmlFooter();
\ No newline at end of file
...@@ -113,6 +113,7 @@ ...@@ -113,6 +113,7 @@
<li><a href="6.1.1-zend-http-adapter.php">6.1.1 Zend_Http adapter</a></li> <li><a href="6.1.1-zend-http-adapter.php">6.1.1 Zend_Http adapter</a></li>
<li><a href="6.1.2-pecl-http-adapter.php">6.1.2 Pecl_Http adapter</a></li> <li><a href="6.1.2-pecl-http-adapter.php">6.1.2 Pecl_Http adapter</a></li>
<li><a href="6.1.3-curl-adapter.php">6.1.3 Curl adapter</a></li> <li><a href="6.1.3-curl-adapter.php">6.1.3 Curl adapter</a></li>
<li><a href="6.1.4-http-adapter.php">6.1.4 Http adapter (PHP stream)</a></li>
</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>
......
...@@ -107,7 +107,7 @@ class Query extends BaseQuery ...@@ -107,7 +107,7 @@ class Query extends BaseQuery
'handler' => 'update', 'handler' => 'update',
'resultclass' => 'Solarium\QueryType\Update\Result', 'resultclass' => 'Solarium\QueryType\Update\Result',
'documentclass' => 'Solarium\QueryType\Update\Query\Document', 'documentclass' => 'Solarium\QueryType\Update\Query\Document',
'omitheader' => true, 'omitheader' => false,
); );
/** /**
......
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