/[Semantic-Engine]/EPrints/search.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /EPrints/search.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9 - (hide annotations)
Fri Jun 29 15:29:55 2007 UTC (16 years, 10 months ago) by dpavlin
File size: 4035 byte(s)
dump STDERR output with $debug = 1
1 dpavlin 1 #!/usr/bin/perl -w
2    
3    
4     ######################################
5     #
6     # A simple search engine program
7     #
8     ######################################
9    
10    
11     use strict;
12     use CGI::Carp qw(fatalsToBrowser);
13     use Semantic::API;
14     use CGI;
15     use Data::Dump qw/dump/;
16     use EPrints;
17     use Cwd qw/abs_path/;
18 dpavlin 8 use lib '/home/dpavlin/stem-hr/';
19     use StemHR;
20 dpavlin 1
21 dpavlin 9 my $debug = 1;
22    
23 dpavlin 1 my $abs_path = abs_path( $0 );
24     $abs_path =~ s!/[^/]*$!/!; #!fix-vim
25    
26     #############################################################
27     my $COLLECTION = 'EPrints';
28     my ( @TERMS, @RESULTS );
29 dpavlin 5 my ( $RESULTS_TO_DISPLAY, $TERMS_TO_DISPLAY ) = ( 20, 20 );
30 dpavlin 1 #############################################################
31    
32    
33     ###############################
34     # CGI Variables
35     ###############################
36     my $cgi = new CGI;
37     my $start = $cgi->param( 'start' ) || 0;
38     my $query = $cgi->param( 'query' ) || '';
39     my $similar = $cgi->param( 'similar' ) || '';
40 dpavlin 5 my $slogovi = $cgi->param( 'slogovi' );
41 dpavlin 8 my $stem = $cgi->param( 'stem' );
42 dpavlin 1
43     my $charset='iso-8859-2';
44    
45 dpavlin 5 my $full_query = $query;
46 dpavlin 8 $full_query .= " " . EPrints::slogovi( $query ) if ($slogovi);
47     $full_query .= " " . StemHR->stem( $query ) if ($stem);
48 dpavlin 1
49     ##############################
50     # Start the HTML output
51     ##############################
52     print "Content-type: text/html; charset=$charset\n\n";
53     print qq|<?xml version="1.0" encoding="$charset"?>
54     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
55     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
56     <html xmlns="http://www.w3.org/1999/xhtml">
57     <head>
58     <meta http-equiv="content-type" content="text/html; charset=$charset" />
59     <title>Search Engine</title>
60     </head>
61     <body>
62     <form method="get" action="">
63     <p>
64     <input type="text" name="query" value="$query" />
65     <input type="submit" />
66 dpavlin 8 |, $cgi->checkbox( -name => 'stem' ), $cgi->checkbox( -name => 'slogovi' ), qq|
67 dpavlin 1 </p>\n|;
68    
69    
70    
71     ##########################
72     # Do the actual search
73     ##########################
74     if( $query || $similar ) {
75    
76     # Create collection-based objects
77     my $semantic = Semantic::API::Search->new( storage => 'sqlite',
78     database => "$abs_path/eprints.db",
79     collection => $COLLECTION );
80    
81     my ($results, $terms);
82     if ( $query ) {
83 dpavlin 4 ($results, $terms) = $semantic->semantic_search( $full_query );
84 dpavlin 1 } else {
85     ($results, $terms) = $semantic->find_similar( $similar );
86     }
87    
88 dpavlin 9 warn "results = ",dump( $results ) if $debug;
89     warn "terms = ",dump( $terms ) if $debug;
90 dpavlin 1
91     ##################################
92     # TERM BASED CALCULATIONS
93     ##################################
94     my @sorted_terms = sort { $terms->{$b} <=> $terms->{$a} } keys %$terms;
95     my @top_terms = splice( @sorted_terms, $start, $TERMS_TO_DISPLAY );
96 dpavlin 9
97     warn "top_terms = ", dump( @top_terms ) if $debug;
98    
99 dpavlin 4 print "<p>Full query: $full_query</p>\n";
100 dpavlin 1 print "<p>Related Terms: ". ( join ", ", @top_terms ) ."</p>\n";
101     print "<hr />\n";
102    
103    
104     ##################################
105     # DOCUMENT BASED CALCULATIONS
106     ##################################
107    
108     print "<p>Result Count: ".(scalar keys %$results)."</p>\n";
109    
110     my @sorted_results = sort { $results->{$b} <=> $results->{$a} } keys %$results;
111     my @display_results = splice( @sorted_results, $start, $RESULTS_TO_DISPLAY );
112    
113 dpavlin 9 warn "display results = ", dump( @display_results ) if $debug;
114 dpavlin 1
115     ##################################
116     # Access the storage engine to
117     # retrieve the title and text
118     ##################################
119     my $i = 1 + $start;
120     print $semantic->paginate( "?query=$query;similar=$similar", $start, scalar keys %$results, $RESULTS_TO_DISPLAY);
121     foreach my $id ( @display_results ){
122     EPrints->id( $id );
123 dpavlin 8 print "<p>$i. <b>", EPrints->lookup( 'title' ), "</b>";
124     print "$id <em>", sprintf("%.2f",$results->{$id}), "</em> <a href=\"?similar=$id\">similar</a></p>\n";
125 dpavlin 1 print "<p>";
126     # print $semantic->summarize($id);
127 dpavlin 8 print "</p><p>Keywords: ", EPrints->lookup('keywords'), "</p><p>";
128 dpavlin 1 print "<small>", EPrints->lookup('abstract'), "</small>";
129     print "</p>\n";
130     $i++;
131     }
132    
133     }
134    
135    
136     print "</body>\n</html>\n";

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26