#topicpath
**概要 [#x5bac883]
単語検索で空白文字を含むフレーズ検索を可能にします。~
'' ' ''または'' " ''で括られた文字列はフレーズとして扱うようになります。
**差分((1.4.5_1ベース((1.4.4or1.4.6_rcでもほぼ同じ場所の書き換えで対応可能なようです。)))) [#dee156e3]
--- func.org.php Sun Feb 20 12:50:06 2005
+++ func.php Sat Jul 16 12:38:34 2005
@@ -171,6 +171,13 @@
return $retval;
}
+function split_search_word($word)
+{
+ $matches = array();
+ preg_match_all('/((["\'])(?:(?!\2).)+\2|[^\s]+)/', $word, $matches);
+ return preg_replace('/^(["\'])(.+)\1$/', '$2', $matches[1]);
+}
+
// 'Search' main function
function do_search($word, $type = 'AND', $non_format = FALSE)
{
@@ -181,7 +188,7 @@
$retval = array();
$b_type = ($type == 'AND'); // AND:TRUE OR:FALSE
- $keys = get_search_words(preg_split('/\s+/', $word, -1, PREG_SPLIT_NO_EMPTY));
+ $keys = get_search_words(split_search_word($word));
$_pages = get_existpages();
$pages = array();
--- html.org.php Wed Jan 26 13:26:38 2005
+++ html.php Sat Jul 16 12:37:00 2005
@@ -113,9 +113,7 @@
if ($search_word_color && isset($vars['word'])) {
$body = '<div class="small">' . $_msg_word . htmlspecialchars($vars['word']) .
'</div>' . $hr . "\n" . $body;
- $words = array_flip(array_splice(
- preg_split('/\s+/', $vars['word'], -1, PREG_SPLIT_NO_EMPTY),
- 0, 10));
+ $words = array_flip(array_splice(split_search_word($vars['word']), 0, 10));
$keys = array();
foreach ($words as $word=>$id) $keys[$word] = strlen($word);
arsort($keys, SORT_NUMERIC);
**コメント [#n9aae2f2]
-有りそうで無かったみたいなので弄ってみました。文字列の分割(split_search_word)で、もっと簡潔なコーディングを思いつかれた方はぜひお寄せください。 -- [[Cue]] &new{2005-07-16 (土) 13:31:15};
- いしだたみいしだたみ -- &new{2007-01-21 (日) 17:34:14};
#comment