Beispiel #1
0
function validate_search_word($word, $idx)
{
    static $stopwords;
    // If the word is a keyword we don't want to index it, but we do want to be allowed to search it
    if (is_keyword($word)) {
        return !$idx;
    }
    if (!isset($stopwords)) {
        if (file_exists(FORUM_CACHE_DIR . 'cache_stopwords.php')) {
            include FORUM_CACHE_DIR . 'cache_stopwords.php';
        }
        if (!defined('FORUM_STOPWORDS_LOADED')) {
            if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) {
                require FORUM_ROOT . 'include/cache.php';
            }
            generate_stopwords_cache();
            require FORUM_CACHE_DIR . 'cache_stopwords.php';
        }
    }
    // If it is a stopword it isn't valid
    if (in_array($word, $stopwords)) {
        return false;
    }
    // If the word is CJK we don't want to index it, but we do want to be allowed to search it
    if (is_cjk($word)) {
        return !$idx;
    }
    // Exclude % and * when checking whether current word is valid
    $word = str_replace(array('%', '*'), '', $word);
    // Check the word is within the min/max length
    $num_chars = luna_strlen($word);
    return $num_chars >= FORUM_SEARCH_MIN_WORD && $num_chars <= FORUM_SEARCH_MAX_WORD;
}
function validate_search_word($word, $idx)
{
    global $cache;
    static $stopwords;
    // If the word is a keyword we don't want to index it, but we do want to be allowed to search it
    if (is_keyword($word)) {
        return !$idx;
    }
    if (!isset($stopwords)) {
        $cache_id = generate_stopwords_cache_id();
        $stopwords = $cache->get('stopwords.' . $cache_id);
        if ($stopwords === Flux_Cache::NOT_FOUND) {
            $stopwords = array();
            $d = dir(PUN_ROOT . 'lang');
            while (($entry = $d->read()) !== false) {
                if ($entry[0] == '.') {
                    continue;
                }
                if (is_dir(PUN_ROOT . 'lang/' . $entry) && file_exists(PUN_ROOT . 'lang/' . $entry . '/stopwords.txt')) {
                    $stopwords = array_merge($stopwords, file(PUN_ROOT . 'lang/' . $entry . '/stopwords.txt'));
                }
            }
            $d->close();
            // Tidy up and filter the stopwords
            $stopwords = array_map('pun_trim', $stopwords);
            $stopwords = array_filter($stopwords);
            $cache->set('stopwords.' . $cache_id, $stopwords);
        }
    }
    // If it is a stopword it isn't valid
    if (in_array($word, $stopwords)) {
        return false;
    }
    // If the word if CJK we don't want to index it, but we do want to be allowed to search it
    if (is_cjk($word)) {
        return !$idx;
    }
    // Exclude % and * when checking whether current word is valid
    $word = str_replace(array('%', '*'), '', $word);
    // Check the word is within the min/max length
    $num_chars = pun_strlen($word);
    return $num_chars >= PUN_SEARCH_MIN_WORD && $num_chars <= PUN_SEARCH_MAX_WORD;
}