Пример #1
0
 private function hydrate(array &$record, array $fields, array $index_fields)
 {
     if (!isset($record['databox_id'])) {
         throw new Exception('Expected a record with the "databox_id" key set.');
     }
     $values = array();
     $terms = array();
     $filters = array();
     $field_names = array();
     foreach ($fields as $name => $root_concepts) {
         // Loop through all values to prepare bulk query
         $field_values = \igorw\get_in($record, explode('.', $index_fields[$name]));
         if ($field_values !== null) {
             // Concepts are databox's specific, but when no root concepts are
             // given we need to make sure we only match in the right databox.
             $filter = $root_concepts ? Filter::childOfConcepts($record['databox_id'], $root_concepts) : Filter::byDatabox($record['databox_id']);
             foreach ($field_values as $value) {
                 $values[] = $value;
                 $terms[] = Term::parse($value);
                 $filters[] = $filter;
                 $field_names[] = $name;
             }
         }
     }
     $bulk = $this->thesaurus->findConceptsBulk($terms, null, $filters, true);
     foreach ($bulk as $offset => $item_concepts) {
         if ($item_concepts && is_array($item_concepts) && count($item_concepts) > 0) {
             $name = $field_names[$offset];
             foreach ($item_concepts as $concept) {
                 $record['concept_path'][$name][] = $concept->getPath();
             }
         } else {
             $this->candidate_terms->insert($field_names[$offset], $values[$offset]);
         }
     }
 }