diff options
-rw-r--r-- | static/style.css | 10 | ||||
-rw-r--r-- | templates/search.html | 25 | ||||
-rw-r--r-- | web.py | 7 |
3 files changed, 26 insertions, 16 deletions
diff --git a/static/style.css b/static/style.css index dec9982..0a036ed 100644 --- a/static/style.css +++ b/static/style.css @@ -22,11 +22,17 @@ div#footer { div.book { } -div.book img.frontpage { +div.book div.c_frontpage { width: 260px; height: 390px; - border: 1px solid gray; float: left; + border: 1px solid gray; +} + +div.book div.c_frontpage img.frontpage { + border: 1px solid black; + overflow-x: hidden; + overflow-y: visible; } div.book div.c_matches, diff --git a/templates/search.html b/templates/search.html index d4e8590..b99c053 100644 --- a/templates/search.html +++ b/templates/search.html @@ -1,31 +1,34 @@ {% extends "_base.html" %} {% block title %} - {% if term != "" %} - {{ term }} - {% else %} - Start a new Search - {% endif %} + {% if term: %}{{ term }}{% else %}Start a new Search{% endif %} {% endblock %} {% block searchValue %}{{ term }}{% endblock %} {% block javascript %} <script> jQuery(document).ready(function() { - var acc = jQuery("div.matches").accordion({active:false}); + // createa accordion for all books + var acc = jQuery("div.book div.matches").accordion({active:false, autoHeight:false}); + // accordion change handler acc.bind('accordionchangestart', function(event, ui) { var docnum = ui.newContent.find("p.docnum").text(); var term = ui.newContent.find("p.term").text(); + /* load excerpt */ jQuery.get('/excerpt/' + docnum + '/' + term, function(data) { ui.newContent.children("div.excerpt").html(data); - ui.newHeader.parent().accordion('resize'); - ui.newHeader.parent().accordion('resize'); } ); - var frontpage = jQuery(this).parent().parent().children("img.frontpage"); + + /* update image preview */ + var frontpage = jQuery(this).parent().parent().find("img.frontpage"); frontpage.attr('src', '/static/ajax-loader.gif'); frontpage.load(function() { frontpage.attr('src', '/page/image/' + docnum); }); + + /* scroll image preview */ + var offset = ui.newHeader[0].offsetTop - frontpage.parent()[0].offsetTop; + frontpage.parent().css({paddingTop: offset+"px"}); }); }); </script> @@ -36,7 +39,9 @@ {% for docnum, matches in matches.items() %} <h2 asd="foo"> <a href="{{ url_for("do_book_file", docnum=docnum) }}">book: {{ docnum }}</a> </h2> <div class="book"> - <img class="frontpage" src="{{ url_for("do_book_frontpage", docnum=docnum) }}"/> + <div class="c_frontpage"> + <img class="frontpage" src="{{ url_for("do_book_frontpage", docnum=docnum) }}"/> + </div> <div class="description"> filename, creationtime, indexed-time, +any pdf metadata </div> @@ -6,7 +6,6 @@ from StringIO import StringIO from whoosh.index import open_dir from whoosh.qparser import QueryParser import whoosh.searching as searching -import whoosh.fields as fields import whoosh.analysis as analysis import whoosh.highlight as highlight import whoosh.query as query @@ -95,8 +94,8 @@ def excerpt(docnum, term): if fieldname == "content" ] excerpt = highlight.highlight(result.get("content"), terms, - analysis.FancyAnalyzer(), - highlight.SentenceFragmenter(), + analysis.StandardAnalyzer(), + highlight.ContextFragmenter(terms, maxchars=400, charsbefore=40, charsafter=40), #highlight.SentenceFragmenter(maxchars=500), MyHtmlFormatter()) yield json.dumps( { 'pagenumber':result.get("pagenumber"), @@ -125,7 +124,7 @@ def do_search(skip=0,term=None): searcher = index_book.searcher() query = QueryParser("content").parse(term) facets = searching.Facets.from_field(searcher, "path") - results = searcher.search(query, limit=None) + results = searcher.search(query, limit=None, sortedby="pagenumber") categories = facets.categorize(results) searcher.close() |