/[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

Contents of /EPrints/search.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (show annotations)
Sat Jun 30 12:50:56 2007 UTC (16 years, 9 months ago) by dpavlin
File size: 4256 byte(s)
some instructions
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 use lib '/home/dpavlin/stem-hr/';
19 use StemHR;
20
21 my $debug = 1;
22
23 my $abs_path = abs_path( $0 );
24 $abs_path =~ s!/[^/]*$!/!; #!fix-vim
25
26 #############################################################
27 my $COLLECTION = 'EPrints';
28 my ( @TERMS, @RESULTS );
29 my ( $RESULTS_TO_DISPLAY, $TERMS_TO_DISPLAY ) = ( 20, 20 );
30 #############################################################
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 my $slogovi = $cgi->param( 'slogovi' ) || '';
41 my $stem = $cgi->param( 'stem' ) || '';
42
43 my $charset='iso-8859-2';
44
45 my $full_query = $query;
46 $full_query .= " " . EPrints->slogovi( $query ) if ($slogovi);
47 $full_query .= " " . StemHR->stem( $query ) if ($stem);
48
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 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 |, $cgi->checkbox( -name => 'stem' ), $cgi->checkbox( -name => 'slogovi' ), qq|
68 </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 ($results, $terms) = $semantic->semantic_search( $full_query );
85 } else {
86 ($results, $terms) = $semantic->find_similar( $similar );
87 }
88
89 warn "results = ",dump( $results ) if $debug;
90 warn "terms = ",dump( $terms ) if $debug;
91
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
98 warn "top_terms = ", dump( @top_terms ) if $debug;
99
100 print "<p>Full query: $full_query</p>\n";
101 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 warn "display results = ", dump( @display_results ) if $debug;
115
116 ##################################
117 # Access the storage engine to
118 # retrieve the title and text
119 ##################################
120 my $i = 1 + $start;
121 print $semantic->paginate( "?query=$query;similar=$similar;stem=$stem;slogovi=$slogovi", $start, scalar keys %$results, $RESULTS_TO_DISPLAY);
122 foreach my $id ( @display_results ){
123 EPrints->id( $id );
124 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 my ($type,$uri) = EPrints->fulltext;
127 print qq|<a href="$uri">$type</a>|;
128 print "</p>\n";
129 print "<p>";
130 # print $semantic->summarize($id);
131 print "</p><p>Keywords: ", EPrints->lookup('keywords'), "</p><p>";
132 print "<small>", EPrints->lookup('abstract'), "</small>";
133 print "</p>\n";
134 $i++;
135 }
136
137 }
138
139
140 print "</body>\n</html>\n";

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26