Skip to content

Commit

Permalink
Allow searches only by nick again
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Aug 20, 2014
1 parent 595523b commit 5c42854
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 14 additions & 8 deletions lib/Ilbot/Backend/Search.pm
Expand Up @@ -197,24 +197,30 @@ sub _index_timestamp {
sub _query {
my ($self, %opt) = @_;
die "Missing argument 'q'" unless defined $opt{q};
my $query = Lucy::Search::QueryParser->new(
schema => $self->_searcher->get_schema,
)->parse($opt{q});
my @criteria;
if (length $opt{q}) {
push @criteria, Lucy::Search::QueryParser->new(
schema => $self->_searcher->get_schema,
)->parse($opt{q});
}
if (length $opt{nick}) {
my $q_nick = Lucy::Search::TermQuery->new(
push @criteria, Lucy::Search::TermQuery->new(
field => 'nick',
term => lc($opt{nick}),
);
$query = Lucy::Search::ANDQuery->new(
children => [$query, $q_nick],
}
if (@criteria > 1) {
return Lucy::Search::ANDQuery->new(
children => \@criteria,
);
}
return $query;
else {
return $criteria[0];
}
}

sub search_results {
my ($self, %opt) = @_;
die "Missing argument 'q'" unless defined $opt{q};
my $s = $self->_searcher;
my $q = $self->_query(%opt);
my $offset = $opt{offset} // 0;
Expand Down
4 changes: 1 addition & 3 deletions lib/Ilbot/Frontend.pm
Expand Up @@ -341,15 +341,13 @@ sub search {
my $c = 0;
my $prev_nick = q[!!!];
my $line_number = 0;
if (defined $opt{q} && length $opt{q}) {
if (length $opt{q} || length $opt{nick}) {
my $res = $b->search_results(
nick => $opt{nick},
q => $opt{q},
offset => $opt{offset} // 0,
);
if (my $ts = $res->{index_timestamp}) {
use Data::Dumper;
print Dumper $ts;
my ($sec, $min, $hour, $day, $mon, $year) = mytime($ts);
my $date = sprintf '%04d-%02d-%02d %02d:%02d H',
$year + 1900, $mon + 1, $day, $hour, $min;
Expand Down

0 comments on commit 5c42854

Please sign in to comment.