Exemplo n.º 1
0
 /**
  * Запуск переиндексации указанной области
  */
 public static function index_area($area_string, $runner_type = nc_search::INDEXING_NC_CRON)
 {
     $area = new nc_search_area($area_string);
     // task: состояние сессии переиндексации
     $task = new nc_search_indexer_task(array('area' => $area, 'rule_id' => $area->get('rule_id'), 'runner_type' => $runner_type));
     $task->save();
     // runner: стратегия
     $runner_classes = array(nc_search::INDEXING_NC_CRON => 'nc_search_indexer_runner_console', nc_search::INDEXING_CONSOLE => 'nc_search_indexer_runner_console', nc_search::INDEXING_BROWSER => 'nc_search_indexer_runner_web', nc_search::INDEXING_CONSOLE_BATCH => 'nc_search_indexer_runner_batch');
     if (!isset($runner_classes[$runner_type])) {
         throw new nc_search_exception("nc_search_indexer::index_area(): wrong runner type '{$runner_type}'");
     }
     $runner_class = $runner_classes[$runner_type];
     $indexer = new nc_search_indexer();
     return $indexer->start($task, new $runner_class());
 }
Exemplo n.º 2
0
 /**
  * @return array  keys: included, excluded
  */
 public function get_area_description()
 {
     $area = new nc_search_area($this->get('area_string'), $this->get('site_id'));
     return array('included' => $area->get_description(false), 'excluded' => $area->get_description(true));
 }
Exemplo n.º 3
0
 /**
  * Трансформация запроса nc_search_query в запрос Lucene
  * @param nc_search_query $query
  * @return Zend_Search_Lucene_Search_Query
  */
 protected function get_lucene_query(nc_search_query $query)
 {
     Zend_Search_Lucene_Search_QueryParser::suppressQueryParsingExceptions();
     if ($this->get_setting('DefaultBooleanOperator') == 'AND') {
         Zend_Search_Lucene_Search_QueryParser::setDefaultOperator(Zend_Search_Lucene_Search_QueryParser::B_AND);
     }
     $query_string = $query->to_string();
     // range search for integers
     if (nc_search::should('AllowRangeSearch') && strpos($query_string, ' TO ')) {
         preg_match_all("/(\\[|\\{)\\s*(\\d+)\\s+TO\\s+(\\d+)\\s*(\\]|\\})/", $query_string, $matches, PREG_SET_ORDER);
         foreach ($matches as $m) {
             $query_string = str_replace($m[0], $m[1] . $this->pad_integer($m[2]) . " TO " . $this->pad_integer($m[3]) . $m[4], $query_string);
         }
     }
     // add a time range should it be required
     $modified_after = $query->get('modified_after');
     $modified_before = $query->get('modified_before');
     if ($modified_before || $modified_after) {
         $modified_after = $modified_after ? strftime("%Y%m%d%H%M%S", strtotime($modified_after)) : "19000101000000";
         $modified_before = $modified_before ? strftime("%Y%m%d%H%M%S", strtotime($modified_before)) : "22000101000000";
         $query_string = "({$query_string}) last_modified:[{$modified_after} TO {$modified_before}]";
     }
     // add area
     $area = $query->get('area');
     if ($area) {
         if (!$area instanceof nc_search_area) {
             $area = new nc_search_area($area);
         }
         $is_boolean = nc_search_util::is_boolean_query($query_string);
         $query_string = "({$query_string}) " . ($is_boolean ? " AND " : "+") . $area->get_field_condition($is_boolean);
     }
     // parse string into Lucene Query
     $zend_query = Zend_Search_Lucene_Search_QueryParser::parse($query_string, 'UTF-8');
     return $zend_query;
 }
