Skip to content

Instantly share code, notes, and snippets.

@SebDeclercq
Created May 21, 2012 13:38
Show Gist options
  • Save SebDeclercq/2762377 to your computer and use it in GitHub Desktop.
Save SebDeclercq/2762377 to your computer and use it in GitHub Desktop.
#! /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>
@SebDeclercq
Copy link
Author

DOESN'T WORK:

  1. Problem with the interaction between articles & laws in template #TO_SOLVE
  2. Don't match every query #WHY ?!

@SebDeclercq
Copy link
Author

OK with 2.

@SebDeclercq
Copy link
Author

Ugly but works \o/

@SebDeclercq
Copy link
Author

less ugly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment