1 ############################################################
3 # ¸¡º÷¤ò¼Â¹Ô¤·¤Æ·ë²Ì¤òɽ¼¨¤¹¤ë¥¢¥¯¥·¥ç¥ó¥×¥é¥°¥¤¥ó
7 ############################################################
8 package plugin::search::SearchHandler;
10 #===========================================================
12 #===========================================================
16 return bless $self,$class;
19 #===========================================================
21 #===========================================================
25 my $cgi = $wiki->get_CGI;
26 my $word = Util::trim($cgi->param("word"));
29 my $or_search = $cgi->param('t') eq 'or';
30 my $with_content = $cgi->param('c') eq 'true';
32 $wiki->set_title("¸¡º÷");
33 $buf .= "<form method=\"GET\" action=\"".$wiki->create_url()."\">\n".
34 "¥¡¼¥ï¡¼¥É <input type=\"text\" name=\"word\" size=\"20\" value=\"".&Util::escapeHTML($word)."\"> ";
36 $buf .= "<input type=\"radio\" name=\"t\" id=\"and\" value=\"and\"";
37 $buf .= " checked" if (not $or_search);
38 $buf .= "><label for=\"and\">AND</label>\n";
39 $buf .= "<input type=\"radio\" name=\"t\" id=\"or\" value=\"or\"";
40 $buf .= " checked" if ($or_search);
41 $buf .= "><label for=\"or\">OR</label>\n";
42 $buf .= "<input type=\"checkbox\" id=\"contents\" name=\"c\" value=\"true\"";
43 $buf .= " checked" if ($with_content);
44 $buf .= "><label for=\"contents\">¥Ú¡¼¥¸ÆâÍƤâ´Þ¤á¤ë</label>\n";
46 $buf .= "<input type=\"submit\" value=\" ¸¡ º÷ \">".
47 "<input type=\"hidden\" name=\"action\" value=\"SEARCH\">".
51 my $conv_upper_case = ($ignore_case and $word =~ /[A-Za-z]/);
52 $word = uc $word if ($conv_upper_case);
53 my @words = grep { $_ ne '' } split(/ +|¡¡+/, $word);
54 return $buf unless (@words);
55 #---------------------------------------------------------------------------
57 my @list = $wiki->get_page_list({-permit=>'show'});
60 foreach my $name (@list){
61 # ¥Ú¡¼¥¸Ì¾¤â¸¡º÷Âоݤˤ¹¤ë
63 $page .= "\n".$wiki->get_page($name) if ($with_content);
64 my $pageref = ($conv_upper_case) ? \(my $page2 = uc $page) : \$page;
68 # OR¸¡º÷ -------------------------------------------------------
71 next WORD if (($index = index $$pageref, $_) == -1);
73 "<a href=\"".$wiki->create_page_url($name)."\">".Util::escapeHTML($name)."</a>".
75 Util::escapeHTML(&get_match_content($wiki, $page, $index)).
80 # AND¸¡º÷ ------------------------------------------------------
83 next PAGE if (($index = index $$pageref, $_) == -1);
86 "<a href=\"".$wiki->create_page_url($name)."\">".Util::escapeHTML($name)."</a>".
88 Util::escapeHTML(&get_match_content($wiki, $page, $index)).
92 return "$buf<ul>\n$res</ul>\n" if ($res ne '');
96 #===========================================================
97 # ¸¡º÷¤Ë¥Þ¥Ã¥Á¤·¤¿¹Ô¤ò¼è¤ê½Ð¤¹´Ø¿ô
98 #===========================================================
99 sub get_match_content {
104 # ¸¡º÷¤Ë¥Þ¥Ã¥Á¤·¤¿¹Ô¤ÎÀèƬʸ»ú¤Î°ÌÃÖ¤òµá¤á¤ë¡£
105 # ¡¦$content ¤Î $index ÈÖÌܤÎʸ»ú¤«¤éÀèƬÊý¸þ¤Ë²þ¹Ôʸ»ú¤òõ¤¹¡£
106 # ¡¦$index ¤Î°ÌÃÖ¤ò´Þ¤à¹Ô¤ÎÀèƬʸ»ú¤Î°ÌÃ֤ϲþ¹Ôʸ»ú¤Î¼¡¤Ê¤Î¤Ç +1 ¤¹¤ë¡£
107 # ¡¦ÀèƬÊý¸þ¤Ë²þ¹Ôʸ»ú¤¬Ìµ¤«¤Ã¤¿¤éºÇ½é¤Î¹Ô¤Ê¤Î¤Ç¡¢·ë²Ì¤Ï 0(ÀèƬ)¡£
108 # (¸«¤Ä¤«¤é¤Ê¤¤¤È rindex() = -1 ¤Ë¤Ê¤ë¤Î¤Ç¡¢+1 ¤·¤Æ¤Á¤ç¤¦¤É 0)
109 my $pre_index = rindex($content, "\n", $index) + 1;
111 # ¸¡º÷¤Ë¥Þ¥Ã¥Á¤·¤¿¹Ô¤ÎËöÈøʸ»ú¤Î°ÌÃÖ¤òµá¤á¤ë¡£
112 # ¡¦$content ¤Î $index ÈÖÌܤÎʸ»ú¤«¤éËöÈøÊý¸þ¤Ë²þ¹Ôʸ»ú¤òõ¤¹¡£
113 my $post_index = index($content, "\n", $index);
115 # ËöÈøÊý¸þ¤Ë²þ¹Ôʸ»ú¤¬¤Ê¤«¤Ã¤¿¤éºÇ½ª¹Ô¤Ê¤Î¤Ç $pre_index °Ê¹ßÁ´¤Æ¤òÊֵѡ£
116 return substr($content, $pre_index) if ($post_index == -1);
118 # ¸«¤Ä¤«¤Ã¤¿²þ¹Ôʸ»ú¤Ë¶´¤Þ¤ì¤¿Ê¸»úÎó¤òÊֵѡ£
119 return substr($content, $pre_index, $post_index - $pre_index);