/[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 1 - (show annotations)
Fri Jun 29 09:08:58 2007 UTC (16 years, 10 months ago) by dpavlin
File size: 3447 byte(s)
EPrints indexer and searcher for Semantic-Engine
at http://www.hirank.com/semantic-indexing-project/index.html

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

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26