Initial search support. Only ASCII characters
This commit is contained in:
parent
fa55cd636b
commit
1235bfe0de
36
II/DB.pm
36
II/DB.pm
@ -2,6 +2,8 @@ package II::DB;
|
||||
|
||||
use SQL::Abstract;
|
||||
use DBI;
|
||||
use Encode;
|
||||
use utf8;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
@ -49,6 +51,7 @@ sub begin {
|
||||
$dbh->do('BEGIN');
|
||||
}
|
||||
|
||||
# Commit transaction
|
||||
sub commit {
|
||||
my ($self) = @_;
|
||||
my $dbh = $self->{_dbh};
|
||||
@ -332,4 +335,37 @@ sub select_new {
|
||||
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;
|
||||
|
22
II/Render.pm
22
II/Render.pm
@ -263,4 +263,26 @@ sub new_mes {
|
||||
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;
|
||||
|
@ -175,3 +175,17 @@ margin-bottom: 0%;
|
||||
margin-left: 45%;
|
||||
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;
|
||||
}
|
@ -15,4 +15,10 @@
|
||||
<b>[</b> <a href="/out">неотправленные сообщения</a> <b>]</b> 
|
||||
</p>
|
||||
</div>
|
||||
<div class='search'>
|
||||
<form action='/search' method='POST'>
|
||||
<input type='text' name='q'><br>
|
||||
<input type='submit' value='Искать'>
|
||||
</form>
|
||||
</div>
|
||||
<!-- <hr> -->
|
||||
|
Loading…
Reference in New Issue
Block a user