private function getQueryIndex($query, SearchEngineOptions $options) { $index = '*'; $index_keys = []; foreach ($options->getDataboxes() as $databox) { $index_keys[] = $this->CRCdatabox($databox); } if (count($index_keys) > 0) { if ($options->getFields() || $options->getBusinessFieldsOn()) { if ($query !== '' && $options->isStemmed() && $options->getLocale()) { $index = 'metadatas' . implode('_stemmed_' . $options->getLocale() . ', metadatas', $index_keys) . '_stemmed_' . $options->getLocale(); $index .= ', metas_realtime_stemmed_' . $options->getLocale() . '_' . implode(', metas_realtime_stemmed_' . $options->getLocale() . '_', $index_keys); } else { $index = 'metadatas' . implode(',metadatas', $index_keys); $index .= ', metas_realtime' . implode(', metas_realtime', $index_keys); } } else { if ($query !== '' && $options->isStemmed() && $options->getLocale()) { $index = 'documents' . implode('_stemmed_' . $options->getLocale() . ', documents', $index_keys) . '_stemmed_' . $options->getLocale(); $index .= ', docs_realtime_stemmed_' . $options->getLocale() . '_' . implode(', docs_realtime_stemmed_' . $options->getLocale() . '_', $index_keys); } else { $index = 'documents' . implode(', documents', $index_keys); $index .= ', docs_realtime' . implode(', docs_realtime', $index_keys); } } } return $index; }
/** * Executes the Phrasea query * * @param string $query * @return PhraseaEngine */ private function executeQuery($query, SearchEngineOptions $options) { $nbanswers = $total_time = 0; $sort = ''; if ($options->getSortBy()) { switch ($options->getSortOrder()) { case SearchEngineOptions::SORT_MODE_ASC: $sort = '+'; break; case SearchEngineOptions::SORT_MODE_DESC: default: $sort = '-'; break; } $sort .= '0' . $options->getSortBy(); } foreach ($this->queries as $sbas_id => $qry) { $BF = []; foreach ($options->getBusinessFieldsOn() as $collection) { // limit business field query to databox local collection if ($sbas_id === $collection->get_sbas_id()) { $BF[] = $collection->get_base_id(); } } $results = phrasea_query2($this->app['session']->get('phrasea_session_id'), $sbas_id, $this->colls[$sbas_id], $this->arrayq[$sbas_id], $this->app['conf']->get(['main', 'key']), $this->app['session']->get('usr_id'), false, $options->getSearchType() == SearchEngineOptions::RECORD_GROUPING ? PHRASEA_MULTIDOC_REGONLY : PHRASEA_MULTIDOC_DOCONLY, $sort, $BF, $options->isStemmed() ? $options->getLocale() : null); if ($results) { $total_time += $results['time_all']; $nbanswers += $results["nbanswers"]; } } $sql = 'UPDATE cache SET query = :query, query_time = NOW(), duration = :duration, total = :total WHERE session_id = :ses_id'; $params = ['query' => $query, ':ses_id' => $this->app['session']->get('phrasea_session_id'), ':duration' => $total_time, ':total' => $nbanswers]; $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); return $this; }