SPECIAL_CHARS = array("ー", "-", "ー", "-", "。", ",", "、", " ", " ", "/", "/", "・", "・", ",", ",", ".", "゙", "゚"); //エスケープ対象文字set $this->ESC_CHARS = array("<", ">", "&", "~", "^", "'", '"', "\\", "*", "+", "?", "{", "}", "(", ")", "$", "|", "."); //あいまい検索用文字列set $this->SEARCH_CHAR = array( array("0","0"), array("1","1"), array("2","2"), array("3","3"), array("4","4"), array("5","5"), array("6","6"), array("7","7"), array("8","8"), array("9","9"), array("a","a","A","A"), array("b","b","B","B"), array("c","c","C","C"), array("d","d","D","D"), array("e","e","E","E"), array("f","f","F","F"), array("g","g","G","G"), array("h","h","H","H"), array("i","i","I","I"), array("j","j","J","J"), array("k","k","K","K"), array("l","l","L","L"), array("m","m","M","M"), array("n","n","N","N"), array("o","o","O","O"), array("p","p","P","P"), array("q","q","Q","Q"), array("r","r","R","R"), array("s","s","S","S"), array("t","t","T","T"), array("u","u","U","U"), array("v","v","V","V"), array("w","w","W","W"), array("x","x","X","X"), array("y","y","Y","Y"), array("z","z","Z","Z"), array("あ","ぁ","ア","ァ","ア","ァ"), array("い","ゐ","ぃ","イ","イ","ィ","ィ","ヰ"), array("う","ぅ","ウ","ゥ","ウ","ゥ"), array("え","ゑ","ぇ","エ","エ","ヱ","ェ","ェ"), array("お","ぉ","を","オ","ォ","ヲ","オ","ォ","ヲ"), array("か","カ","が","ガ","ヵ","カ","ガ"), array("き","キ","ぎ","ギ","キ","ギ"), array("く","ク","ぐ","グ","ク","グ"), array("け","ケ","げ","ゲ","ヶ","ケ","ゲ"), array("こ","コ","ご","ゴ","コ","ゴ"), array("さ","ざ","サ","サ","ザ"), array("し","じ","シ","シ","ジ","ヂ","ぢ","ヂ"), array("す","ず","ス","ス","ズ","づ","ヅ"), array("せ","ぜ","セ","セ","ゼ"), array("そ","ぞ","ソ","ソ","ゾ"), array("た","だ","タ","タ","ダ"), array("ち","ぢ","チ","チ","ヂ","ジ","じ","ジ"), array("つ","づ","ず","っ","ず","ツ","ツ","ヅ","ヅ","ズ","ズ","ッ","ッ"), array("て","で","テ","テ","デ"), array("と","ど","ト","ト","ド"), array("な","ナ","ナ"), array("に","ニ","ニ"), array("ぬ","ヌ","ヌ"), array("ね","ネ","ネ"), array("の","ノ","ノ"), array("は","ふぁ","ハ","ハ","ファ","ファ"), array("ひ","ふぃ","ヒ","ヒ","フィ","フィ"), array("ふ","フ","フ"), array("へ","ふぇ","ヘ","ヘ","フェ","フェ"), array("ほ","ふぉ","ホ","ホ","フォ","フォ"), array("ば","バ","バ","ヴぁ","ヴァ","ヴァ"), array("び","ビ","ビ","ヴぃ","ヴィ","ヴィ"), array("ぶ","ブ","ブ","ヴ","ヴ"), array("べ","ベ","ベ","ヴぇ","ヴェ","ヴェ"), array("ぼ","ボ","ボ","ヴぉ","ヴォ","ヴォ"), array("ぱ","パ","パ"), array("ぴ","ピ","ピ"), array("ぷ","プ","プ"), array("ぺ","ペ","ペ"), array("ぽ","ポ","ポ"), array("ま","マ","マ"), array("み","ミ","ミ"), array("む","ム","ム"), array("め","メ","メ"), array("も","モ","モ"), array("や","ゃ","ヤ","ヤ","ャ","ャ"), array("ゆ","ゅ","ユ","ユ","ュ","ュ"), array("よ","ょ","ヨ","ヨ","ョ","ョ"), array("ら","ラ","ラ"), array("り","リ","リ"), array("る","ル","ル"), array("れ","レ","レ"), array("ろ","ロ","ロ"), array("わ","ゎ","ワ","ワ","ヮ"), // array("わ","ゎ","ワ","ワ","ヮ",""), array("ん","ン","ン")); $this->INDEX50_CHAR = array( 'a' => 'あ', 'i' => 'い', 'u' => 'う', 'e' => 'え', 'o' => 'お', 'ka' => '(か|が)', 'ki' => '(き|ぎ)', 'ku' => '(く|ぐ)', 'ke' => '(け|げ)', 'ko' => '(こ|ご)', 'sa' => '(さ|ざ)', 'si' => '(し|じ)', 'su' => '(す|ず)', 'se' => '(せ|ぜ)', 'so' => '(そ|ぞ)', 'ta' => '(た|だ)', 'ti' => '(ち|ぢ)', 'tu' => '(つ|づ)', 'te' => '(て|で)', 'to' => '(と|ど)', 'na' => 'な', 'ni' => 'に', 'nu' => 'ぬ', 'ne' => 'ね', 'no' => 'の', 'ha' => '(は|ば|ぱ)', 'hi' => '(ひ|び|ぴ)', 'hu' => '(ふ|ぶ|ぷ)', 'he' => '(へ|べ|ぺ)', 'ho' => '(ほ|ぼ|ぽ)', 'ma' => 'ま', 'mi' => 'み', 'mu' => 'む', 'me' => 'め', 'mo' => 'も', 'ya' => 'や', 'yu' => 'ゆ', 'yo' => 'よ', 'ra' => 'ら', 'ri' => 'り', 'ru' => 'る', 're' => 'れ', 'ro' => 'ろ', 'wa' => 'わ', 'num' => '[0-9]', 'alpha' => '[a-zA-Z]'); $this->PERSON_CHAR = array( 1 => 'エルヴィス・プレスリー', 2 => 'オードリー・ヘプバーン', 3 => 'スティーブン・スピルバーグ', 4 => 'トム・クルーズ', 5 => 'リュック・ベッソン', 6 => 'ジョン・トラボルタ', 7 => 'リチャード・ギア', 8 => 'エディ・マーフィ', 9 => 'スティーヴ・マックィーン', 10 => 'ジョン・ウェイン', 11 => 'ジェリー・ルイス', 12 => 'ジム・ジャームッシュ'); } // 曖昧検索用文字列作成 public function make_matching_string($str) { // 1文字ずつバラす $tmpArray = $this->mbStringToArray($str); $tmpStr = ''; foreach ($tmpArray as $tmp) { $tmpStr .= "("; //省略可能文字が見つかった場合 if (in_array($tmp, $this->SPECIAL_CHARS) == true) { // $tmpStr .= implode("", $this->SPECIAL_CHARS); //エスケープ対象文字が見つかった場合 } elseif (in_array($tmp,$this->ESC_CHARS) == true) { $tmpStr .= "\\" . $tmp; //あいまい検索用文字列作成 } else { $flg_in=0; foreach ($this->SEARCH_CHAR as $tmpchararrs) { if ($flg_in == 0) { if (in_array($tmp, $tmpchararrs)) { $flg_in = 1; $tmpStr .= implode("|", $tmpchararrs); } } } if ($flg_in == 0) { $tmpStr .= $tmp; } } $tmpStr .= ")"; $tmpStr .= "((".implode("|", $this->SPECIAL_CHARS).")*)"; } // $logger = new Logger('search'); // $logger->logWrite($tmpStr); return $tmpStr; } //マルチバイト文字列を1文字ずつ配列に入れる public function mbStringToArray($str, $sEnc = 'UTF-8') { $tmpArray = array(); while ($iLen = mb_strlen($str, $sEnc)) { array_push($tmpArray, mb_substr($str, 0, 1, $sEnc)); $str = mb_substr($str, 1, $iLen, $sEnc); } return $tmpArray; } public function getIndex50SearchText($str) { return (isset($this->INDEX50_CHAR[$str])) ? $this->INDEX50_CHAR[$str] : ''; } public function getPersonList() { return $this->PERSON_CHAR; } public function getPersonText2id($id) { return (isset($this->PERSON_CHAR[$id])) ? $this->PERSON_CHAR[$id] : ''; } }