表紙 | 新規 | 編集 | 編集 | 差分 | 一覧 | RSS | 検索 | 閲覧履歴 | 作成履歴 | 更新履歴

do_searchresult関数 - YukiWikiベースのPonyWikiのソースを読んでみる その11

YukiWikiベースのPonyWikiのソースを読んでみる その11

検索機能の中心部。

処理の流れは以下の通り。

sub do_searchresult {
	my ($argword,$keyopt,$loop_cnt)  = @_;
	my $counter = 0;
	my $html;
	my %name_list; my %mod_list; my %access_list;
	my $sortopt;

	my $word;
	my @words;
	my @tmpwords;
	my $page_hit_cnt;

	$argword =~ s|"|"|g;
	for (my $cnt = 0; $argword =~ s/"([^"]*)"//; $cnt++){
		$words[$cnt] = $1;
	}
	$argword =~ s|^\s||;
	@tmpwords = split(/\s+/, $argword);
	@words = (@words, @tmpwords);
	if(!@words){
		return undef;
	}

	&open_search_index;
	for (my $i=0; $i < @search_index; $i++){
		my $index_data = $search_index[$i];
		chomp $index_data;
		next if $index_data =~ /^$[[FrontPage]]\t/;
		next if $index_data =~ /^\Q$form{mypage}\E\t/;
		
		my ($page,$idx_contents,$idx_subject,$mtime) = split(/\t/,$index_data);
		
		
		for (my $cnt=0,$page_hit_cnt=0; $cnt < @words; $cnt++) {
			$word = $words[$cnt];
			if ($idx_contents =~ /\Q$word\E/i or $page =~ /\Q$word\E/i) {
				$page_hit_cnt++;
			}
		}
	
# For debug
#		$html .= "$page  A$idx_subject B  C$mtime D".'<BR>';
	
		if($page_hit_cnt == @words){
			$name_list{$page} = &escape($idx_subject);
			$mod_list{$page} = $mtime;
			if($keyopt =~ /ACC/i) { $access_list{$page} = &get_info($page, $info_UniqAccessCount); }
			$counter++;
		}
	}
	&close_search_index;
	
	if ($counter == 0) {
		$html .= "";
	} else {
		$html .= qq|<ul>|;
	
		if ($keyopt eq 'NAM+') {		# Sort Order by PageName
			$sortopt = 'sort keys %name_list';
		} elsif ($keyopt eq 'MOD+') {	# Sort Order by LastMod
			$sortopt = 'sort {$mod_list{$a} <=> $mod_list{$b} or $a cmp $b} keys %mod_list';
		} elsif ($keyopt eq 'SBJ+') {	# Sort Order by Subject
			$sortopt = 'sort {$name_list{$a} cmp $name_list{$b} or $a cmp $b} keys %name_list';
		} elsif ($keyopt eq 'ACC+' or $keyopt eq 'acc+' ) {	# Sort Order by Access Count
			$sortopt = 'sort {$access_list{$a} <=> $access_list{$b} or $a cmp $b} keys %access_list';
		
		} elsif ($keyopt eq 'NAM-') {	# Sort Order by PageName DESC
			$sortopt = 'sort { $b cmp $a } keys %name_list';
		} elsif ($keyopt eq 'MOD-') {	# Sort Order by LastMod DESC
			$sortopt = 'sort {$mod_list{$b} <=> $mod_list{$a} or $b cmp $a} keys %mod_list';
		} elsif ($keyopt eq 'SBJ-') {	# Sort Order by Subject DESC
			$sortopt = 'sort {$name_list{$b} cmp $name_list{$a} or $b cmp $a} keys %name_list';
		} elsif ($keyopt eq 'ACC-' or $keyopt eq 'acc-' ) {	# Sort Order by Access Count
			$sortopt = 'sort {$access_list{$b} <=> $access_list{$a} or $b cmp $a} keys %access_list';
		
		} else {						# Sort Order by DEFAULT
			$sortopt = 'sort keys %name_list';
		}
		
		foreach my $page (eval $sortopt) {
			if ($keyopt =~ /\Qacc\E/) {
				$html .= qq(<li><a href ="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}   $access_list{$page}access.</li>\n); 
			} else {
				$html .= qq(<li><a href ="$url_cgi?@{[&encode($page)]}">@{[&escape($page)]}</a>@{[&escape(&get_subjectline($page))]}</li>\n); 
			}
			$loop_cnt = $loop_cnt -1;
			if ($loop_cnt == 0) {last;}
		}
		$html .= qq|</ul>|;
	}
	
# For debug
#	$html .= join("<br>",@words);
	
	return $html;
}


''TrackBack'' - http://you-like.to/cgi-bin/ponytail/yukiwiki/wiki.cgi/do_searchresult%b4%d8%bf%f4

先頭へ