equal
deleted
inserted
replaced
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 use Doctrine\ORM\Query\ResultSetMapping; |
7 use Doctrine\ORM\Query\ResultSetMapping; |
8 use \ReflectionClass; |
8 use \ReflectionClass; |
9 use Doctrine\ORM\AbstractQuery; |
9 use Doctrine\ORM\AbstractQuery; |
|
10 use Doctrine\ORM\Mapping\ClassMetadataInfo; |
10 |
11 |
11 /** |
12 /** |
12 * DocumentRepository |
13 * DocumentRepository |
13 * |
14 * |
14 * This class was generated by the Doctrine ORM. Add your own custom |
15 * This class was generated by the Doctrine ORM. Add your own custom |
133 |
134 |
134 //TODO: replace by custom exception |
135 //TODO: replace by custom exception |
135 throw new \Exception("Unknown accessor $accessor"); |
136 throw new \Exception("Unknown accessor $accessor"); |
136 } |
137 } |
137 |
138 |
138 function writeDocument($document, $document_id_column, $fields) |
139 |
|
140 private function getColumnName($field_name) |
|
141 { |
|
142 if(isset($this->getClassMetadata()->columnNames[$field_name])) |
|
143 { |
|
144 return $this->getClassMetadata()->columnNames[$field_name]; |
|
145 } |
|
146 |
|
147 $res = $field_name; |
|
148 if(isset($this->getClassMetadata()->associationMappings[$field_name])) |
|
149 { |
|
150 $association_mapping = $this->getClassMetadata()->associationMappings[$field_name]; |
|
151 if( |
|
152 isset($association_mapping['type']) |
|
153 && ( $association_mapping['type'] === ClassMetadataInfo::ONE_TO_ONE || $association_mapping['type'] === ClassMetadataInfo::MANY_TO_ONE) |
|
154 && count($association_mapping['joinColumns']) > 0 |
|
155 ) |
|
156 { |
|
157 $res = $association_mapping['joinColumns'][0]['name']; |
|
158 } |
|
159 } |
|
160 |
|
161 return $res; |
|
162 } |
|
163 |
|
164 public function writeDocument($document, $document_id_column, $fields) |
139 { |
165 { |
140 // get document from id |
166 // get document from id |
141 |
167 |
142 $docid = $this->reflectionGetField($document, $document_id_column); |
168 $docid = $this->reflectionGetField($document, $document_id_column); |
143 $baseDocument = $this->findOneByExternalId($docid); |
169 $baseDocument = $this->findOneByExternalId($docid); |
229 |
255 |
230 $score = array(); |
256 $score = array(); |
231 $i = 0; |
257 $i = 0; |
232 foreach ($values as $fielddef) { |
258 foreach ($values as $fielddef) { |
233 $i++; |
259 $i++; |
234 $columns = $fielddef["columns"]; |
260 $field_list = explode(",", $fielddef["columns"]); |
|
261 $column_list = array(); |
|
262 foreach($field_list as $field_name) |
|
263 { |
|
264 $column_list[] = $this->getColumnName(trim($field_name)); |
|
265 } |
|
266 $columns = join(",", $column_list); |
|
267 |
235 $value = $fielddef["value"]; |
268 $value = $fielddef["value"]; |
236 $weight = isset($fielddef["weight"])?$fielddef["weight"]:1.0; |
269 $weight = isset($fielddef["weight"])?$fielddef["weight"]:1.0; |
237 |
270 |
238 $score[] = "(MATCH($columns) AGAINST (:value_$i))*:weight_$i"; |
271 $score[] = "(MATCH($columns) AGAINST (:value_$i))*:weight_$i"; |
239 $parameters["value_$i"] = $value; |
272 $parameters["value_$i"] = $value; |
249 $conditions_array = array(); |
282 $conditions_array = array(); |
250 $i = 0; |
283 $i = 0; |
251 foreach ($conditions as $field => $conddef) |
284 foreach ($conditions as $field => $conddef) |
252 { |
285 { |
253 $i++; |
286 $i++; |
|
287 $col = $this->getColumnName($field); |
254 if(is_array($conddef) && isset($conddef['operator'])) |
288 if(is_array($conddef) && isset($conddef['operator'])) |
255 { |
289 { |
256 $operator = $conddef["operator"]; |
290 $operator = $conddef["operator"]; |
257 $values = $conddef["value"]; |
291 $values = $conddef["value"]; |
258 } |
292 } |
272 $in_parameters = array(); |
306 $in_parameters = array(); |
273 for ($j = 0; $j < count($values); $j++) { |
307 for ($j = 0; $j < count($values); $j++) { |
274 $parameters["cond_val_$i_$j"] = $values[$j]; |
308 $parameters["cond_val_$i_$j"] = $values[$j]; |
275 $in_parameters[] = ":cond_val_$i_$j"; |
309 $in_parameters[] = ":cond_val_$i_$j"; |
276 } |
310 } |
277 $cond = "($field IN (".implode(",",$in_parameters)."))"; |
311 $cond = "($col IN (".implode(",",$in_parameters)."))"; |
278 } |
312 } |
279 else |
313 else |
280 { |
314 { |
281 $cond = "($field $operator :cond_val_$i)"; |
315 $cond = "($col $operator :cond_val_$i)"; |
282 $parameters["cond_val_$i"] = $values; |
316 $parameters["cond_val_$i"] = $values; |
283 } |
317 } |
284 $conditions_array[] = $cond; |
318 $conditions_array[] = $cond; |
285 } |
319 } |
286 |
320 |