/** * @param nc_search_query $query * @return string|null */ public function translate(nc_search_query $query) { $root = $query->parse(); // empty query? if ($root instanceof nc_search_query_expression_empty) { return null; } // queries with only excluded terms are forbidden if ($root->is_excluded() || $root instanceof nc_search_query_expression_not) { return null; } // initialize variables used for a translation of the query $this->query_builder = $builder = new nc_search_provider_index_querybuilder($query, $this); $this->stack = array(); $this->unknown_required_terms = array(); $this->can_skip_fts_query = false; $this->implicit_field_match = $this->expression_requires_implicit_match($root); // get language filters chain to use in this.translate_term() etc. $language = $query->get('language'); if (!$language) { $language = nc_Core::get_object()->lang->detect_lang(); } $query_context = new nc_search_context(array("search_provider" => get_class($this->provider), "language" => $language, "action" => "searching")); $this->text_filters = nc_search_extension_manager::get('nc_search_language_filter', $query_context)->stop_on(array()); // Ready to go! // translate the expression tree $index_query = $this->dispatch_translate($root); if (!$this->can_skip_fts_query) { // interval search at the root for a numeric field // index query is required almost always if (!strlen($index_query)) { return null; } // e.g. if query string consists of stop words if ($index_query == "____" || $index_query == "(____)") { // empty query return null; } } // set query for the combined index in the query builder if ($index_query && !$root->get_field()) { $builder->set_index_match($index_query); } // there are required terms that are not in the index, so don’t make a query if ($this->unknown_required_terms) { return null; } // использовать временную таблицу для уточняющих запросов при поиске фраз? $use_temp_table = !nc_search::get_setting('DatabaseIndex_AlwaysGetTotalCount') && $this->expression_has_phrase($root); // return SQL query string $result = $builder->get_sql_query($use_temp_table); return $result; }
/** * @param nc_search_query $query * @return mixed */ public function translate(nc_search_query $query) { return $this->dispatch_translate($query->parse()); }