Exemple #1
0
 /**
  * キーワードを設定する
  *
  * @param string $word
  * @return void
  */
 public function setWord($word)
 {
     global $_conf;
     if (is_string($word) && strlen($word) > 0) {
         if ($this->method == 'regex' && substr_count($word, '.') == strlen($word)) {
             $word_fm = null;
         } else {
             $word_fm = StrCtl::wordForMatch($word, $this->method);
             if (strlen($word_fm) == 0) {
                 $word_fm = null;
             } elseif ($this->method == self::METHOD_JUST || $this->method == self::METHOD_REGEX) {
                 $words_fm = array($word_fm);
             } elseif (P2_MBREGEX_AVAILABLE == 1) {
                 $word_fm = mb_ereg_replace('\\s+', '|', $word_fm);
                 $words_fm = mb_split('\\s+', $word_fm);
             } else {
                 $word_fm = preg_replace('/\\s+/', '|', $word_fm);
                 $words_fm = preg_split('/\\s+/', $word_fm);
             }
         }
     } else {
         $word_fm = null;
     }
     if ($word_fm !== null) {
         $this->word = $word;
         $this->_word_fm = $word_fm;
         $this->_words_fm = $words_fm;
         $this->_words_num = count($words_fm);
     } else {
         $this->word = null;
         $this->_word_fm = null;
         $this->_words_fm = null;
         $this->_words_num = 0;
     }
 }
