Commit e86880bd authored by Chris Graham's avatar Chris Graham
Browse files

Fixed MANTIS-4623 (Error with too many indexes CPFs)

parent 35bbd424
Loading
Loading
Loading
Loading
+10 −14
Original line number Diff line number Diff line
@@ -207,6 +207,7 @@ class Hook_search_cns_members extends FieldsSearchHook
        require_lang('cns');

        $indexes = collapse_2d_complexity('i_fields', 'i_name', $GLOBALS['FORUM_DB']->query_select('db_meta_indices', array('i_fields', 'i_name'), array('i_table' => 'f_member_custom_fields'), 'ORDER BY i_name'));
        // ^ the ORDER BY above causes fulltext indexes to be given precedence in $indexes for any field_x

        // Calculate our where clause (search)
        if ($author != '') {
@@ -231,15 +232,15 @@ class Hook_search_cns_members extends FieldsSearchHook
                $non_trans_fields++;
            }
        }
        $index_issue = (get_param_integer('force_like', 0) == 0) && ($non_trans_fields > 16); // MySQL limit for fulltext index querying. We'll therefore not throw EVERY searchable field into the search query (only core ones, and ones we're explicitly filtering on)
        if ($index_issue) {
            $boolean_search = true;
            list($content_where) = build_content_where($content, $boolean_search, $boolean_operator); // Rebuilding $content_where from what was passed to this function
        }
        $reduced_ft_searching = ((get_param_integer('force_like', 0) == 0) && ($non_trans_fields > 16)); // MySQL limit for fulltext index querying. We'll therefore not throw EVERY searchable field into the search query (only core ones, and ones we're explicitly filtering on)
        foreach ($rows as $i => $row) {
            $ob = get_fields_hook($row['cf_type']);
            list(, , $storage_type) = $ob->get_field_value_row_bits($row);

            $doing_slow_boolean_search = (($boolean_search) && ((!method_exists($GLOBALS['SITE_DB']->static_ob, 'db_has_full_text_boolean')) || (!$GLOBALS['SITE_DB']->static_ob->db_has_full_text_boolean())));
            $fulltext_possible = (db_has_full_text($GLOBALS['SITE_DB']->connection_read)) && (array_key_exists('field_' . strval($row['id']), $indexes)) && ($indexes['field_' . strval($row['id'])][0] == '#');
            $fulltext_searched = $fulltext_possible && !$doing_slow_boolean_search;

            // Filter form
            $param = get_param_string('option_' . strval($row['id']), '');
            if ($param != '') {
@@ -251,12 +252,7 @@ class Hook_search_cns_members extends FieldsSearchHook
                    $temp = '?=' . float_to_raw_string(floatval($param));
                } elseif ($storage_type == 'list') {
                    $temp = db_string_equal_to('?', $param);
                } elseif (
                    (array_key_exists('field_' . strval($row['id']), $indexes)) && ($indexes['field_' . strval($row['id'])][0] == '#') &&
                    (db_has_full_text($GLOBALS['SITE_DB']->connection_read)) &&
                    ((method_exists($GLOBALS['SITE_DB']->static_ob, 'db_has_full_text_boolean')) && ($GLOBALS['SITE_DB']->static_ob->db_has_full_text_boolean()) || (!$boolean_search)) &&
                    (!is_under_radar($param))
                ) {
                } elseif (($fulltext_searched) && (!is_under_radar($param))) { // Anything is fulltext-searched, if possible
                    $temp = db_full_text_assemble('"' . $param . '"', true);
                } else {
                    list($temp,) = db_like_assemble($param);
@@ -271,13 +267,13 @@ class Hook_search_cns_members extends FieldsSearchHook
            }

            // Standard search
            if (((array_key_exists('field_' . strval($row['id']), $indexes)) && ($indexes['field_' . strval($row['id'])][0] == '#')) || ($boolean_search)) {
            if (($fulltext_searched) || ($doing_slow_boolean_search)) {
                if (strpos($storage_type, '_trans') === false) {
                    if ((!$index_issue) || ($boolean_search)) {
                    if ((!$reduced_ft_searching) || ($doing_slow_boolean_search)) {
                        $raw_fields[] = 'field_' . strval($row['id']);
                    }
                } else {
                    if ((!$index_issue) || ($boolean_search) || (multi_lang_content())) { // MySQL limit for fulltext index querying
                    if ((multi_lang_content()) || (!$reduced_ft_searching) || ($doing_slow_boolean_search)) {
                        $trans_fields['field_' . strval($row['id'])] = 'LONG_TRANS__COMCODE';
                    }
                }