| author | ymh <ymh.work@gmail.com> |
| Fri, 26 Sep 2014 10:04:40 +0200 | |
| changeset 136 | f209fcb0df6c |
| parent 75 | ca2a145e67f3 |
| permissions | -rwxr-xr-x |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
<?php |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
/* |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
* This file is part of the WikiTagBundle package. |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
* |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
* (c) IRI <http://www.iri.centrepompidou.fr/> |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
* |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
* For the full copyright and license information, please view the LICENSE |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
* file that was distributed with this source code. |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
*/ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
namespace IRI\Bundle\WikiTagBundle\Services; |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
use Symfony\Component\DependencyInjection\ContainerAware; |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
class SearchService extends ContainerAware |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
{ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
/** |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
* Get the container associated with this service. |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
* @return ContainerInterface |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
*/ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
public function getContainer() |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
{ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
return $this->container; |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
} |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
/** |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
* Public constructor with container as parameter for contruct injection. |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
* @param ContainerInterface $container |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
*/ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
public function __construct(ContainerInterface $container) |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
{ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
$this->setContainer($container); |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
} |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
private $doctrine; |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
|
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
37 |
/** |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
38 |
* doctrine object getter |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
39 |
* @return object |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
40 |
*/ |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
public function getDoctrine() |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
{ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
if(is_null($this->doctrine)) |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
{ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
$this->doctrine = $this->getContainer()->get('doctrine'); |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
} |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
return $this->doctrine; |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
48 |
} |
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
49 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
50 |
|
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
/** |
|
75
ca2a145e67f3
Completion service add the nb of doc + test
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
52 |
* Search. |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
* |
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
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]] |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
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) |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
56 |
* @param array $fields : The field of field names to export, one of the list specified in the configuration file |
|
75
ca2a145e67f3
Completion service add the nb of doc + test
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
57 |
* @return array [{'host_doc_id'=>,'wikitag_doc_id'=>, 'wikitag_doc'=>, '_score'=>,'field1'=>, 'field2'=>, }] |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
*/ |
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
59 |
public function search($value, array $conditions = null, array $fields = null) |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
{ |
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
61 |
if(is_null($value) || (is_string($value) && strlen($value) == 0) || count($value)==0 ) { |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
62 |
return null; |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
63 |
} |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
64 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
65 |
$fielddeflist = $this->getContainer()->getParameter("wiki_tag.fields"); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
66 |
$fieldquery = array(); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
67 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
68 |
// build filed query |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
69 |
if(is_string($value)) { |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
70 |
foreach ($fielddeflist as $fieldname => $fielddef) { |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
71 |
if(!is_null($fielddef) && isset($fielddef['weight'])) { |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
72 |
$weight = $fielddef['weight']; |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
73 |
} |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
74 |
else |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
75 |
{ |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
76 |
$weight = 1.0; |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
77 |
} |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
78 |
$fieldquery[] = array("columns"=>$fieldname, "value"=>$value, "weight"=>$weight); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
79 |
} |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
80 |
} |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
81 |
else { |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
82 |
foreach ($value as $fieldname => $fielddef) { |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
83 |
if(is_null($fielddef) || !isset($fielddef['value']) || strlen($fielddef['value']) == 0) { |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
84 |
continue; |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
85 |
} |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
86 |
$valuefield = $fielddef['value']; |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
87 |
if(isset($fielddef['weight'])) { |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
88 |
$weight = $fielddef['weight']; |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
89 |
} |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
90 |
else |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
91 |
{ |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
92 |
$weight = 1.0; |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
93 |
} |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
94 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
95 |
$fieldquery[] = array("columns"=>$fieldname, "value"=>$valuefield, "weight"=>$weight); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
96 |
} |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
97 |
} |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
98 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
99 |
// buildf |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
100 |
if(is_null($fields)) |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
101 |
{ |
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
102 |
$fieldnamelist = array(); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
103 |
foreach ($fielddeflist as $fieldname => $fielddef) { |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
104 |
$fieldnamelist[] = $fieldname; |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
105 |
} |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
106 |
} |
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
107 |
else { |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
108 |
$fieldnamelist = $fields; |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
109 |
} |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
110 |
|
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
111 |
$doctrine = $this->getContainer()->get('doctrine'); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
112 |
$rep = $doctrine->getRepository('WikiTagBundle:Document'); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
113 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
114 |
$score_res = $rep->search($fieldquery, $conditions, $fieldnamelist); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
115 |
|
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
116 |
$res = array(); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
117 |
foreach($score_res as $single_res) { |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
118 |
$res_entry = array(); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
119 |
$res_entry['host_doc_id'] = $single_res[0]->getExternalId()->getId(); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
120 |
$res_entry['wikitag_doc_id'] = $single_res[0]->getId(); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
121 |
foreach($fieldnamelist as $fieldname) { |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
122 |
$accessor_name = "get".ucfirst($fieldname); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
123 |
$res_entry[$fieldname] = $single_res[0]->{$accessor_name}(); |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
124 |
} |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
125 |
$res_entry['_score'] = $single_res['score']; |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
126 |
$res_entry['wikitag_doc'] = $single_res[0]; |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
127 |
$res[] = $res_entry; |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
128 |
} |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
129 |
|
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
130 |
return $res; |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
131 |
} |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
132 |
|
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
133 |
|
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
134 |
/** |
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
135 |
* get a list of tags label sprted by their number of documents tagged. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
136 |
* @param int $max_tags the max number of tags to return |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
137 |
* @return array of array of tags, |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
138 |
*/ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
139 |
public function getTagCloud($max_tags) |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
140 |
{ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
141 |
$rep = $this->getDoctrine()->getRepository('WikiTagBundle:Tag'); |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
142 |
return $rep->getTagCloud($max_tags); |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
143 |
} |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
144 |
|
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
145 |
/** |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
146 |
* List the tag label containing the seed given as an argument. |
|
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
147 |
* The seed is either at the beggining, the end of the label or at the beggining of a word. |
|
75
ca2a145e67f3
Completion service add the nb of doc + test
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
148 |
* @param string $seed |
|
ca2a145e67f3
Completion service add the nb of doc + test
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
149 |
* @param boolean $doc_nb |
|
ca2a145e67f3
Completion service add the nb of doc + test
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
150 |
* @return : an array containing the possible tag labels with the number of documents |
|
68
e7384fb35f7a
improve search test and documentation
ymh <ymh.work@gmail.com>
parents:
57
diff
changeset
|
151 |
*/ |
|
75
ca2a145e67f3
Completion service add the nb of doc + test
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
152 |
public function completion($seed, $doc_nb=False) |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
153 |
{ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
154 |
$rep = $this->getDoctrine()->getRepository('WikiTagBundle:Tag'); |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
155 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
156 |
$res = array(); |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
157 |
foreach ($rep->getCompletion($seed) as $value) { |
|
75
ca2a145e67f3
Completion service add the nb of doc + test
ymh <ymh.work@gmail.com>
parents:
68
diff
changeset
|
158 |
$res[] = array('label' => $value['label'], 'nb_docs' => $value['nb_docs']); |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
159 |
} |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
160 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
161 |
return $res; |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
162 |
} |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
163 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
164 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
165 |
} |