Exemple #2
0
$GLOBALS['word'] = geti($_POST['word'], geti($_GET['word']));
$GLOBALS['word_fm'] = null;
if (strlen($GLOBALS['word'])) {
    // デフォルトオプション
    if (empty($GLOBALS['res_filter']['field'])) {
        $GLOBALS['res_filter']['field'] = "whole";
    }
    if (empty($GLOBALS['res_filter']['match'])) {
        $GLOBALS['res_filter']['match'] = "on";
    }
    if (empty($GLOBALS['res_filter']['method'])) {
        $GLOBALS['res_filter']['method'] = "or";
    }
    if (!($GLOBALS['res_filter']['method'] == 'regex' && preg_match('/^\\.+$/', $GLOBALS['word']))) {
        require_once P2_LIB_DIR . '/StrCtl.php';
        $GLOBALS['word_fm'] = StrCtl::wordForMatch($GLOBALS['word'], $GLOBALS['res_filter']['method']);
        if ($GLOBALS['res_filter']['method'] != 'just') {
            if (P2_MBREGEX_AVAILABLE == 1) {
                $GLOBALS['words_fm'] = mb_split('\\s+', $GLOBALS['word_fm']);
                $GLOBALS['word_fm'] = mb_ereg_replace('\\s+', '|', $GLOBALS['word_fm']);
            } else {
                $GLOBALS['words_fm'] = preg_split('/\\s+/', $GLOBALS['word_fm']);
                $GLOBALS['word_fm'] = preg_replace('/\\s+/', '|', $GLOBALS['word_fm']);
            }
            $GLOBALS['word_fm'] = '(?:' . $GLOBALS['word_fm'] . ')';
        }
    }
    if (UA::isK() || UA::isIPhoneGroup()) {
        $filter_page = isset($_REQUEST['filter_page']) ? max(1, intval($_REQUEST['filter_page'])) : 1;
        $_filter_range = array();
        $_filter_range['start'] = ($filter_page - 1) * $_conf['k_rnum_range'] + 1;
Exemple #3
0
// $GLOBALS['word'] などの検索語の取り扱いがどさくさなのは、できれば整理したいところ...
$GLOBALS['word_fm'] = null;
if (isset($GLOBALS['word']) && strlen($GLOBALS['word']) > 0) {
    // デフォルトオプション
    if (empty($res_filter['field'])) {
        $res_filter['field'] = "hole";
    }
    if (empty($res_filter['match'])) {
        $res_filter['match'] = "on";
    }
    if (empty($res_filter['method'])) {
        $res_filter['method'] = "or";
    }
    if (!($res_filter['method'] == 'regex' && preg_match('/^\\.+$/', $GLOBALS['word']))) {
        require_once P2_LIB_DIR . '/strctl.class.php';
        $GLOBALS['word_fm'] = StrCtl::wordForMatch($word, $res_filter['method']);
        if ($res_filter['method'] != 'just') {
            if (P2_MBREGEX_AVAILABLE == 1) {
                $GLOBALS['words_fm'] = mb_split('\\s+', $GLOBALS['word_fm']);
                $GLOBALS['word_fm'] = mb_ereg_replace('\\s+', '|', $GLOBALS['word_fm']);
            } else {
                $GLOBALS['words_fm'] = preg_split('/\\s+/', $GLOBALS['word_fm']);
                $GLOBALS['word_fm'] = preg_replace('/\\s+/', '|', $GLOBALS['word_fm']);
            }
        }
    }
    if ($_conf['ktai']) {
        $filter_page = isset($_REQUEST['filter_page']) ? max(1, intval($_REQUEST['filter_page'])) : 1;
        $filter_range = array();
        $filter_range['start'] = ($filter_page - 1) * $_conf['k_rnum_range'] + 1;
        $filter_range['to'] = $filter_range['start'] + $_conf['k_rnum_range'] - 1;
Exemple #4
0
/**
 * クエリーからフィルタワードをセットする
 *
 * @return  void
 */
function _setFilterWord()
{
    global $_conf, $sb_filter;
    $sb_filter = array();
    $sb_filter['method'] = null;
    $GLOBALS['word'] = null;
    $GLOBALS['word_fm'] = null;
    $GLOBALS['wakati_word'] = null;
    // 「更新」ではなくて、検索指定があれば
    if (empty($_REQUEST['submit_refresh']) or !empty($_REQUEST['submit_kensaku'])) {
        if (isset($_GET['word'])) {
            $GLOBALS['word'] = $_GET['word'];
        } elseif (isset($_POST['word'])) {
            $GLOBALS['word'] = $_POST['word'];
        }
        if (isset($_GET['method'])) {
            $sb_filter['method'] = $_GET['method'];
        } elseif (isset($_POST['method'])) {
            $sb_filter['method'] = $_POST['method'];
        }
        if (isset($sb_filter['method']) and $sb_filter['method'] == 'similar') {
            $GLOBALS['wakati_word'] = $GLOBALS['word'];
            $GLOBALS['wakati_words'] = _wakati($GLOBALS['word']);
            if (!$GLOBALS['wakati_words']) {
                unset($GLOBALS['wakati_word'], $GLOBALS['wakati_words']);
            } else {
                require_once P2_LIB_DIR . '/StrCtl.php';
                $wakati_words2 = array_filter($GLOBALS['wakati_words'], '_wakatiFilter');
                if (!$wakati_words2) {
                    $GLOBALS['wakati_hl_regex'] = $GLOBALS['wakati_word'];
                } else {
                    rsort($wakati_words2, SORT_STRING);
                    $GLOBALS['wakati_hl_regex'] = implode(' ', $wakati_words2);
                    $GLOBALS['wakati_hl_regex'] = mb_convert_encoding($GLOBALS['wakati_hl_regex'], 'SJIS-win', 'UTF-8');
                }
                $GLOBALS['wakati_hl_regex'] = StrCtl::wordForMatch($GLOBALS['wakati_hl_regex'], 'or');
                $GLOBALS['wakati_hl_regex'] = str_replace(' ', '|', $GLOBALS['wakati_hl_regex']);
                $GLOBALS['wakati_length'] = mb_strlen($GLOBALS['wakati_word'], 'SJIS-win');
                $GLOBALS['wakati_score'] = _getSbScore($GLOBALS['wakati_words'], $GLOBALS['wakati_length']);
                if (!isset($_conf['expack.min_similarity'])) {
                    $_conf['expack.min_similarity'] = 0.05;
                } elseif ($_conf['expack.min_similarity'] > 1) {
                    $_conf['expack.min_similarity'] /= 100;
                }
                if (count($GLOBALS['wakati_words']) == 1) {
                    $_conf['expack.min_similarity'] /= 100;
                }
                $_conf['expack.min_similarity'] = (double) $_conf['expack.min_similarity'];
            }
            $GLOBALS['word'] = '';
        } elseif (preg_match('/^\\.+$/', $GLOBALS['word'])) {
            $GLOBALS['word'] = '';
        }
        if (strlen($GLOBALS['word'])) {
            // デフォルトオプション
            if (!$sb_filter['method']) {
                $sb_filter['method'] = "or";
            }
            // $sb_filter は global @see sb_print.icn.php
            require_once P2_LIB_DIR . '/StrCtl.php';
            $GLOBALS['word_fm'] = StrCtl::wordForMatch($GLOBALS['word'], $sb_filter['method']);
            if ($sb_filter['method'] != 'just') {
                if (P2_MBREGEX_AVAILABLE == 1) {
                    $GLOBALS['words_fm'] = mb_split('\\s+', $GLOBALS['word_fm']);
                    $GLOBALS['word_fm'] = mb_ereg_replace('\\s+', '|', $GLOBALS['word_fm']);
                } else {
                    $GLOBALS['words_fm'] = preg_split('/\\s+/', $GLOBALS['word_fm']);
                    $GLOBALS['word_fm'] = preg_replace('/\\s+/', '|', $GLOBALS['word_fm']);
                }
            }
        }
    }
}
Exemple #5
0
/**
 * p2_wakati()の結果等、キーワードの配列からハイライト用の正規表現を生成する
 *
 * @param   array $words
 * @return  string
 */
function p2_get_highlighting_regex(array $words)
{
    $featured_words = array_filter($words, '_p2_get_highlighting_regex_filter');
    if (count($featured_words) == 0) {
        $featured_words = $words;
    }
    //rsort($featured_words, SORT_STRING);
    $pattern = mb_convert_encoding(implode(' ', $featured_words), 'SJIS-win', 'UTF-8');
    return str_replace(' ', '|', StrCtl::wordForMatch($pattern, 'or'));
}
Exemple #6
0
 /**
  * 板検索(スレタイ検索)のwordクエリーがあればパースする
  * $GLOBALS['word'], $GLOBALS['words_fm'], $GLOBALS['word_fm'] をセットする
  *
  * @static
  * @access  public
  * @return  void
  */
 function parseWord()
 {
     $GLOBALS['word'] = null;
     $GLOBALS['words_fm'] = null;
     $GLOBALS['word_fm'] = null;
     if (isset($_GET['word'])) {
         $word = $_GET['word'];
     } elseif (isset($_POST['word'])) {
         $word = $_POST['word'];
     }
     if (!isset($word) || strlen($word) == 0) {
         return;
     }
     /*
     // 特別に除外する条件
     // 何でもマッチしてしまう正規表現
     if (preg_match('/^\.+$/', $word)) {
         return;
     }
     */
     require_once P2_LIB_DIR . '/StrCtl.php';
     // and検索でよろしく(正規表現ではない)
     $word_fm = StrCtl::wordForMatch($word, 'and');
     if (P2_MBREGEX_AVAILABLE == 1) {
         $GLOBALS['words_fm'] = mb_split('\\s+', $word_fm);
         $GLOBALS['word_fm'] = mb_ereg_replace('\\s+', '|', $word_fm);
     } else {
         $GLOBALS['words_fm'] = preg_split('/\\s+/', $word_fm);
         $GLOBALS['word_fm'] = preg_replace('/\\s+/', '|', $word_fm);
     }
     $GLOBALS['word'] = $word;
 }