/[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 16 - (hide annotations)
Sat Jun 30 12:50:56 2007 UTC (16 years, 10 months ago) by dpavlin
File size: 4256 byte(s)
some instructions
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 15 my $slogovi = $cgi->param( 'slogovi' ) || '';
41     my $stem = $cgi->param( 'stem' ) || '';
42 dpavlin 1
43     my $charset='iso-8859-2';
44    
45 dpavlin 5 my $full_query = $query;
46 dpavlin 14 $full_query .= " " . EPrints->slogovi( $query ) if ($slogovi);
47 dpavlin 8 $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 dpavlin 16 Enter bunch of related terms to documents you are trying to find:
65     <br/><input type="text" name="query" value="$query" size="80">
66     <br/><input type="submit" />
67 dpavlin 8 |, $cgi->checkbox( -name => 'stem' ), $cgi->checkbox( -name => 'slogovi' ), qq|
68 dpavlin 1 </p>\n|;
69    
70    
71    
72     ##########################
73     # Do the actual search
74     ##########################
75     if( $query || $similar ) {
76    
77     # Create collection-based objects
78     my $semantic = Semantic::API::Search->new( storage => 'sqlite',
79     database => "$abs_path/eprints.db",
80     collection => $COLLECTION );
81    
82     my ($results, $terms);
83     if ( $query ) {
84 dpavlin 4 ($results, $terms) = $semantic->semantic_search( $full_query );
85 dpavlin 1 } else {
86     ($results, $terms) = $semantic->find_similar( $similar );
87     }
88    
89 dpavlin 9 warn "results = ",dump( $results ) if $debug;
90     warn "terms = ",dump( $terms ) if $debug;
91 dpavlin 1
92     ##################################
93     # TERM BASED CALCULATIONS
94     ##################################
95     my @sorted_terms = sort { $terms->{$b} <=> $terms->{$a} } keys %$terms;
96     my @top_terms = splice( @sorted_terms, $start, $TERMS_TO_DISPLAY );
97 dpavlin 9
98     warn "top_terms = ", dump( @top_terms ) if $debug;
99    
100 dpavlin 4 print "<p>Full query: $full_query</p>\n";
101 dpavlin 1 print "<p>Related Terms: ". ( join ", ", @top_terms ) ."</p>\n";
102     print "<hr />\n";
103    
104    
105     ##################################
106     # DOCUMENT BASED CALCULATIONS
107     ##################################
108    
109     print "<p>Result Count: ".(scalar keys %$results)."</p>\n";
110    
111     my @sorted_results = sort { $results->{$b} <=> $results->{$a} } keys %$results;
112     my @display_results = splice( @sorted_results, $start, $RESULTS_TO_DISPLAY );
113    
114 dpavlin 9 warn "display results = ", dump( @display_results ) if $debug;
115 dpavlin 1
116     ##################################
117     # Access the storage engine to
118     # retrieve the title and text
119     ##################################
120     my $i = 1 + $start;
121 dpavlin 15 print $semantic->paginate( "?query=$query;similar=$similar;stem=$stem;slogovi=$slogovi", $start, scalar keys %$results, $RESULTS_TO_DISPLAY);
122 dpavlin 1 foreach my $id ( @display_results ){
123     EPrints->id( $id );
124 dpavlin 11 print "<p>$i. <b>", EPrints->lookup( 'title' ), "</b>";
125     print "| score: <em>", sprintf("%.2f",$results->{$id}), "</em> | id: $id | <a href=\"?similar=$id\">similar</a> | ";
126 dpavlin 12 my ($type,$uri) = EPrints->fulltext;
127 dpavlin 11 print qq|<a href="$uri">$type</a>|;
128     print "</p>\n";
129     print "<p>";
130 dpavlin 1 # print $semantic->summarize($id);
131 dpavlin 8 print "</p><p>Keywords: ", EPrints->lookup('keywords'), "</p><p>";
132 dpavlin 1 print "<small>", EPrints->lookup('abstract'), "</small>";
133     print "</p>\n";
134 dpavlin 11 $i++;
135 dpavlin 1 }
136    
137     }
138    
139    
140     print "</body>\n</html>\n";

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26