News:

Join the Facebook Fan Page.

Main Menu

Blank Search Page

Started by xtom, October 05, 2010, 07:02:56 AM

Previous topic - Next topic

xtom

I think I've found the problem at last. It's the spellchecking code in sources/search.php - If I remove the block of code below from around line 777 on this file the search works again, no more blank search page. I think it's the line pspell_new('en'); that causes it to crash to blank screen. Strangly I don't get this problem on a fresh install, only when I use it on my existing database. Anyone know why it's happening exactly? Is it safe to remove this code permanently or is there something else I can do to fix?

    if ($context['show_spellchecking'])
    {
        // Windows fix.
        ob_start();
        $old = error_reporting(0);
        pspell_new('en');
        $pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($txt['lang_character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
        error_reporting($old);

        if (!$pspell_link)
            $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);

        ob_end_clean();

        $did_you_mean = array('search' => array(), 'display' => array());
        $found_misspelling = false;
        foreach ($searchArray as $word)
        {
            if (empty($pspell_link))
                continue;

            $word = $word;
            // Don't check phrases.
            if (preg_match('~^\w+$~', $word) === 0)
            {
                $did_you_mean['search'][] = '"' . $word . '"';
                $did_you_mean['display'][] = '"' . $smcFunc['htmlspecialchars']($word) . '"';
                continue;
            }
            // For some strange reason spell check can crash PHP on decimals.
            elseif (preg_match('~\d~', $word) === 1)
            {
                $did_you_mean['search'][] = $word;
                $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
                continue;
            }
            elseif (pspell_check($pspell_link, $word))
            {
                $did_you_mean['search'][] = $word;
                $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
                continue;
            }

            $suggestions = pspell_suggest($pspell_link, $word);
            foreach ($suggestions as $i => $s)
            {
                // Search is case insensitive.
                if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word))
                    unset($suggestions[$i]);
                // Plus, don't suggest something the user thinks is rude!
                elseif ($suggestions[$i] != censorText($s))
                    unset($suggestions[$i]);
            }

            // Anything found?  If so, correct it!
            if (!empty($suggestions))
            {
                $suggestions = array_values($suggestions);
                $did_you_mean['search'][] = $suggestions[0];
                $did_you_mean['display'][] = '<em><strong>' . $smcFunc['htmlspecialchars']($suggestions[0]) . '</strong></em>';
                $found_misspelling = true;
            }
            else
            {
                $did_you_mean['search'][] = $word;
                $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
            }
        }

        if ($found_misspelling)
        {
            // Don't spell check excluded words, but add them still...
            $temp_excluded = array('search' => array(), 'display' => array());
            foreach ($excludedWords as $word)
            {
                $word = $word;

                if (preg_match('~^\w+$~', $word) == 0)
                {
                    $temp_excluded['search'][] = '-"' . $word . '"';
                    $temp_excluded['display'][] = '-&quot;' . $smcFunc['htmlspecialchars']($word) . '&quot;';
                }
                else
                {
                    $temp_excluded['search'][] = '-' . $word;
                    $temp_excluded['display'][] = '-' . $smcFunc['htmlspecialchars']($word);
                }
            }

            $did_you_mean['search'] = array_merge($did_you_mean['search'], $temp_excluded['search']);
            $did_you_mean['display'] = array_merge($did_you_mean['display'], $temp_excluded['display']);

            $temp_params = $search_params;
            $temp_params['search'] = implode(' ', $did_you_mean['search']);
            if (isset($temp_params['brd']))
                $temp_params['brd'] = implode(',', $temp_params['brd']);
            $context['params'] = array();
            foreach ($temp_params as $k => $v)
                $context['did_you_mean_params'][] = $k . '|\'|' . $v;
            $context['did_you_mean_params'] = base64_encode(implode('|"|', $context['did_you_mean_params']));
            $context['did_you_mean'] = implode(' ', $did_you_mean['display']);
        }
    }

xenovanis

Before removing anything, I'd suggest seeing if disabling the spellchecker in Admin -> Forum -> Posts and Topics -> Post settings helps.
"Insanity: doing the same thing over and over again and expecting different results."

xtom

Yes disabling the spell check option works, I wasn't even aware it was enabled, thanks. Now if I only thought of this yesterday I could have saved myself a lot of time and trouble :)

xenovanis

Is aspell enabled on your server? Does the spellcheck in posts work for you?
"Insanity: doing the same thing over and over again and expecting different results."

xtom

My phpinfo lists PSpell Support enabled but no mention of aspell. I don't think the spell check works on posts for me either, when I click the spell check button a blank page (that's familiar) in a pop up window appears.

xenovanis

Sorry, I meant pspell.

Probably it's not setup correctly, or, at least not to work with SMF. You might want to try contacting your host about it.
"Insanity: doing the same thing over and over again and expecting different results."

Alex' Manson

i had this and its fixed when i changed to a better host, its a host problem :P

Aleksi "Lex" Kilpinen

Quote from: xtom on October 06, 2010, 04:43:52 AM
Yes disabling the spell check option works, I wasn't even aware it was enabled, thanks. Now if I only thought of this yesterday I could have saved myself a lot of time and trouble :)

Hi, I take it you have been able to find out the cause to your problem, and a way around it - so I'll just mark the topic solved.
If your issue is not solved, and you need further assistance from us - feel free to mark the topic not solved, and update us on the current situation :)
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Advertisement: