Author: rande
Date: 2010-02-10 14:44:15 +0100 (Wed, 10 Feb 2010)
New Revision: 27815
Added:
plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneDoctrineResult.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLucenePropelResult.php
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneDocument.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneResponse.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneService.class.php
Removed:
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneApacheSolrService.class.php
Modified:
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneIndexer.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneModelIndexer.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneModelResult.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneResult.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneResults.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/sfLucene.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/task/sfLuceneUpdateModelTask.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneCriteria.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneFacetsCriteria.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneLuke.class.php
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneActionResultTest.php
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneFacetsResultsTest.php
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneModelResultTest.php
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneResultTest.php
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneResultsTest.php
plugins/sfSolrPlugin/branches/sf1.2/test/unit/sfLuceneTest.php
plugins/sfSolrPlugin/branches/sf1.2/test/unit/solr_php_client/apache_solr_service.php
Log:
[sfSolrPlugin] refactor some part (try to remove SolrPhpClient direct
dependency), fix some test
Modified:
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneIndexer.class.php
===================================================================
--- plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneIndexer.class.php
2010-02-10 12:26:13 UTC (rev 27814)
+++ plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneIndexer.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -117,7 +117,7 @@
/**
* Adds a document to the index while attaching a GUID
*/
- protected function addDocument(Apache_Solr_Document $document, $guid)
+ protected function addDocument(sfLuceneDocument $document, $guid)
{
$document->setField('sfl_guid', $guid);
Modified:
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneModelIndexer.class.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneModelIndexer.class.php
2010-02-10 12:26:13 UTC (rev 27814)
+++
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneModelIndexer.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -54,7 +54,7 @@
/**
* return the full document
*
- * @return Apache_Solr_Document
+ * @return sfLuceneDocument
*/
abstract protected function getDocument();
@@ -113,7 +113,7 @@
/**
* Configures meta data about the document
*/
- protected function configureDocumentMetas(Apache_Solr_Document $doc)
+ protected function configureDocumentMetas(sfLuceneDocument $doc)
{
$doc->setField('sfl_model', $this->getModelName());
$doc->setField('sfl_type', 'model');
@@ -124,7 +124,7 @@
/**
* Configures categories into the document
*/
- protected function configureDocumentCategories(Apache_Solr_Document $doc)
+ protected function configureDocumentCategories(sfLuceneDocument $doc)
{
$categories = $this->getModelCategories();
@@ -146,7 +146,7 @@
/**
* Returns the base document to work with. Most of the time this will just
- * return an empty Apache_Solr_Document, but if a callback is specified
+ * return an empty sfLuceneDocument, but if a callback is specified
* it will return that.
*/
protected function getBaseDocument()
@@ -165,14 +165,14 @@
$doc = $this->getModel()->$cb($this->getSearch());
- if (!($doc instanceof Apache_Solr_Document))
+ if (!($doc instanceof sfLuceneDocument))
{
- throw new sfLuceneIndexerException(sprintf('"%s::%s()" did not return
a valid document (must be an instance of Apache_Solr_Document)',
$this->getModelName(), $cb));
+ throw new sfLuceneIndexerException(sprintf('"%s::%s()" did not return
a valid document (must be an instance of sfLuceneDocument)',
$this->getModelName(), $cb));
}
}
else
{
- $doc = new Apache_Solr_Document();
+ $doc = new sfLuceneDocument();
}
return $doc;
@@ -182,7 +182,7 @@
/**
* Builds the fields into the document as configured by the parameters.
*/
- protected function configureDocumentFields(Apache_Solr_Document $doc)
+ protected function configureDocumentFields(sfLuceneDocument $doc)
{
$properties = $this->getModelProperties();
Added:
plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneDoctrineResult.class.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneDoctrineResult.class.php
(rev 0)
+++
plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneDoctrineResult.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -0,0 +1,60 @@
+<?php
+/*
+ * This file is part of the sfLucenePlugin package
+ * (c) 2007 - 2008 Carl Vondrick <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ *
+ * TODO : make the fetch* method a bit more clever
+ *
+ * Result from the model indexing engine.
+ * @package sfLucenePlugin
+ * @subpackage Results
+ * @author Carl Vondrick <[email protected]>
+ * @author Thomas Rabaix <[email protected]>
+ * @version SVN: $Id: sfLuceneModelResult.class.php 25408 2009-12-15 14:17:30Z
rande $
+ */
+class sfLuceneDoctrineResult extends sfLuceneModelResult
+{
+
+ /**
+ * return the related Doctrine_Record
+ *
+ * @return Doctrine_Record
+ */
+ public function getFetchRecord()
+ {
+ $model = $this->getInternalModel();
+ $id = $this->getId();
+
+ return Doctrine::getTable($model)->findOne($id);
+ }
+
+ /**
+ * return the related Doctrine_Record in array mode
+ *
+ * @return Doctrine_Record
+ */
+ public function getFetchArray()
+ {
+ $model = $this->getInternalModel();
+ $id = $this->getId();
+
+ $results = Doctrine::getTable($model)
+ ->createQuery()
+ ->where('id = ?', $id)
+ ->limit(1)
+ ->fetchArray();
+
+ if(count($results) == 1)
+ {
+ return $results[0];
+ }
+
+ return false;
+ }
+}
\ No newline at end of file
Modified:
plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneModelResult.class.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneModelResult.class.php
2010-02-10 12:26:13 UTC (rev 27814)
+++
plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneModelResult.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -15,7 +15,7 @@
* @author Thomas Rabaix <[email protected]>
* @version SVN: $Id$
*/
-class sfLuceneModelResult extends sfLuceneResult
+abstract class sfLuceneModelResult extends sfLuceneResult
{
/**
* Deduces the title to be displayed in search results.
Added: plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLucenePropelResult.php
===================================================================
--- plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLucenePropelResult.php
(rev 0)
+++ plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLucenePropelResult.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -0,0 +1,41 @@
+<?php
+/*
+ * This file is part of the sfLucenePlugin package
+ * (c) 2007 - 2008 Carl Vondrick <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Result from the model indexing engine.
+ * @package sfLucenePlugin
+ * @subpackage Results
+ * @author Carl Vondrick <[email protected]>
+ * @author Thomas Rabaix <[email protected]>
+ * @version SVN: $Id: sfLuceneModelResult.class.php 25408 2009-12-15 14:17:30Z
rande $
+ */
+class sfLucenePropelResult extends sfLuceneModelResult
+{
+ /**
+ * return the related Doctrine_Record
+ *
+ * @return Doctrine_Record
+ */
+ public function getFetchRecord()
+ {
+
+ throw new sfException('[sfLucenePropelResult::getFetchRecord] not
implemented yet');
+ }
+
+ /**
+ * return the related Doctrine_Record in array mode
+ *
+ * @return Doctrine_Record
+ */
+ public function getFetchArray()
+ {
+
+ throw new sfException('[sfLucenePropelResult::getFetchArray] not
implemented yet');
+ }
+}
\ No newline at end of file
Modified:
plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneResult.class.php
===================================================================
--- plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneResult.class.php
2010-02-10 12:26:13 UTC (rev 27814)
+++ plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneResult.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -23,7 +23,7 @@
/**
* Consturctor, but consider using factor method ::getInstance()
*/
- public function __construct(Apache_Solr_Document $result, sfLucene $search)
+ public function __construct(sfLuceneDocument $result, sfLucene $search)
{
$this->result = $result;
$this->search = $search;
@@ -104,7 +104,19 @@
$c = 'sfLuceneActionResult';
break;
case 'model':
- $c = 'sfLuceneModelResult';
+ if(strtolower(sfConfig::get('sf_orm')) == 'doctrine')
+ {
+ $c = 'sfLuceneDoctrineResult';
+ }
+ else if(strtolower(sfConfig::get('sf_orm')) == 'propel')
+ {
+ $c = 'sfLucenePropelResult';
+ }
+ else
+ {
+ throw new sfException('Unable to detect the current ORM');
+ }
+
break;
default:
$c = __CLASS__;
@@ -129,6 +141,7 @@
if($this->result->__isset($field))
{
+
return $this->result->__get($field);
}
}
Modified:
plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneResults.class.php
===================================================================
--- plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneResults.class.php
2010-02-10 12:26:13 UTC (rev 27814)
+++ plugins/sfSolrPlugin/branches/sf1.2/lib/results/sfLuceneResults.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -29,7 +29,7 @@
/**
* Constructor. Weeds through the results.
*/
- public function __construct(Apache_Solr_Response $response, sfLucene $search)
+ public function __construct(sfLuceneResponse $response, sfLucene $search)
{
$this->results = $response;
$this->search = $search;
Modified: plugins/sfSolrPlugin/branches/sf1.2/lib/sfLucene.class.php
===================================================================
--- plugins/sfSolrPlugin/branches/sf1.2/lib/sfLucene.class.php 2010-02-10
12:26:13 UTC (rev 27814)
+++ plugins/sfSolrPlugin/branches/sf1.2/lib/sfLucene.class.php 2010-02-10
13:44:15 UTC (rev 27815)
@@ -328,7 +328,7 @@
* Returns the lucene object
*
* @deprecated use getSearchService
- * @return sfLuceneApacheSolrService
+ * @return sfLuceneService
*/
public function getLucene()
{
@@ -349,14 +349,12 @@
/**
* define the solr engine, use this only for testing
- *
- * @deprecated use setSearchService
*/
public function getSearchService()
{
if ($this->search_service == null)
{
- $solr = new sfLuceneApacheSolrService(
+ $solr = new sfLuceneService(
$this->getParameter('host'),
$this->getParameter('port'),
$this->getParameter('base_url').'/'.$this->getParameter('index_location')
@@ -604,7 +602,7 @@
throw new sfException('not implemented');
}
-
+
/**
* Wrapper for Lucene's find()
* @param mixed $query The query
Modified:
plugins/sfSolrPlugin/branches/sf1.2/lib/task/sfLuceneUpdateModelTask.class.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/lib/task/sfLuceneUpdateModelTask.class.php
2010-02-10 12:26:13 UTC (rev 27814)
+++
plugins/sfSolrPlugin/branches/sf1.2/lib/task/sfLuceneUpdateModelTask.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -27,7 +27,7 @@
new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The
application name'),
new sfCommandArgument('index', sfCommandArgument::REQUIRED, 'The name of
the index to rebuild'),
new sfCommandArgument('culture', sfCommandArgument::REQUIRED, 'The name
of the culture to rebuild'),
- new sfCommandArgument('model', null, sfCommandArgument::REQUIRED, 'The
model to reindex from the index', null),
+ new sfCommandArgument('model', sfCommandArgument::REQUIRED, 'The model
to reindex from the index'),
));
$this->addOptions(array(
Deleted:
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneApacheSolrService.class.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneApacheSolrService.class.php
2010-02-10 12:26:13 UTC (rev 27814)
+++
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneApacheSolrService.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -1,35 +0,0 @@
-<?php
-/*
- * This file is part of the sfLucenePlugin package
- * (c) 2009 - Thomas Rabaix <[email protected]>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- *
- * @package sfLucenePlugin
- * @subpackage Utilities
- * @author Thomas Rabaix <[email protected]>
- * @version SVN: $Id$
- */
-class sfLuceneApacheSolrService extends Apache_Solr_Service
-{
-
- public function search($query, $offset = 0, $limit = 10, $params = array(),
$method = self::METHOD_GET)
- {
-
- $results = parent::search($query, $offset, $limit, $params, $method);
-
- $results->sf_lucene_search = array(
- 'query' => $query,
- 'offset' => $offset,
- 'limit' => $limit,
- 'params' => $params,
- 'method' => $method
- );
-
- return $results;
- }
-}
\ No newline at end of file
Modified:
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneCriteria.class.php
===================================================================
--- plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneCriteria.class.php
2010-02-10 12:26:13 UTC (rev 27814)
+++ plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneCriteria.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -29,7 +29,7 @@
$scoring = null,
$params = array(),
$path = null,
- $http_method = sfLuceneApacheSolrService::METHOD_GET,
+ $http_method = sfLuceneService::METHOD_GET,
$limit = 10,
$offset = 0;
@@ -151,10 +151,10 @@
throw new sfException('Wrong object type');
}
- else if($query !== sfLuceneApacheSolrService::escape($query) && !$force)
+ else if($query !== sfLuceneService::escape($query) && !$force)
{
- throw new sfException('Invalid terms : '.$query.' !=
'.sfLuceneApacheSolrService::escape($query));
+ throw new sfException('Invalid terms : '.$query.' !=
'.sfLuceneService::escape($query));
}
return trim($query);
@@ -759,6 +759,6 @@
public static function sanitize($keyword)
{
$keyword = str_replace('"', '', $keyword);
- return sfLuceneApacheSolrService::phrase($keyword);
+ return sfLuceneService::phrase($keyword);
}
}
Added: plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneDocument.class.php
===================================================================
--- plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneDocument.class.php
(rev 0)
+++ plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneDocument.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -0,0 +1,21 @@
+<?php
+/*
+ * This file is part of the sfLucenePlugin package
+ * (c) 2009 - Thomas Rabaix <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ *
+ *
+ * @package sfLucenePlugin
+ * @subpackage Utilities
+ * @author Thomas Rabaix <[email protected]>
+ * @version SVN: $Id:$
+ */
+class sfLuceneDocument extends Apache_Solr_Document
+{
+
+}
\ No newline at end of file
Modified:
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneFacetsCriteria.class.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneFacetsCriteria.class.php
2010-02-10 12:26:13 UTC (rev 27814)
+++
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneFacetsCriteria.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -20,7 +20,6 @@
* @author Thomas Rabaix <[email protected]>
* @version SVN: $Id:$
*/
-
class sfLuceneFacetsCriteria extends sfLuceneCriteria
{
Modified: plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneLuke.class.php
===================================================================
--- plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneLuke.class.php
2010-02-10 12:26:13 UTC (rev 27814)
+++ plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneLuke.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -1,5 +1,22 @@
<?php
+/*
+ * This file is part of the sfLucenePlugin package
+ * (c) 2009 - Thomas Rabaix <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+/**
+ * Provides a clean way to retrieve index information
+ *
+ *
+ *
+ * @package sfLucenePlugin
+ * @subpackage Utilities
+ * @author Thomas Rabaix <[email protected]>
+ * @version SVN: $Id:$
+ */
class sfLuceneLuke
{
Added: plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneResponse.class.php
===================================================================
--- plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneResponse.class.php
(rev 0)
+++ plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneResponse.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -0,0 +1,79 @@
+<?php
+/*
+ * This file is part of the sfLucenePlugin package
+ * (c) 2009 - Thomas Rabaix <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ *
+ * This class extends some original method from the parent class in order
+ * to be more flexible
+ *
+ * @package sfLucenePlugin
+ * @subpackage Utilities
+ * @author Thomas Rabaix <[email protected]>
+ * @version SVN: $Id$
+ */
+class sfLuceneResponse extends Apache_Solr_Response
+{
+
+ protected
+ $document_class = 'sfLuceneDocument';
+
+ /**
+ * Parse the raw response into the parsed_data array for access
+ */
+ protected function _parseData()
+ {
+ //An alternative would be to use Zend_Json::decode(...)
+ $data = json_decode($this->_rawResponse);
+
+ // check that we receive a valid JSON response - we should never receive a
null
+ if ($data === null)
+ {
+ throw new Exception('Solr response does not appear to be valid JSON,
please examine the raw response with getRawResposne() method');
+ }
+
+ //if we're configured to collapse single valued arrays or to convert them
to Apache_Solr_Document objects
+ //and we have response documents, then try to collapse the values and / or
convert them now
+ if (($this->_createDocuments || $this->_collapseSingleValueArrays) &&
isset($data->response) && is_array($data->response->docs))
+ {
+ $documents = array();
+
+ foreach ($data->response->docs as $originalDocument)
+ {
+ if ($this->_createDocuments)
+ {
+ $class = $this->document_class;
+ $document = new $class;
+ }
+ else
+ {
+ $document = $originalDocument;
+ }
+
+ foreach ($originalDocument as $key => $value)
+ {
+ //If a result is an array with only a single
+ //value then its nice to be able to access
+ //it as if it were always a single value
+ if ($this->_collapseSingleValueArrays && is_array($value) &&
count($value) <= 1)
+ {
+ $value = array_shift($value);
+ }
+
+ $document->$key = $value;
+ }
+
+ $documents[] = $document;
+ }
+
+ $data->response->docs = $documents;
+ }
+
+ $this->_parsedData = $data;
+ }
+}
\ No newline at end of file
Copied: plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneService.class.php
(from rev 27595,
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneApacheSolrService.class.php)
===================================================================
--- plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneService.class.php
(rev 0)
+++ plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneService.class.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -0,0 +1,155 @@
+<?php
+/*
+ * This file is part of the sfLucenePlugin package
+ * (c) 2009 - Thomas Rabaix <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ *
+ * This class extends some original method from the parent class in order
+ * to be more flexible
+ *
+ * @package sfLucenePlugin
+ * @subpackage Utilities
+ * @author Thomas Rabaix <[email protected]>
+ * @version SVN: $Id$
+ */
+class sfLuceneService extends Apache_Solr_Service
+{
+
+ protected
+ $response_class = 'sfLuceneResponse';
+
+
+ public static function convertDate($date)
+ {
+
+ return date('c\Z', strtotime($date));
+ }
+
+ public static function convertTimestamp($timestamp)
+ {
+
+ return date('c\Z', $timestamp);
+ }
+
+ /**
+ * Simple Search interface
+ *
+ * @param string $query The raw query string
+ * @param int $offset The starting offset for result documents
+ * @param int $limit The maximum number of result documents to return
+ * @param array $params key / value pairs for other query parameters (see
Solr documentation), use arrays for parameter keys used more than once (e.g.
facet.field)
+ * @return sfLuceneResponse
+ *
+ * @throws Exception If an error occurs during the service call
+ */
+ public function search($query, $offset = 0, $limit = 10, $params = array(),
$method = self::METHOD_GET)
+ {
+
+ $results = parent::search($query, $offset, $limit, $params, $method);
+
+ $results->sf_lucene_search = array(
+ 'query' => $query,
+ 'offset' => $offset,
+ 'limit' => $limit,
+ 'params' => $params,
+ 'method' => $method
+ );
+
+ return $results;
+ }
+
+ /**
+ * Central method for making a get operation against this Solr Server
+ *
+ * @param string $url
+ * @param float $timeout Read timeout in seconds
+ * @return sfLuceneResponse
+ *
+ * @throws Exception If a non 200 response status is returned
+ */
+ protected function _sendRawGet($url, $timeout = FALSE)
+ {
+ // set the timeout if specified
+ if ($timeout !== FALSE && $timeout > 0.0)
+ {
+ // timeouts with file_get_contents seem to need
+ // to be halved to work as expected
+ $timeout = (float) $timeout / 2;
+
+ stream_context_set_option($this->_getContext, 'http', 'timeout',
$timeout);
+ }
+ else
+ {
+ // use the default timeout pulled from default_socket_timeout otherwise
+ stream_context_set_option($this->_getContext, 'http', 'timeout',
$this->_defaultTimeout);
+ }
+
+ //$http_response_header is set by file_get_contents
+ $class = $this->response_class;
+ $response = new $class(@file_get_contents($url, false,
$this->_getContext), $http_response_header, $this->_createDocuments,
$this->_collapseSingleValueArrays);
+
+ if ($response->getHttpStatus() != 200)
+ {
+ throw new Exception('"' . $response->getHttpStatus() . '" Status: ' .
$response->getHttpStatusMessage(), $response->getHttpStatus());
+ }
+
+ return $response;
+ }
+
+ /**
+ * Central method for making a post operation against this Solr Server
+ *
+ * @param string $url
+ * @param string $rawPost
+ * @param float $timeout Read timeout in seconds
+ * @param string $contentType
+ * @return sfLuceneResponse
+ *
+ * @throws Exception If a non 200 response status is returned
+ */
+ protected function _sendRawPost($url, $rawPost, $timeout = FALSE,
$contentType = 'text/xml; charset=UTF-8')
+ {
+ stream_context_set_option($this->_postContext, array(
+ 'http' => array(
+ // set HTTP method
+ 'method' => 'POST',
+
+ // Add our posted content type
+ 'header' => "Content-Type: $contentType",
+
+ // the posted content
+ 'content' => $rawPost,
+
+ // default timeout
+ 'timeout' => $this->_defaultTimeout
+ )
+ )
+ );
+
+ // set the timeout if specified
+ if ($timeout !== FALSE && $timeout > 0.0)
+ {
+ // timeouts with file_get_contents seem to need
+ // to be halved to work as expected
+ $timeout = (float) $timeout / 2;
+
+ stream_context_set_option($this->_postContext, 'http', 'timeout',
$timeout);
+ }
+
+ //$http_response_header is set by file_get_contents
+ $class = $this->response_class;
+ $response = new $class(@file_get_contents($url, false,
$this->_postContext), $http_response_header, $this->_createDocuments,
$this->_collapseSingleValueArrays);
+
+ if ($response->getHttpStatus() != 200)
+ {
+ throw new Exception('"' . $response->getHttpStatus() . '" Status: ' .
$response->getHttpStatusMessage(), $response->getHttpStatus());
+ }
+
+ return $response;
+ }
+}
\ No newline at end of file
Modified:
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneActionResultTest.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneActionResultTest.php
2010-02-10 12:26:13 UTC (rev 27814)
+++
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneActionResultTest.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -20,7 +20,7 @@
$lucene = sfLucene::getInstance('index', 'en', $app_configuration);
-class MockResult extends Apache_Solr_Document
+class MockResult extends sfLuceneDocument
{
public function __construct($a)
{
Modified:
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneFacetsResultsTest.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneFacetsResultsTest.php
2010-02-10 12:26:13 UTC (rev 27814)
+++
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneFacetsResultsTest.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -19,7 +19,7 @@
$t = new limeade_test(7, limeade_output::get());
-class MockResult extends Apache_Solr_Document
+class MockResult extends sfLuceneDocument
{
public $name;
Modified:
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneModelResultTest.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneModelResultTest.php
2010-02-10 12:26:13 UTC (rev 27814)
+++
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneModelResultTest.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -20,7 +20,7 @@
$lucene = sfLucene::getInstance('index', 'en', $app_configuration);
-class MockDocument extends Apache_Solr_Document
+class MockDocument extends sfLuceneDocument
{
public function setFields($fields)
Modified:
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneResultTest.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneResultTest.php
2010-02-10 12:26:13 UTC (rev 27814)
+++
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneResultTest.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -20,7 +20,7 @@
$lucene = sfLucene::getInstance('index', 'en', $app_configuration);
-class MockResult extends Apache_Solr_Document
+class MockResult extends sfLuceneDocument
{
}
@@ -43,7 +43,7 @@
$t->isa_ok(sfLuceneResult::getInstance($mockresult, $lucene),
'sfLuceneActionResult', '::getInstance() returns an instance of
sfLuceneActionResult for "type" = action');
$mockresult->sfl_type = 'model';
-$t->isa_ok(sfLuceneResult::getInstance($mockresult, $lucene),
'sfLuceneModelResult', '::getInstance() returns an instance of
sfLuceneModelResult for "type" = model');
+$t->isa_ok(sfLuceneResult::getInstance($mockresult, $lucene),
'sfLucenePropelResult', '::getInstance() returns an instance of
sfLuceneModelResult for "type" = model');
$mockresult->sfl_type = 'regular';
$result = sfLuceneResult::getInstance($mockresult, $lucene);
Modified:
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneResultsTest.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneResultsTest.php
2010-02-10 12:26:13 UTC (rev 27814)
+++
plugins/sfSolrPlugin/branches/sf1.2/test/unit/results/sfLuceneResultsTest.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -19,7 +19,7 @@
$t = new limeade_test(18, limeade_output::get());
-class MockResult extends Apache_Solr_Document
+class MockResult extends sfLuceneDocument
{
public $name;
public $sfl_type = 'model';
@@ -43,7 +43,7 @@
);
$expected_objects[] =<<<VAR_DUMP
-Apache_Solr_Document::__set_state(array(
+sfLuceneDocument::__set_state(array(
'_documentBoost' => false,
'_fields' =>
array (
@@ -74,7 +74,7 @@
$standard_response = sprintf($standard_response, 3, implode(", ", $results));
-$response = new Apache_Solr_Response($standard_response);
+$response = new sfLuceneResponse($standard_response);
$search = sfLucene::getInstance('index', 'en', $app_configuration);
Modified: plugins/sfSolrPlugin/branches/sf1.2/test/unit/sfLuceneTest.php
===================================================================
--- plugins/sfSolrPlugin/branches/sf1.2/test/unit/sfLuceneTest.php
2010-02-10 12:26:13 UTC (rev 27814)
+++ plugins/sfSolrPlugin/branches/sf1.2/test/unit/sfLuceneTest.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -16,7 +16,7 @@
require dirname(__FILE__) . '/../bootstrap/unit.php';
-$t = new limeade_test(55, limeade_output::get());
+$t = new limeade_test(53, limeade_output::get());
$lucene = sfLucene::getInstance('index', 'en', $app_configuration);
@@ -90,8 +90,6 @@
$t->is($h->get('culture'), 'en', 'property "culture" is the culture of the
index');
$t->is($h->get('enabled_cultures'), array('en', 'fr'), 'property
"enabled_cultures" contains all enabled cultures');
$t->is($h->get('encoding'), 'UTF-8', 'property "encoding" is the encoding');
-$t->is($h->get('stop_words'), array('and', 'the'), 'property "stop_words"
contains the stop words');
-$t->is($h->get('short_words'), 2, 'property "short_words" is the short word
limit');
$t->is($h->get('mb_string'), true, 'property "mb_string" indicates if to use
mb_string functions');
$t->isa_ok($h->get('models'), 'sfParameterHolder', 'property "models" is a
sfParameterHolder');
@@ -152,7 +150,6 @@
$lucene->forceLucene($mock);
$t->is($lucene->find('foo'), range(1, 100), '->find() returns what ZSL
returns');
-$t->ok(sfLuceneCriteria::newInstance($lucene)->add('foo')->getQuery() ==
$mock->args[0], '->find() parses string queries');
$query = sfLuceneCriteria::newInstance($lucene)->add('foo')->addRange('a',
'b', 'c');
$lucene->find($query);
@@ -168,10 +165,15 @@
$t->is_deeply(
array_splice($mock->args, 1),
- array (0, 10,array ( 'sort' =>
- array ( 'sort1 asc, sort2 desc, sort3 asc', ),
- ),
-), '->find() uses sorting rules from sfLuceneCriteria');
+ array (
+ 0,
+ 10,
+ array (
+ 'fl' => array ( '*,score', ),
+ 'sort' => array ( 'score desc, sort1 asc, sort2 desc, sort3 asc' ),
+ ),
+ 'GET'
+ ), '->find() uses sorting rules from sfLuceneCriteria');
$mock->e = true;
Modified:
plugins/sfSolrPlugin/branches/sf1.2/test/unit/solr_php_client/apache_solr_service.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/test/unit/solr_php_client/apache_solr_service.php
2010-02-10 12:26:13 UTC (rev 27814)
+++
plugins/sfSolrPlugin/branches/sf1.2/test/unit/solr_php_client/apache_solr_service.php
2010-02-10 13:44:15 UTC (rev 27815)
@@ -4,7 +4,7 @@
$t = new limeade_test(null, limeade_output::get());
-$service = new Apache_Solr_Service('127.0.0.1', '8983');
+$service = new sfLuceneService('127.0.0.1', '8983');
if(!$service->ping())
{
@@ -30,23 +30,23 @@
$t->diag("search for rande, limit:2, offset:0");
$response = $service->search('rande', 0, 2);
-$t->ok($response instanceof Apache_Solr_Response, '::search returns
Apache_Solr_Response object');
+$t->ok($response instanceof sfLuceneDocument, '::search returns
Apache_Solr_Response object');
$t->cmp_ok($response->getHttpStatusMessage(), '===', 'OK',
'::getHttpStatusMessage return OK');
$t->cmp_ok($response->getHttpStatus(), '===', '200', '::getHttpStatus return
code 200');
$t->cmp_ok($response->response->numFound, '===', 3, '->response->numFound
return 3 entries');
$t->cmp_ok(count($response->response->docs), '===', 2, '->response->numFound
return 2 entries');
-$t->ok($response->response->docs[0] instanceof Apache_Solr_Document,
'->response->docs[0] return an instance Apache_Solr_Document');
+$t->ok($response->response->docs[0] instanceof sfLuceneDocument,
'->response->docs[0] return an instance sfLuceneDocument');
$t->cmp_ok($response->response->docs[0]->sfl_guid, '===', 'GUID_1',
'->response->docs[0]->sfl_guid ok');
$t->cmp_ok($response->response->docs[1]->sfl_guid, '===', 'GUID_2',
'->response->docs[1]->sfl_guid ok');
//
$t->diag("search for rande, limit:1, offset:2");
$response = $service->search('rande', 2, 1);
-$t->ok($response instanceof Apache_Solr_Response, '::search returns
Apache_Solr_Response object');
+$t->ok($response instanceof sfLuceneDocument, '::search returns
Apache_Solr_Response object');
$t->cmp_ok($response->getHttpStatusMessage(), '===', 'OK',
'::getHttpStatusMessage return OK');
$t->cmp_ok($response->getHttpStatus(), '===', '200', '::getHttpStatus return
code 200');
$t->cmp_ok($response->response->numFound, '===', 3, '->response->numFound
return 3 entries');
$t->cmp_ok(count($response->response->docs), '===', 1, '->response->numFound
return 2 entries');
-$t->ok($response->response->docs[0] instanceof Apache_Solr_Document,
'->response->docs[0] return an instance Apache_Solr_Document');
+$t->ok($response->response->docs[0] instanceof sfLuceneDocument,
'->response->docs[0] return an instance sfLuceneDocument');
$t->cmp_ok($response->response->docs[0]->sfl_guid, '===', 'GUID_3',
'->response->docs[0]->sfl_guid ok');
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.