Commit 4dcfb999 authored by Bas de Nooijer's avatar Bas de Nooijer

Added extract example, first working version. Still needs more work though

parent fb830050
<?php
require(__DIR__.'/init.php');
htmlHeader();
// create a client instance
$client = new Solarium\Client($config);
$client->setAdapter('Solarium\Core\Client\Adapter\ZendHttp');
// get an extract query instance and add settings
$query = $client->createExtract();
$query->addFieldMapping('content', 'text');
$query->setUprefix('attr_');
$query->setFile(__DIR__.'/index.html');
$query->setCommit(true);
$query->setOmitHeader(false);
// add document
$doc = $query->createDocument();
$doc->id = time();
$doc->some = 'more fields';
$query->setDocument($doc);
// this executes the query and returns the result
$result = $client->extract($query);
echo '<b>Extract query executed</b><br/>';
echo 'Query status: ' . $result->getStatus(). '<br/>';
echo 'Query time: ' . $result->getQueryTime();
htmlFooter();
\ No newline at end of file
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
<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> <li><a href="2.6-suggester-query.php">2.6 Suggester query</a></li>
<li><a href="2.7-extract-query.php">2.7 Extract query</a></li>
</ul> </ul>
<li>4. Usage modes</li> <li>4. Usage modes</li>
......
...@@ -178,7 +178,6 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -178,7 +178,6 @@ class ZendHttp extends Configurable implements AdapterInterface
break; break;
case Request::METHOD_POST: case Request::METHOD_POST:
$client->setMethod(\Zend_Http_Client::POST); $client->setMethod(\Zend_Http_Client::POST);
if ($request->getFileUpload()) { if ($request->getFileUpload()) {
$this->prepareFileUpload($client, $request); $this->prepareFileUpload($client, $request);
} else { } else {
......
...@@ -1088,6 +1088,6 @@ class Client extends Configurable ...@@ -1088,6 +1088,6 @@ class Client extends Configurable
*/ */
public function createExtract($options = null) public function createExtract($options = null)
{ {
return $this->createExtract(self::QUERY_EXTRACT, $options); return $this->createQuery(self::QUERY_EXTRACT, $options);
} }
} }
...@@ -66,9 +66,10 @@ class Query extends BaseQuery ...@@ -66,9 +66,10 @@ class Query extends BaseQuery
* *
* @var array * @var array
*/ */
protected $_options = array( protected $options = array(
'handler' => 'update/extract', 'handler' => 'update/extract',
'resultclass' => 'Solarium\QueryType\Extract\Result', 'resultclass' => 'Solarium\QueryType\Extract\Result',
'documentclass' => 'Solarium\QueryType\Update\Query\Document',
'omitheader' => true, 'omitheader' => true,
); );
...@@ -117,10 +118,10 @@ class Query extends BaseQuery ...@@ -117,10 +118,10 @@ class Query extends BaseQuery
* *
* @return void * @return void
*/ */
protected function _init() protected function init()
{ {
if (isset($this->_options['fmap'])) { if (isset($this->options['fmap'])) {
$this->setFieldMappings($this->_options['fmap']); $this->setFieldMappings($this->options['fmap']);
} }
} }
...@@ -358,4 +359,46 @@ class Query extends BaseQuery ...@@ -358,4 +359,46 @@ class Query extends BaseQuery
return $this; return $this;
} }
/**
* Set a custom document class for use in the createDocument method
*
* This class should implement the document interface
*
* @param string $value classname
* @return self Provides fluent interface
*/
public function setDocumentClass($value)
{
return $this->setOption('documentclass', $value);
}
/**
* Get the current documentclass option
*
* The value is a classname, not an instance
*
* @return string
*/
public function getDocumentClass()
{
return $this->getOption('documentclass');
}
/**
* Create a document object instance
*
* You can optionally directly supply the fields and boosts
* to get a ready-made document instance for direct use in an add command
*
* @param array $fields
* @param array $boosts
* @return Document
*/
public function createDocument($fields = array(), $boosts = array())
{
$class = $this->getDocumentClass();
return new $class($fields, $boosts);
}
} }
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