Example #1
0
 /**
  * {@inheritdoc}
  */
 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);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function findOneBy(array $args)
 {
     $metaInformation = $this->solr->getMetaFactory()->loadInformation($this->entity);
     $query = $this->solr->createQuery($this->entity);
     $query->setHydrationMode($this->hydrationMode);
     $query->setRows(1);
     $query->setUseAndOperator(true);
     $query->addSearchTerm('id', $metaInformation->getDocumentName() . '_*');
     $query->setQueryDefaultField('id');
     $helper = $query->getHelper();
     foreach ($args as $fieldName => $fieldValue) {
         $fieldValue = $helper->escapeTerm($fieldValue);
         $query->addSearchTerm($fieldName, $fieldValue);
     }
     $found = $this->solr->query($query);
     return array_pop($found);
 }
Example #3
0
 public function testQuery_OneDocumentFound()
 {
     $arrayObj = new SolrDocumentStub(array('title_s' => 'title'));
     $document = new Document();
     $document->addField('document_name_s', 'name');
     $query = new FindByDocumentNameQuery();
     $query->setDocumentName('name');
     $query->setDocument($document);
     $query->setEntity(new ValidTestEntity());
     $query->setIndex('index0');
     $this->assertQueryWasExecuted(array($arrayObj), 'index0');
     $solr = new Solr($this->solrClientFake, $this->commandFactory, $this->eventDispatcher, $this->metaFactory, $this->mapper);
     $entities = $solr->query($query);
     $this->assertEquals(1, count($entities));
 }