forked from floriansemm/SolrBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Florian Semm
committed
Jan 30, 2012
1 parent
ecc47e0
commit 0a2caba
Showing
9 changed files
with
313 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
namespace FS\SolrBundle\Query; | ||
|
||
class FindByDocumentNameQuery extends AbstractQuery { | ||
/** | ||
* | ||
* @var \SolrInputDocument | ||
*/ | ||
private $document = null; | ||
|
||
public function __construct(\SolrInputDocument $document) { | ||
parent::__construct(); | ||
|
||
$this->document = $document; | ||
} | ||
|
||
public function getQueryString() { | ||
$documentNameField = $this->document->getField('document_name_s'); | ||
|
||
if ($documentNameField == null) { | ||
throw new \RuntimeException('documentName should not be null'); | ||
} | ||
|
||
$query = 'document_name_s:'.$documentNameField->values[0]; | ||
|
||
return $query; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
namespace FS\SolrBundle\Repository; | ||
|
||
use FS\SolrBundle\Query\FindByDocumentNameQuery; | ||
|
||
use FS\SolrBundle\Query\FindByIdentifierQuery; | ||
|
||
use FS\SolrBundle\SolrFacade; | ||
|
||
class Repository implements RepositoryInterface { | ||
|
||
/** | ||
* | ||
* @var SolrFacade | ||
*/ | ||
private $solr = null; | ||
|
||
/** | ||
* | ||
* @var object | ||
*/ | ||
private $entity = null; | ||
|
||
public function __construct(SolrFacade $solr, $entity) { | ||
$this->solr = $solr; | ||
|
||
$this->entity = $entity; | ||
} | ||
|
||
/* (non-PHPdoc) | ||
* @see FS\SolrBundle\Repository.RepositoryInterface::find() | ||
*/ | ||
public function find($id) { | ||
$this->entity->setId($id); | ||
|
||
$mapper = $this->solr->getMapper(); | ||
$mapper->setMappingCommand($this->solr->getCommandFactory()->get('all')); | ||
$document = $mapper->toDocument($this->entity); | ||
|
||
$query = new FindByIdentifierQuery($document); | ||
$query->setEntity($this->entity); | ||
$found = $this->solr->query($query); | ||
|
||
if (count($found) == 0) { | ||
return null; | ||
} | ||
|
||
return array_pop($found); | ||
} | ||
|
||
/* (non-PHPdoc) | ||
* @see FS\SolrBundle\Repository.RepositoryInterface::findAll() | ||
*/ | ||
public function findAll() { | ||
$mapper = $this->solr->getMapper(); | ||
$mapper->setMappingCommand($this->solr->getCommandFactory()->get('all')); | ||
|
||
$document = $mapper->toDocument($this->entity); | ||
|
||
if (null === $document) { | ||
return null; | ||
} | ||
|
||
$document->deleteField('id'); | ||
|
||
$query = new FindByDocumentNameQuery($document); | ||
$query->setEntity($this->entity); | ||
|
||
return $this->solr->query($query); | ||
} | ||
|
||
/* (non-PHPdoc) | ||
* @see FS\SolrBundle\Repository.RepositoryInterface::findBy() | ||
*/ | ||
public function findBy(array $args) { | ||
$query = $this->solr->createQuery($this->entity); | ||
|
||
foreach ($args as $fieldName => $fieldValue) { | ||
$query->addSearchTerm($fieldName, $fieldValue); | ||
} | ||
|
||
return $this->solr->query($query); | ||
} | ||
|
||
/* (non-PHPdoc) | ||
* @see FS\SolrBundle\Repository.RepositoryInterface::findOneBy() | ||
*/ | ||
public function findOneBy(array $args) { | ||
$found = $this->findBy($args); | ||
|
||
return array_pop($found); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace FS\SolrBundle\Repository; | ||
|
||
interface RepositoryInterface { | ||
public function findBy(array $args); | ||
|
||
public function find($id); | ||
|
||
public function findOneBy(array $args); | ||
|
||
public function findAll(); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.