/** * */ public function add_item(nc_search_query_expression $item) { if ($this->field && !$item->get_field()) { $item->set_field($this->field); } $this->items[] = $item; return $this; }
/** * @param nc_search_query_expression $expression * @param string $fts_query */ protected function add_field_matches(nc_search_query_expression $expression, $fts_query) { $has_field = $expression->get_field(); if (!$has_field && !$this->implicit_field_match) { return; } // --- EXIT --- $table_names = $this->get_table_names($expression); $is_inside_or = $this->is_inside('or'); // prefetch Document_IDs -- this is the fastest way to do this // type of queries (other ways are subqueries, which are quite slow, // and FTS match, which won’t use FTS index and therefore slow too) $id_conditions = array(); $db = $this->get_db(); foreach ($table_names as $table_name) { if (!$has_field && !$is_inside_or) { // i.e. regular term which is not optional // this condition is already in the FTS query $id_conditions[] = "1"; } else { $query = "SELECT `Document_ID` FROM `{$table_name}` WHERE MATCH(`Content`) AGAINST ('{$fts_query}' IN BOOLEAN MODE)"; $ids = $db->get_col($query); $ids = $ids ? join(",", $ids) : "0"; $id_conditions[] = "`{$this->index_table_name}`.`Document_ID` IN ({$ids})"; } } $condition = $id_conditions ? "(" . join(" OR ", $id_conditions) . ")" : "0"; $this->query_builder->add_condition($condition); }