OSDN Git Service

add 'search in this book' function
authorgn64_jp <gn64@rec10.org>
Sat, 11 May 2013 22:53:51 +0000 (07:53 +0900)
committergn64_jp <gn64@rec10.org>
Sat, 11 May 2013 22:53:51 +0000 (07:53 +0900)
htmlserver.pl
index/pdf2xml.py
pdfsearch.pl
template/desktop_top.tmp.html
template/desktop_viewjpeg.tmp.html
template/mobile_top.tmp.html
template/mobile_viewjpeg.tmp.html

index 9ded371..be16343 100755 (executable)
@@ -70,6 +70,8 @@ $single_pagenum = $pagenum - $dbh2->{'startpage'};
 $pdfpath        = $dbh2->{'id'};
 $jumplink =
 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=";
+$searchlink = 
+"pdfsearch.pl?mode=$mode&width=$width&height=$height&search_text=";
 $bpage = $pagenum - 1;
 $blink =
 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$bpage";
@@ -96,9 +98,11 @@ if ( $mode eq 'mobile' ) {
        $template->param( nlink    => $nlink );
        $template->param( jpegpath => $jpeglink );
        $template->param( jumplink => $jumplink );
+       $template->param( searchlink => $searchlink );
        $template->param( nowpage  => $pagenum );
        $template->param( maxpage  => $multi_maxpage );
        $template->param( homelink => $homelink );
+       #$template->param( title_id => $title_group );
 }
 else {
        $blink   = "$blink";
@@ -114,8 +118,10 @@ else {
        $template->param( n10link  => $n10link );
        $template->param( jpegpath => $jpeglink );
        $template->param( jumplink => $jumplink );
+       $template->param( searchlink => $searchlink );
        $template->param( nowpage  => $pagenum );
        $template->param( maxpage  => $multi_maxpage );
        $template->param( homelink => $homelink );
+       $template->param( title_id => $title_group );
 }
 print $cgi->header( -charset => 'utf-8' ), $template->output;
index 7863d97..54052cf 100644 (file)
@@ -4,6 +4,7 @@
 import commands
 import sys
 import os
+import os.path
 import subprocess
 import codecs
 import time
@@ -14,8 +15,11 @@ import hashlib
 import solr
 import yaml
 import sqlite3
-
 confstr="/etc/libre10.conf"
+if os.path.exists("./libre10.conf"):
+    confstr="./libre10.conf"
+elif os.path.exists("../libre10.conf"):
+    confstr="../libre10.conf"
 conf_dic=yaml.load(open(confstr).read())
 sqlpath=conf_dic['dburl']
 dbcon=sqlite3.connect(sqlpath,isolation_level=None)
index f02fde1..25de0ba 100755 (executable)
@@ -46,6 +46,11 @@ $width  = $q->param("width");
 $height = $q->param("height");
 $start  = $q->param("start");
 $rows   = $q->param("rows");
+$fq_title_row = $q->param("fq_title");
+$fq_genre_row = $q->param("fq_genre");
+$fq_title = uri_unescape($fq_title_row);
+#$fq_title = decode('utf-8',$fq_title);
+$fq_genre = decode('utf-8',uri_unescape($fq_genre_row));
 if ( $start eq "" ) { $start = "0"; }
 if ( $rows  eq "" ) { $rows  = "10"; }
 
@@ -80,9 +85,9 @@ if ( $bstart < 0 ) {
        $bstart = 0;
 }
 $blink =
-"pdfsearch.pl?mode=$mode&search_text=$search_text&width=$width&height=$height&start=$bstart&rows=$rows";
+"pdfsearch.pl?mode=$mode&search_text=$search_text&width=$width&height=$height&start=$bstart&rows=$rows&fq_title=$fq_title_row&fq_genre=$fq_genre_row";
 $nlink =
-"pdfsearch.pl?mode=$mode&search_text=$search_text&width=$width&height=$height&start=$nstart&rows=$rows";
+"pdfsearch.pl?mode=$mode&search_text=$search_text&width=$width&height=$height&start=$nstart&rows=$rows&fq_title=$fq_title_row&fq_genre=$fq_genre_row";
 $template->param( blink => $blink );
 $template->param( nlink => $nlink );
 
@@ -92,25 +97,51 @@ if ( length $search_text > 0 ) {
        $template->param( search_top  => "0" );
        my $query = WebService::Solr::Query->new(
                { text => decode( 'utf-8', $search_text ) } );
+       my %response_query = (
+            'rows'                        => $rows,
+            'start'                       => $start,
+            'group.limit'                 => '30',
+            'group.field'                 => 'title_group',
+            'group'                       => true,
+            'hl'                          => true,
+            'hl.fl'                       => 'text',
+            'hl.simple.pre'               => "<font color=red><em>",
+            'hl.simple.post'              => "</em></font>",
+            'hl.fragsize'                 => '300',
+            'hl.fragmenter'               => 'gap',
+            'hl.alternateField'           => 'text',
+            'hl.maxAlternateFieldLength'  => '300',
+            'hl.useFastVectorHighlighter' => true,
+        );
+       my $fq_title_solr="";
+       if ((length $fq_title > 0) or (length $fq_genre > 0)){
+               $sql = "SELECT title
+                       FROM pdffile 
+                       WHERE title_id = '$fq_title' 
+                       ORDER BY part DESC LIMIT 1";
+               $dbs = $sqldbi->prepare($sql);
+               $dbs->execute();
+               $dbh           = $dbs->fetchrow_hashref;
+               $fq_title_solr = decode('utf-8',$dbh->{'title'});
+               #print Dumper $dbh;
+       }
+       #if ((length $fq_title > 0) and (length $fq_genre > 0)){
+   #   $response_query{'facet'} = "true";
+       #       @fqs = ('title_group:$fq_title_solr','genre:$fq_genre');
+       #       $response_query{'fq'} = [@fqs];
+       if (length $fq_title > 0){
+               $response_query{'fq'}="title_group:\"$fq_title_solr\"";
+       }
+       if (length $fq_genre > 0){
+               $response_query{'facet'} = "true";
+        @fqs = ('genre:' . $fq_genre,);
+        $response_query{'fq'} = [@fqs];
+       }
+       #print Dumper %response_query;
        my $response = $solr->search(
-               $query,
-               {
-                       'rows'                        => $rows,
-                       'start'                       => $start,
-                       'group.limit'                 => '30',
-                       'group.field'                 => 'title_group',
-                       'group'                       => true,
-                       'hl'                          => true,
-                       'hl.fl'                       => 'text',
-                       'hl.simple.pre'               => "<font color=red><em>",
-                       'hl.simple.post'              => "</em></font>",
-                       'hl.fragsize'                 => '300',
-                       'hl.fragmenter'               => 'gap',
-                       'hl.alternateField'           => 'text',
-                       'hl.maxAlternateFieldLength'  => '300',
-                       'hl.useFastVectorHighlighter' => true,
-               }
+               $query,\%response_query
        );
+       #print Dumper $response;
 
        my $hits               = $response->content;
        my %hits               = %$hits;
index 222d326..61338ab 100644 (file)
@@ -53,7 +53,7 @@
                                .click(function(){
                        window.location.href="<TMPL_VAR NAME="nlink">";
             });
-                       $("#blink_footer").button({
+                       $("#blinkF").button({
                 label:"back",
                 icons:{
                     primary:"ui-icon-circle-triangle-w"
@@ -62,7 +62,7 @@
                 .click(function(){
                     window.location.href="<TMPL_VAR NAME="blink">";
             });
-            $("#settings_footer").button({
+            $("#settingsF").button({
                 label:"Settings",
                 icons:{
                     primary:"ui-icon-gear"
@@ -70,7 +70,7 @@
                 })
                 .click(function(){
             });
-            $("#login_footer").button({
+            $("#loginF").button({
                 label:"Login",
                 icons:{
                     primary:"ui-icon-key"
@@ -78,7 +78,7 @@
                 })
                 .click(function(){
             });
-                       $("#nlink_footer").button({
+                       $("#nlinkF").button({
                 label:"next",
                 icons:{
                     primary:"ui-icon-circle-triangle-e"
                        </TMPL_LOOP>
                <div align="center">
             <div id="toolbar" class="ui-corner-all">
-                <button id="blink_footer"></button>
-                <button id="settings_footer" disabled></button>
-                <button id="login_footer" disabled></button>
-                <button id="nlink_footer"></button>
+                <button type="button" id="blinkF"></button>
+                <button type="button" id="settingsF" disabled></button>
+                <button type="button" id="loginF" disabled></button>
+                <button type="button" id="nlinkF"></button>
             </div>
         </div>
                </TMPL_IF>
index c9311d5..f9df71f 100644 (file)
                                modal:true,
                                title:"Search"
                        });
+                       $("#search").button({
+                               label:"検索",
+                               icons:{
+                                       primary:"ui-icon-search"
+                                       }
+                               })
+                               .click(function(){
+                                       $("#search_dialog").dialog('open');
+                       });
+                       $("#search_button").button({
+                               label:"検索",
+                               icons:{
+                                       primary:"ui-icon-search"
+                                       }
+                               })
+                               .click(function(){
+                                       var selected = $("#search_radio :radio:checked").attr('id');
+                                       if (selected == 'search_all'){
+                                               var search_link="<TMPL_VAR NAME="homelink">"+"&search_text="+$("#search_text").val();
+                                               window.location.href=search_link;
+                                       }else{
+                                               var search_link="<TMPL_VAR NAME="homelink">"+"&search_text="+$("#search_text").val()+"&fq_title=<TMPL_VAR NAME="title_id">";
+                                               window.location.href=search_link;
+                                       }
+                       });
+                       $("#search_text").bind('keypress',function(e){
+                       if(e.keyCode == 13){
+                       var selected = $("#search_radio :radio:checked").attr('id');
+                       if (selected == 'search_all'){
+                               var search_link="<TMPL_VAR NAME="homelink">"+"&search_text="+$("#search_text").val();
+                           window.location.href=search_link;
+                       }else{
+                               var search_link="<TMPL_VAR NAME="homelink">"+"&search_text="+$("#search_text").val()+"&fq_title=<TMPL_VAR NAME="title_id">";
+                           window.location.href=search_link;
+                       }       
+                       }
+               });
                        $("#jump_dialog").dialog({
                                autoOpen:false,
                                //height:140,
                                modal:true,
                                title:"移動 (<TMPL_VAR NAME="nowpage">/<TMPL_VAR NAME="maxpage">)"
                        });
+                       $("#jump").button({
+                               label:"移動",
+                               icons:{
+                                       primary:"ui-icon-arrowreturnthick-1-n"
+                                       }
+                               })
+                               .click(function(){
+                                       $("#jump_dialog").dialog('open');
+                       });
+                       $("#jump_button").button({
+                               label:"移動",
+                               icons:{
+                                       primary:"ui-icon-arrowreturnthick-1-n"
+                                       }
+                               })
+                               .click(function(){
+                                       var jump_link="<TMPL_VAR NAME="jumplink">"+$("#jump_num").val();
+                                       window.location.href=jump_link;
+                       });
+                       $("#jump_num").bind('keypress',function(e){
+                       if(e.keyCode == 13){
+                       if ($('#jump_num').val().length > 0){
+                               var jump_link="<TMPL_VAR NAME="jumplink">"+$("#jump_num").val();
+                                               window.location.href=jump_link;
+                       }
+                       }
+               });
                        $("#b10link").button({
                                label:"-10頁",
                                icons:{
                 .click(function(){
                     window.location.href="<TMPL_VAR NAME="blink">";
             });
-                       $("#search").button({
-                               label:"検索",
-                               icons:{
-                                       primary:"ui-icon-search"
-                                       }
-                               })
-                               .click(function(){
-                                       $("#search_dialog").dialog('open');
-                       });
-                       $("#search_button").button({
-                               label:"検索",
-                               icons:{
-                                       primary:"ui-icon-search"
-                                       }
-                               })
-                               .click(function(){
-                                       var selected = $("#search_radio :radio:checked").attr('id');
-                                       if (selected == 'search_all'){
-                                               var search_link="<TMPL_VAR NAME="homelink">"+"&search_text="+$("#search_text").val();
-                                               window.location.href=search_link;
-                                       }
-                                       //alert($("#search_radio :radio:checked").attr('id'));
-                       });
-                       $("#jump").button({
-                               label:"移動",
-                               icons:{
-                                       primary:"ui-icon-arrowreturnthick-1-n"
-                                       }
-                               })
-                               .click(function(){
-                                       $("#jump_dialog").dialog('open');
-                       });
-                       $("#jump_button").button({
-                               label:"移動",
-                               icons:{
-                                       primary:"ui-icon-arrowreturnthick-1-n"
-                                       }
-                               })
-                               .click(function(){
-                                       var jump_link="<TMPL_VAR NAME="jumplink">"+$("#jump_num").val();
-                                       window.location.href=jump_link;
-                                       //alert($("#search_radio :radio:checked").attr('id'));
-                       });
+                       
+                       
                        $("#index").button({
                                label:"目次",
                                icons:{
                        <div id="search_radio">
                                <input type="radio" id="search_all" checked="checked" name="radio"/>
                                <label for="search_all">全体から</label>
-                               <input type="radio" id="search_this" name="radio" disabled/>
+                               <input type="radio" id="search_this" name="radio" />
                                <label for="search_this">本書から</label>
                        </div>
                        <br>
index 288cb92..16cd57f 100644 (file)
@@ -49,7 +49,7 @@
     </div>
 </div> 
 <div data-role="content" id='top'>
-    <input type='search' name='search_text' id='search-text' value='' /> 
+    <input type='search' name='search_text' id='search-text' value='<TMPL_VAR NAME="text">' /> 
     <label><button type="submit" data-theme="b" id="submit" name="submit">検索</button></label>
     <TMPL_IF NAME="show_result">
         <div data-role="collapsible-set" data-theme="c" data-content-theme="d">
index 7b799f5..0669d2e 100644 (file)
                 //$.mobile.changePage('<TMPL_VAR NAME="blink">',{transition:'slide'});
             });
                        $('div.ui-input-search').bind('keypress',function(e){
+              //console.log("test");
                                if(e.keyCode == 13){
+                //console.log("test");
                 if ($('#search-text').val().length > 0){
-                    $.mobile.changePage("pdfsearch.pl?mode=&width=&height=&search_text=\"" + $('#search-text').val() + "\"",{transition:'slide'});
+                    var txt=$('#search-text').val();
+                    $('#search-text').val("");
+                    $.mobile.changePage("<TMPL_VAR NAME="searchlink">" + txt ,{transition:'slide'});
                 }
                                }
                        });
+            $('#jumpPagenum').bind('keypress',function(e){
+                if(e.keyCode == 13){
+                    if($('#jumpPagenum').val().length > 0){
+                        var jnum=$('#jumpPagenum').val();
+                        $('#jumpPagenum').val("");
+                        $.mobile.changePage("<TMPL_VAR NAME="jumplink">"+jnum,{transition:'slidedown'});
+                    
+                    }
+                }
+            });
                        $('#jumpPage').bind("click",function(e,ui){
-                               $.mobile.changePage("<TMPL_VAR NAME="jumplink">"+$('#jumpPagenum').val(),{transition:'slidedown'});
+                if($('#jumpPagenum').val().length > 0){
+                    var jnum=$('#jumpPagenum').val();
+                    $('#jumpPagenum').val("");
+                    $.mobile.changePage("<TMPL_VAR NAME="jumplink">"+jnum,{transition:'slidedown'});
+                    
+                }
                        });
             $.mobile.loadPage("<TMPL_VAR NAME="nlink">",{showLoadMsg: false});
             $.mobile.loadPage("<TMPL_VAR NAME="blink">",{showLoadMsg: false});
@@ -71,6 +90,7 @@
                <h1>page move dialog</h1>
        </div>
        <div data-role='content'>
+    <TMPL_VAR NAME="nowpage"> / <TMPL_VAR NAME="maxpage">
                <p><input type='number' id='jumpPagenum' value='' />
                <div data-role='button' id='jumpPage'>移動</div>
                </p>