Entity/DocumentRepository.php
changeset 29 7496254cfead
parent 27 8551d844b4f3
child 30 d2fba1e3b94b
equal deleted inserted replaced
28:85c7e5e965e2 29:7496254cfead
     2 
     2 
     3 namespace IRI\Bundle\WikiTagBundle\Entity;
     3 namespace IRI\Bundle\WikiTagBundle\Entity;
     4 
     4 
     5 use Doctrine\ORM\EntityRepository;
     5 use Doctrine\ORM\EntityRepository;
     6 use IRI\Bundle\WikiTagBundle\Entity\Document;
     6 use IRI\Bundle\WikiTagBundle\Entity\Document;
     7 
     7 use Doctrine\ORM\Query\ResultSetMapping;
     8 use \ReflectionClass;
     8 use \ReflectionClass;
     9 
     9 
    10 /**
    10 /**
    11  * DocumentRepository
    11  * DocumentRepository
    12  *
    12  *
   204         $tagstr = $this->getTagsStr($document);
   204         $tagstr = $this->getTagsStr($document);
   205         
   205         
   206         $document->setTagsStr(implode(",",$tagstr));
   206         $document->setTagsStr(implode(",",$tagstr));
   207         $this->getEntityManager()->persist($document);
   207         $this->getEntityManager()->persist($document);
   208     }
   208     }
       
   209     
       
   210     /**
       
   211      *
       
   212      * Enter description here ...
       
   213      * @param array $values : key: the fields to search into, value array('value'=>value, 'weight'=>weight)
       
   214      * @param unknown_type $conditions
       
   215      */
       
   216     function search(array $values, array $conditions=NULL)
       
   217     {
       
   218 /*        $em = $this->getEntityManager();
       
   219         
       
   220         $rsm = new ResultSetMapping();
       
   221         $rsm->addEntityResult("IRI/Bundle/WikiTagBundle/Entity/Document", "d");
       
   222         $rsm->addFieldResult("d", "id", "id");
       
   223         $rsm->addFieldResult("d", "external_id", "externalId");
       
   224         $rsm->addScalarResult("d", "score");
       
   225         
       
   226         $score = "";
       
   227         foreach ($values as $fielddef) {
       
   228             
       
   229             $columns = $fielddef["columns"];
       
   230             $value = $fielddef["value"];
       
   231             $value = isset($fielddef["weight"])?$fielddef["weight"]:1.0;
       
   232             
       
   233             $score = "(MATCH($columns) AGAINST (:value))*:weight";
       
   234             $parameters[] =
       
   235         }
       
   236         
       
   237         
       
   238         $query = $em->createNativeQuery("SELECT d.id, d.external_id, MATCH(title) AGAINST('$value') FROM wikitag_document d WHERE MATCH(title) AGAINST('$value') > 0", $rsm);
       
   239         
       
   240         $res = $query->getScalarResult();
       
   241         
       
   242         return $res;*/
       
   243         
       
   244         
       
   245     }
   209         
   246         
   210 }
   247 }