grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026hits = $hits; $this->scores = $scores; $this->options = $options; $this->groupedByModule = $groupedByModule; $this->searchTime = $searchTime; $this->total = $total; if ($this->scores != null && count($hits) != count($scores)) { throw new RuntimeException('The sizes of $hits and $scores must match.'); } } /** * Returns the results. * * Note that the structure of the results depends whether of not they have been nested by module or not. * * @return array */ public function getHits() { return $this->hits; } /** * Fetches the results (originally just module->id) as Beans. * * @see getHits() * @return array */ public function getHitsAsBeans() { $hits = $this->hits; $parsed = []; foreach ($hits as $module => $beans) { foreach ((array)$beans as $bean) { $obj = BeanFactory::getBean($module, $bean); // if a search found a bean but suitecrm does not, it could happens // maybe the bean is deleted but elsasticsearch is not re-indexing yet. // so at this point we trying to rebuild the index and try again to get bean: if (!$obj) { ElasticSearch\ElasticSearchIndexer::repairElasticsearchIndex(); $obj = BeanFactory::getBean($module, $bean); } if (!$obj) { throw new Exception('Error retrieveing bean: ' . $module . ' [' . $bean . ']'); } $obj->load_relationships(); $fieldDefs = $obj->getFieldDefinitions(); $objUpdatedLinks = $this->updateFieldDefLinks($obj, $fieldDefs); $parsed[$module][] = $objUpdatedLinks; } } return $parsed; } /** * * @param SugarBean $obj * @param array $fieldDefs * @return SugarBean */ protected function updateFieldDefLinks(SugarBean $obj, $fieldDefs) { foreach ($fieldDefs as &$fieldDef) { if (isset($obj->{$fieldDef['name']})) { $obj = $this->updateObjLinks($obj, $fieldDef); } } return $obj; } /** * Update related links in a bean to show it on results page * * @param SugarBean $obj * @param array $fieldDef * @return SugarBean */ protected function updateObjLinks(SugarBean $obj, &$fieldDef) { if ($fieldDef['type'] == 'relate' && isset($fieldDef['link']) && isset($fieldDef['id_name']) && $fieldDef['id_name']) { $relId = $this->getRelatedId($obj, $fieldDef['id_name'], $fieldDef['link']); $obj->{$fieldDef['name']} = $this->getLink($obj->{$fieldDef['name']}, $fieldDef['module'], $relId, 'DetailView'); } elseif ($fieldDef['name'] == 'name') { $obj->{$fieldDef['name']} = $this->getLink($obj->{$fieldDef['name']}, $obj->module_name, $obj->id, 'DetailView'); } return $obj; } /** * resolve related record ID * * @param string $idName * @param string $link * @return null|string */ protected function getRelatedId(SugarBean $obj, $idName, $link) { $relId = $obj->id; $relField = $idName; if (isset($obj->$link)) { $link2 = $obj->$link; $link2Focus = $link2->getFocus(); $relId = $link2Focus->$relField; } elseif (isset($obj->$relField)) { $relId = $obj->$relField; } else { LoggerManager::getLogger()->warn('Unresolved related ID for field: '. $relField); } return $relId; } /** * * @global array $sugar_config * @param string $label * @param string $module * @param string $record * @param string $action * @return string */ protected function getLink($label, $module, $record, $action) { global $sugar_config; $link = "{$label}"; return $link; } /** * Returns an arbitrary scores defining how much related a hit is to the query. * * @return array */ public function getScores() { return $this->scores; } /** * Returns the total number of hits (without pagination). * * @return int */ public function getTotal() { return $this->total; } /** * @return array */ public function getOptions() { return $this->options; } /** * @param string $key * * @return array */ public function getOption($key) { return $this->options[$key]; } /** * Time in seconds it took to perform the search. * * @return float */ public function getSearchTime() { return $this->searchTime; } /** * @return bool */ public function isGroupedByModule() { return $this->groupedByModule; } }