15 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
16 |
use EPrints; |
use EPrints; |
17 |
use Cwd qw/abs_path/; |
use Cwd qw/abs_path/; |
18 |
|
use KinoSearch::Simple; |
19 |
use lib '/home/dpavlin/stem-hr/'; |
use lib '/home/dpavlin/stem-hr/'; |
20 |
use StemHR; |
use StemHR; |
21 |
|
|
40 |
my $similar = $cgi->param( 'similar' ) || ''; |
my $similar = $cgi->param( 'similar' ) || ''; |
41 |
my $slogovi = $cgi->param( 'slogovi' ) || ''; |
my $slogovi = $cgi->param( 'slogovi' ) || ''; |
42 |
my $stem = $cgi->param( 'stem' ) || ''; |
my $stem = $cgi->param( 'stem' ) || ''; |
43 |
|
my $kino = $cgi->param( 'kino' ); |
44 |
|
|
45 |
my $charset='iso-8859-2'; |
my $charset='iso-8859-2'; |
46 |
|
|
81 |
database => "$abs_path/eprints.db", |
database => "$abs_path/eprints.db", |
82 |
collection => $COLLECTION ); |
collection => $COLLECTION ); |
83 |
|
|
84 |
|
my $score_ponder; |
85 |
|
|
86 |
my ($results, $terms); |
my ($results, $terms); |
87 |
if ( $query ) { |
if ( $query ) { |
88 |
($results, $terms) = $semantic->semantic_search( $full_query ); |
($results, $terms) = $semantic->semantic_search( $full_query ); |
89 |
|
|
90 |
|
my $kino = KinoSearch::Simple->new( |
91 |
|
path => 'kinoindex/', |
92 |
|
language => 'ru', |
93 |
|
); |
94 |
|
|
95 |
|
my $total_hits = $kino->search( |
96 |
|
query => $query, |
97 |
|
offset => 0, |
98 |
|
num_wanted => 10, |
99 |
|
); |
100 |
|
|
101 |
|
print qq|<div style="width:20%; float:right;">KinoSearch hits $total_hits for $query\n<ol>|; |
102 |
|
while ( my $hit = $kino->fetch_hit_hashref ) { |
103 |
|
print qq|<li><a href="#id_$hit->{id}">$hit->{title}</a> $hit->{score}</li>\n|; |
104 |
|
$score_ponder->{ $hit->{id} } = $hit->{score}; |
105 |
|
} |
106 |
|
print qq|</ol></div>|; |
107 |
|
|
108 |
} else { |
} else { |
109 |
($results, $terms) = $semantic->find_similar( $similar ); |
($results, $terms) = $semantic->find_similar( $similar ); |
110 |
} |
} |
115 |
################################## |
################################## |
116 |
# TERM BASED CALCULATIONS |
# TERM BASED CALCULATIONS |
117 |
################################## |
################################## |
118 |
my @sorted_terms = sort { $terms->{$b} <=> $terms->{$a} } keys %$terms; |
my @sorted_terms = sort { |
119 |
|
my ( $sb, $sa ) = ( $terms->{$b}, $terms->{$a} ); |
120 |
|
$sb *= $score_ponder->{$b} if $score_ponder->{$b}; |
121 |
|
$sa *= $score_ponder->{$a} if $score_ponder->{$a}; |
122 |
|
$sb <=> $sa; |
123 |
|
} keys %$terms; |
124 |
my @top_terms = splice( @sorted_terms, $start, $TERMS_TO_DISPLAY ); |
my @top_terms = splice( @sorted_terms, $start, $TERMS_TO_DISPLAY ); |
125 |
|
|
126 |
warn "top_terms = ", dump( @top_terms ) if $debug; |
warn "top_terms = ", dump( @top_terms ) if $debug; |
149 |
print $semantic->paginate( "?query=$query;similar=$similar;stem=$stem;slogovi=$slogovi", $start, scalar keys %$results, $RESULTS_TO_DISPLAY); |
print $semantic->paginate( "?query=$query;similar=$similar;stem=$stem;slogovi=$slogovi", $start, scalar keys %$results, $RESULTS_TO_DISPLAY); |
150 |
foreach my $id ( @display_results ){ |
foreach my $id ( @display_results ){ |
151 |
EPrints->id( $id ); |
EPrints->id( $id ); |
152 |
print "<p>$i. <b>", EPrints->lookup( 'title' ), "</b>"; |
print "<p><a name=\"id_$id\"/>$i. <b>", EPrints->lookup( 'title' ), "</b>"; |
153 |
print "| score: <em>", sprintf("%.2f",$results->{$id}), "</em> | id: $id | <a href=\"?similar=$id\">similar</a> | "; |
print "| score: <em>", sprintf("%.2f",$results->{$id}), "</em> | id: $id | <a href=\"?similar=$id\">similar</a> | "; |
154 |
my ($type,$uri) = EPrints->fulltext; |
my ($type,$uri) = EPrints->fulltext; |
155 |
print qq|<a href="$uri">$type</a>|; |
print qq|<a href="$uri">$type</a>|; |