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

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26