Created
May 21, 2012 13:38
-
-
Save SebDeclercq/2762377 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl -w | |
use strict; | |
use warnings; | |
package My::LawDB::Schema; | |
use base qw(DBIx::Class::Schema::Loader); | |
package main; | |
use Dancer ':syntax'; | |
use Dancer::Plugin::DBIC; | |
use Template; | |
use feature 'say'; | |
my $schema = My::LawDB::Schema->connect('dbi:SQLite:dbname=LawDB.db.bak'); | |
my $query = 'préjudice'; | |
my @articles = $schema->resultset('ArticleIdx')->search({content => {match => $query}}); | |
my @lawids; | |
foreach $_ (@articles) { | |
push (@lawids,$_->get_column('lawid')); | |
} | |
my @laws; | |
foreach $_ (@lawids) { | |
@laws = $schema->resultset('Law')->search({id => $_}); | |
} | |
my $tt = Template->new(); | |
$tt->process(\*DATA, {laws => \@laws, | |
articles => \@articles, | |
}) or die $tt->error(); | |
__END__ | |
<html> | |
<head><title>Search results</title></head> | |
<body> | |
[% IF articles.size %] | |
<h2>Results found !</h2> | |
[% FOREACH law IN laws %] | |
<h3>[% law.title %]</h3> | |
[% FOREACH article IN articles %] | |
[% IF (law.id = article.lawid) %] | |
<p><b>[% article.numord %]</b>[% article.content %]</p> | |
[% END %] | |
[% END %] | |
[% END %] | |
[% ELSE %] | |
<h2>No result found</h2> | |
[% END %] | |
</body> | |
</html> |
OK with 2.
Ugly but works \o/
less ugly
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DOESN'T WORK: