Initial search support. Only ASCII characters

This commit is contained in:
Difrex(Denis Zheleztsov) 2014-08-12 11:25:20 +04:00
parent fa55cd636b
commit 1235bfe0de
4 changed files with 78 additions and 0 deletions

View File

@ -2,6 +2,8 @@ package II::DB;
use SQL::Abstract; use SQL::Abstract;
use DBI; use DBI;
use Encode;
use utf8;
use Data::Dumper; use Data::Dumper;
@ -49,6 +51,7 @@ sub begin {
$dbh->do('BEGIN'); $dbh->do('BEGIN');
} }
# Commit transaction
sub commit { sub commit {
my ($self) = @_; my ($self) = @_;
my $dbh = $self->{_dbh}; my $dbh = $self->{_dbh};
@ -332,4 +335,37 @@ sub select_new {
return $data; return $data;
} }
# Search
sub do_search {
my ( $self, $query ) = @_;
my $dbh = $self->{_dbh};
# $query = $query;
print "QUERY " . $query . "\n";
my $q
= "select from_user, to_user, subg, time, echo, post, hash from messages where subg like '\%$query\%' order by time";
my $sth = $dbh->prepare($q);
$sth->execute();
my @posts;
while ( my @hash = $sth->fetchrow_array() ) {
my ( $from, $to, $subg, $time, $echo, $post, $h ) = @hash;
my $data = {
from => "$from",
to => "$to",
subg => "$subg",
time => $time,
echo => "$echo",
post => "$post",
hash => "$h",
};
push( @posts, $data );
}
return @posts;
}
1; 1;

View File

@ -263,4 +263,26 @@ sub new_mes {
return $render; return $render;
} }
# Search results
sub search {
my ( $self, @post ) = @_;
my $t = $self->{_template};
# Render header
my $render
= $t->head(
"ii " . $config->{name} . " :: Результаты поиска" );
my $count = 0;
while ( $count < @post ) {
# Render post
$render .= $t->post( @post[$count] );
$count++;
}
$render .= $t->foot();
return $render;
}
1; 1;

View File

@ -175,3 +175,17 @@ margin-bottom: 0%;
margin-left: 45%; margin-left: 45%;
margin-right: 55%; margin-right: 55%;
} }
/* Search */
.search {
position: fixed;
top: 2em;
left: 0.5em;
opacity: 0.4;
transition-duration: 0.5s;
-webkit-transition-duration: 0.5s;
}
.search:hover {
opacity: 1;
transition-duration: 0.5s;
-webkit-transition-duration: 0.5s;
}

View File

@ -15,4 +15,10 @@
<b>[</b> <a href="/out">неотправленные сообщения</a> <b>]</b>&nbsp <b>[</b> <a href="/out">неотправленные сообщения</a> <b>]</b>&nbsp
</p> </p>
</div> </div>
<div class='search'>
<form action='/search' method='POST'>
<input type='text' name='q'><br>
<input type='submit' value='Искать'>
</form>
</div>
<!-- <hr> --> <!-- <hr> -->