Services/SearchService.php
changeset 77 021131fbe2c5
parent 75 ca2a145e67f3
equal deleted inserted replaced
76:bb7808e180c3 77:021131fbe2c5
    47         return $this->doctrine;
    47         return $this->doctrine;
    48     }
    48     }
    49     
    49     
    50     
    50     
    51     /**
    51     /**
       
    52      * Search.
    52      *
    53      *
    53      * Enter description here ...
       
    54      * @param mixed $value : either a string or the list of fields to search into ; format : ['<field_name>' => ['weight'=><relative weight of the field>, 'value' => value]]
    54      * @param mixed $value : either a string or the list of fields to search into ; format : ['<field_name>' => ['weight'=><relative weight of the field>, 'value' => value]]
    55      * @param array $conditions : array : key : field name, value : simple value (operator is "=") or array(valuea, value2,...) (operator is IN) or array("operator"=>"=","!=","<".">","<=".">=","like","ilike","in">, "value"=>value)
    55      * @param array $conditions : array : key : field name, value : simple value (operator is "=") or array(valuea, value2,...) (operator is IN) or array("operator"=>"=","!=","<".">","<=".">=","like","ilike","in">, "value"=>value)
    56      * @param array $fields : The field of field names to export, one of the list specified in the configuration file
    56      * @param array $fields : The field of field names to export, one of the list specified in the configuration file
    57      * @return array []
    57      * @return array [{'host_doc_id'=>,'wikitag_doc_id'=>, 'wikitag_doc'=>, '_score'=>,'field1'=>, 'field2'=>, }]
    58      */
    58      */
    59     public function search($value, array $conditions = null, array $fields = null)
    59     public function search($value, array $conditions = null, array $fields = null)
    60     {
    60     {
    61         if(is_null($value) || (is_string($value) && strlen($value) == 0) || count($value)==0 ) {
    61         if(is_null($value) || (is_string($value) && strlen($value) == 0) || count($value)==0 ) {
    62             return null;
    62             return null;
   143     }
   143     }
   144     
   144     
   145     /**
   145     /**
   146      * List the tag label containing the seed given as an argument.
   146      * List the tag label containing the seed given as an argument.
   147      * The seed is either at the beggining, the end of the label or at the beggining of a word.
   147      * The seed is either at the beggining, the end of the label or at the beggining of a word.
   148      * @param unknown_type $seed
   148      * @param string $seed
   149      * @return : an array containing the possible tag labels
   149      * @param boolean $doc_nb
       
   150      * @return : an array containing the possible tag labels with the number of documents
   150      */
   151      */
   151     public function completion($seed)
   152     public function completion($seed, $doc_nb=False)
   152     {
   153     {
   153         $rep = $this->getDoctrine()->getRepository('WikiTagBundle:Tag');
   154         $rep = $this->getDoctrine()->getRepository('WikiTagBundle:Tag');
   154         
   155         
   155         $res = array();
   156         $res = array();
   156         foreach ($rep->getCompletion($seed) as $value) {
   157         foreach ($rep->getCompletion($seed) as $value) {
   157             $res[] = $value['label'];
   158             $res[] = array('label' => $value['label'], 'nb_docs' => $value['nb_docs']);
   158         }
   159         }
   159         
   160         
   160         return $res;
   161         return $res;
   161     }
   162     }
   162     
   163