Exemplo n.º 4
0
 /**
  * @param bool $use_temp_table
  * @return string|array
  */
 public function get_sql_query($use_temp_table)
 {
     $index = $this->index_table;
     $has_conditions = count($this->condition_stack[0]) > 0;
     $create_temp_table = $use_temp_table && $has_conditions;
     if (!$create_temp_table) {
         foreach ($this->condition_joins as $table_name => $join_condition) {
             $this->add_left_join($table_name);
         }
     }
     // prepare ORDER BY and value for the `Score` column
     $ranking_select = "1 AS `Score` ";
     $order_by = "";
     $sort_field_name = $this->query->get('sort_by');
     if ($sort_field_name == "last_modified") {
         $this->add_join($this->document_table);
         $order_by = "ORDER BY `{$this->document_table}`.`LastModified` DESC";
     } elseif ($sort_field_name) {
         // some other field
         /** @var $sort_fields nc_search_provider_index_field_manager */
         $sort_fields = $this->translator->get_fields('name', $sort_field_name)->where('is_sortable', true);
         if (count($sort_fields)) {
             $order_by = array();
             /** @var $f nc_search_provider_index_field */
             foreach ($sort_fields as $f) {
                 $field_table_name = $f->get_field_table_name();
                 $this->add_left_join($field_table_name);
                 $order_by[] = "`{$field_table_name}`.`RawData`";
             }
             $order_by = "ORDER BY IFNULL(" . join(", ", $order_by) . ", 0) " . ($this->query->get('sort_direction') == SORT_DESC ? "DESC" : "ASC");
         }
     }
     if (!$order_by) {
         // standard sorting by relevance
         $ranking_select = $this->term_ranking_calculation();
         $order_by = "ORDER BY `Score` DESC";
     }
     // Prepare area condition (will need join)
     $area_condition = "";
     $area = $this->query->get('area');
     if ($area) {
         $this->add_join($this->document_table);
         if (!$area instanceof nc_search_area) {
             $area = new nc_search_area($area);
         }
         $area_condition = "AND " . $area->get_sql_condition() . "\n";
     }
     // Compose query
     // SELECT
     $query_string = "SELECT " . ($create_temp_table ? "" : "SQL_CALC_FOUND_ROWS ") . "`{$index}`.`Document_ID`,\n" . $ranking_select;
     // FROM
     $query_string .= "FROM `{$index}` FORCE INDEX (`Content`)\n";
     // INNER JOINs
     foreach ($this->joins as $j) {
         $query_string .= "{$j}\n";
     }
     // LEFT JOINs
     foreach ($this->left_joins as $j) {
         $query_string .= "{$j}\n";
     }
     // WHERE [index_match_condition]
     // (1) Index match;                  (2) site/path filter
     $query_string .= "WHERE {$this->index_match}\n{$area_condition}";
     // (3) Extra conditions
     if ($has_conditions && !$use_temp_table) {
         $query_string .= "AND " . join("\nAND ", $this->condition_stack[0]);
     }
     // ORDER
     $query_string .= "\n{$order_by}";
     if ($use_temp_table) {
         $t = $this->get_temporary_table_name();
         $queries = array("temp_table" => $t, "prefilter" => $query_string, "refinement" => "SELECT t.`Document_ID`, t.`Rank`\n" . "FROM `{$t}` AS t\n" . join("\n", $this->condition_joins) . "\n" . "WHERE t.`Rank` >= IFNULL(@rank_value,0) AND" . join("\nAND ", $this->condition_stack[0]) . "\n" . "ORDER BY t.`Rank`\n");
         return $queries;
     } else {
         // LIMIT, OFFSET
         $query_string .= "\nLIMIT " . (int) $this->query->get('limit') . "\nOFFSET " . (int) $this->query->get('offset');
         return $query_string;
     }
 }
Exemplo n.º 5
0
$db->query("SET NAMES utf8");
$res = $db->get_results($query, ARRAY_A);
$found_rows = $db->get_var("SELECT FOUND_ROWS()");
$db->query("SET NAMES " . nc_core('MYSQL_CHARSET'));
// this is actually incorrect:
echo "<div class='query_details_header'>", "<b>", sprintf(NETCAT_MODULE_SEARCH_ADMIN_QUERY_ALL_QUERIES, nc_search_util::convert($query_string)), "</b> (", NETCAT_MODULE_SEARCH_ADMIN_QUERY_OPEN_RESULTS_HINT, "):", "</div>";
// таблица с результатами
echo "<table class='nc-table nc--large nc--hovered nc--striped list'>\n", "<tr>", "<th class='nc-text-center'>", NETCAT_MODULE_SEARCH_ADMIN_QUERY_TIME, "</th>", "<th class='nc-text-center' width='40%'>", NETCAT_MODULE_SEARCH_ADMIN_QUERY_AREA, "</th>", "<th class='nc-text-center'>", NETCAT_MODULE_SEARCH_ADMIN_QUERY_RESULTS_COUNT, "</th>", "<th class='nc-text-center'>", NETCAT_MODULE_SEARCH_ADMIN_QUERY_USER, "</th>", "<th class='nc-text-center'>", NETCAT_MODULE_SEARCH_ADMIN_QUERY_IP, "</th>", "</tr>\n";
foreach ($res as $row) {
    $has_area = strlen($row['Area']) > 0;
    $site_area = new nc_search_area("site{$row['Catalogue_ID']}");
    list($site_description) = $site_area->get_description(false);
    if (!$has_area) {
        $area_cell = "<td>" . NETCAT_MODULE_SEARCH_ADMIN_RULE_AREA_DESCRIPTION_ALLSITES . "</td>";
    } else {
        $area = new nc_search_area($row['Area'], $row['Catalogue_ID']);
        $description = array("included" => $area->get_description(false), "excluded" => $area->get_description(true));
        $hint = "<div class='header'><strong>{$site_description}</strong></div>";
        if ($description["included"]) {
            $hint .= "<div class='header'><strong>" . NETCAT_MODULE_SEARCH_ADMIN_QUERY_AREA_INCLUDED . "</strong>:</div><div class='list'>";
            foreach ($description["included"] as $item) {
                $hint .= "<div class='item'>" . NETCAT_MODULE_SEARCH_ADMIN_BULLET . " {$item}</div>\n";
            }
            $hint .= "</div>";
        }
        if ($description["excluded"]) {
            $hint .= "<div class='header'><strong>" . NETCAT_MODULE_SEARCH_ADMIN_QUERY_AREA_EXCLUDED . "</strong>:</div><div class='list'>";
            foreach ($description["excluded"] as $item) {
                $hint .= "<div class='item'>" . NETCAT_MODULE_SEARCH_ADMIN_BULLET . " {$item}</div>\n";
            }
            $hint .= "</div>";