r1770@llin: dpavlin | 2009-04-21 23:06:28 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 21 Apr 2009 21:06:31 +0000 (21:06 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 21 Apr 2009 21:06:31 +0000 (21:06 +0000)
 skeleton of web-based database searcher using simple CGI

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@1132 07558da8-63fa-0310-ba24-9fe276d99e06

vhost/ecas/config.yml [new file with mode: 0644]
vhost/ecas/ovid.pl [new file with mode: 0755]
vhost/style.css [new file with mode: 0644]
vhost/webpac2.cgi [new file with mode: 0755]

diff --git a/vhost/ecas/config.yml b/vhost/ecas/config.yml
new file mode 100644 (file)
index 0000000..5dd7e7f
--- /dev/null
@@ -0,0 +1,54 @@
+vhost:
+  name: 'Katalog elektronièkih èasopisa'
+  description: 'dostupnih u zbirkama nabavljenim za potrebe visoko¹kolskih i znanstvenih ustanova Republike Hrvatske'
+
+  databases: 'Zbirke'
+
+  no_results: 'nema rezultata'
+
+#  fields:
+#    - issn: 'ISSN'
+#    - naslov: 'Naslov'
+#
+#  operators:
+#    - STRINC: 'Bilo koja rijeè'
+#    - STRBW: 'Poèetak naslova'
+#    - STREQ: 'Cijeli naslov'
+#
+
+use_indexer: 'hyperestraier'
+
+hyperestraier:
+  masterurl: 'http://localhost:1978'
+  user: 'admin'
+  passwd: 'admin'
+  
+  # number of results on each page
+  hits_on_page: 10
+  # number of results to fetch for suggestion (it will fold multiple sameones)
+  hits_for_suggest: 20
+  # which tag type to use for search engine (used while indexing)
+  type: 'search'
+  #
+
+kinosearch:
+  index_path: 'var/kinosearch/ecas'
+  # clean database before opening? (WARNING: this erases existing database)
+  clean: 1
+  # which field type to index?
+  type: 'search'
+
+databases:
+  ecas:
+    name: 'Katalog elektronièkih èasopisa'
+    description: 'dostupnih u zbirkama nabavljenim za potrebe visoko¹kolskih i znanstvenih ustanova Republike Hrvatske'
+    input:
+      - name: 'Ovid FullText'
+        module: 'WebPAC::Input::Ovid'
+        path: '/data/webpac2/t/data/ovid-cites.txt'
+        encoding: 'iso-8859-1'
+        normalize:
+          path: 'vhost/ecas/ovid.pl'
+    output:
+      - module: 'Excel'
+        path: 'out/ovid.xls'
diff --git a/vhost/ecas/ovid.pl b/vhost/ecas/ovid.pl
new file mode 100755 (executable)
index 0000000..63cab81
--- /dev/null
@@ -0,0 +1,4 @@
+
+search( 'naslov', rec('Journal Subset') );
+search( 'issn',   rec('ISSN') );
+
diff --git a/vhost/style.css b/vhost/style.css
new file mode 100644 (file)
index 0000000..0608e54
--- /dev/null
@@ -0,0 +1,49 @@
+body {
+       margin: 3em;
+       font-family: Verdana, Arial, Helvetica, sans-serif;
+       background: #fff;
+       color: #369;
+}
+
+h1 {
+       font-size: 150%;
+       color: #008;
+}
+
+#description {
+       font-size: 80%;
+}
+
+form {
+       margin: 2em;
+}
+
+form label,
+form input {
+       float: left;
+}
+
+form input[name=search] {
+       clear: left;
+}
+
+#results {
+       clear: left;
+       float: left;
+}
+
+#results label {
+       width: 10em;
+       float: left;
+}
+
+pre {
+       border-top: 1px solid #888;
+       clear: left;
+       background-color: #eee;
+}
+
+.error {
+       background-color: #fcc;
+       font-color: 000;
+}
diff --git a/vhost/webpac2.cgi b/vhost/webpac2.cgi
new file mode 100755 (executable)
index 0000000..8127935
--- /dev/null
@@ -0,0 +1,85 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use CGI qw/:standard/;
+use CGI::Carp qw/fatalsToBrowser/;
+use File::Slurp;
+use YAML;
+use Search::Estraier;
+
+print header;
+
+sub dump_yaml {
+       print qq|<pre>|, YAML::Dump( @_ ), qq|</pre>|;
+}
+
+my $path = $ENV{PATH_INFO};
+my $dir = $0;
+$dir =~ s{/[^/]+.cgi}{};
+
+my $config = YAML::LoadFile( "$dir/$path/config.yml" );
+
+my $database = (keys %{ $config->{databases} })[0];
+die "$database not in $path" unless $path =~ m{\Q$database\E};
+
+my $estraier = YAML::LoadFile( "$dir/../var/estraier/$database.yaml" );
+
+my $db = $config->{databases}->{$database};
+
+my @attr = keys %{ $estraier->{attr} }; # FIXME replace with real gnerated lookup
+
+print
+       start_html(
+               -title => $db->{name},
+               -style => '../../style.css',
+       ),
+       h1( $db->{name} ),
+       qq|<div id=description>|, $db->{description}, qq|</div>|,
+       start_form,
+               radio_group(
+                       -name => 'attr',
+                       -values => [ 'issn', 'naslov' ],
+#                      -linebreak => 0,
+               ),
+               textfield( -name => 'search' ),
+               submit
+;
+
+print  end_form;
+
+if ( my $search = param('search') ) {
+
+       print qq|<div id="results">search: $search|;
+
+       my $node = Search::Estraier::Node->new(
+               url => $config->{hyperestraier}->{masterurl} . '/node/' . $database,
+               croak_on_error => 1,
+       );
+
+       my $cond = Search::Estraier::Condition->new;
+       $cond->set_phrase( $search );
+       my $nres = $node->search( $cond, 0 );
+
+       if ( ! $nres ) {
+               my $no_results = "No results for search '%s'";
+               printf qq|<div class="error">$no_results</a>|, $search;
+       } else {
+               print qq|<ul>|;
+               foreach my $i ( 1 .. $nres->doc_num ) {
+                       my $rdoc = $nres->get_doc( $i - 1 );
+                       print qq|<li>|;
+                       print qq|<div><label>$_</label><span class=$_>|, $rdoc->attr( $_ ), qq|</span></div>|
+                               foreach @attr;
+                       print qq|</li>\n|;
+               }
+               print qq|</ul>|;
+       }
+       print qq|</div>|;
+}
+
+dump_yaml( $estraier );
+dump_yaml( $db );
+
+print  end_html;