Changeset 170

Show
Ignore:
Timestamp:
07/26/08 16:32:59 (4 months ago)
Author:
rgrp
Message:

[shakespeare/search][m]: (follow-up to previous commit r169) add in basic search support to WUI (search controller, templates etc).

More work is needed on search. In particular need to do more when setting up search index (docid etcs) if search results are to be linked to underlying works.

* layout.html: a few tweaks

  • add search button to main menu in layout.html
  • (finally) fix up css to hide empty submenu
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/shakespeare/controllers/search.py

    Revision 166 Revision 170
    1import logging 1import logging 
    2 2 
    3from milton.lib.base import * 3from shakespeare.lib.base import * 
    4 4 
    5log = logging.getLogger(__name__) 5log = logging.getLogger(__name__) 
    6 6 
    7import xapian 7import shakespeare.search 
    8import genshi   
    9import milton   
    10 8 
    11class SearchController(BaseController): 9class SearchController(BaseController): 
    12 10 
    13    def search(self):  11     def index(self): 
    14        return render('/search.html')  12         query = request.params.get('query', '') 
       13         if query: 
       14             c.matches = self._get_results(query) 
       15             c.total = c.matches.get_matches_estimated() 
       16         else: 
       17             c.matches = None 
       18         return render('search/index') 
    15     19     
    16    def searchword(self):  20     def _get_results(self, query): 
    17        import cgi  21         index = shakespeare.search.SearchIndex.default_index() 
    18        import pprint  22         matches = index.search(query) 
       23         return matches 
    19         24         
    20        search = request.params['searchterm']   
    21        database = xapian.Database('./index')   
    22 25 
    23        enquire = xapian.Enquire(database)   
    24   
    25        # Need to run search from the form parameter   
    26        query_string = search   
    27   
    28        # Parse the query string to produce a Xapian::Query object.   
    29        qp = xapian.QueryParser()   
    30        stemmer = xapian.Stem("english")   
    31        qp.set_stemmer(stemmer)   
    32        qp.set_database(database)   
    33        qp.set_stemming_strategy(xapian.QueryParser.STEM_SOME)   
    34        query = qp.parse_query(query_string)   
    35        enquire.set_query(query)   
    36        matches = enquire.get_mset(0, 10)   
    37   
    38        # Display the results.   
    39        c.results = matches.get_matches_estimated()   
    40   
    41        for m in matches:   
    42            c.rank = m.rank + 1   
    43            c.probability = m.percent   
    44            c.document = m.docid   
    45            c.data = m.document.get_data()   
    46           
    47           
    48        return render('/searchword.html')   
  • trunk/shakespeare/templates/layout.html

    Revision 157 Revision 170
    1<html xmlns="http://www.w3.org/1999/xhtml" 1<html xmlns="http://www.w3.org/1999/xhtml" 
    2  xmlns:py="http://genshi.edgewall.org/"  2  xmlns:py="http://genshi.edgewall.org/"  
    3  xmlns:xi="http://www.w3.org/2001/XInclude"> 3  xmlns:xi="http://www.w3.org/2001/XInclude"> 
    4 4 
    5<head> 5<head> 
    6  <title>Open Shakespeare - ${page_title()}</title> 6  <title>Open Shakespeare - ${page_title()}</title> 
    7 7 
    8  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 8  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    9  <link rel="stylesheet" href="/css/master.css" type="text/css" media="screen, print" title="Master stylesheet" charset="utf-8" /> 9  <link rel="stylesheet" href="/css/master.css" type="text/css" media="screen, print" title="Master stylesheet" charset="utf-8" /> 
    10  <script type="text/javascript" src="/scripts/prototype.js"></script> 10  <script type="text/javascript" src="/scripts/prototype.js"></script> 
    11  <script type="text/javascript" src="/scripts/behaviour.js"></script> 11  <script type="text/javascript" src="/scripts/behaviour.js"></script> 
    12  <script type="text/javascript" src="/scripts/master.js"></script> 12  <script type="text/javascript" src="/scripts/master.js"></script> 
    13  <style type="text/css"> 13  <style type="text/css"> 
      14    /* remove login info at top-right */ 
    14    #top-bar { display: none; } 15    #top-bar { display: none; } 
      16    /* mess with standard ckan theme to remove second submenu for time being */ 
      17    #subnav { background: transparent; height: 1px; } 
    15    #subnav * { display: none; } 18    #subnav * { display: none; } 
    16  </style> 19  </style> 
    17 20 
    18  <py:if test="page_specific_css"> 21  <py:if test="page_specific_css"> 
    19    ${page_specific_css()} 22    ${page_specific_css()} 
    20  </py:if> 23  </py:if> 
    21</head> 24</head> 
    22 25 
    23<body> 26<body> 
    24<div id="airlock"> 27<div id="airlock"> 
    25  <!--[if IE]> 28  <!--[if IE]> 
    26    <hr class="holder" /> 29    <hr class="holder" /> 
    27  <![endif]--> 30  <![endif]--> 
    28  <div id="top"> 31  <div id="top"> 
    29    <div id="top-inner"> 32    <div id="top-inner"> 
    30      <div id="top-bar"> 33      <div id="top-bar"> 
    31        <topbar> 34        <topbar> 
    32         35         
    33        <py:choose> 36        <py:choose> 
    34        <py:when test="c.user"> 37        <py:when test="c.user"> 
    35        <p> 38        <p> 
    36          Logged in as <strong>${c.user}</strong>  39          Logged in as <strong>${c.user}</strong>  
    37          | <a href="/account/logout/">Logout</a> 40          | <a href="/account/logout/">Logout</a> 
    38        </p> 41        </p> 
    39        </py:when> 42        </py:when> 
    40        <py:otherwise> 43        <py:otherwise> 
    41          <p> 44          <p> 
    42          <a href="/account/">Register</a> or 45          <a href="/account/">Register</a> or 
    43          <a href="/account/login/">Login</a> 46          <a href="/account/login/">Login</a> 
    44          </p> 47          </p> 
    45        </py:otherwise> 48        </py:otherwise> 
    46        </py:choose> 49        </py:choose> 
    47        </topbar> 50        </topbar> 
    48      </div><!-- /top-bar --> 51      </div><!-- /top-bar --> 
    49         
    50    <h1><a href="${h.url_for(controller='site', action='home')}" title="Open Shakespeare Home">Open Shakespeare</a></h1> 52    <h1><a href="${h.url_for(controller='site', action='home')}" title="Open Shakespeare Home">Open Shakespeare</a></h1> 
    51     53     
    52    </div><!-- /top-inner --> 54    </div><!-- /top-inner --> 
    53      55      
    54    <h3 class="hidden">Sections:</h3> 56    <h3 class="hidden">Sections:</h3> 
    55    <ul id="navigation"> 57    <ul id="navigation"> 
    56      <li><a href="${h.url_for('/')}">Home</a></li> 58      <li><a href="${h.url_for('/')}">Home</a></li> 
      59      <li><a href="${h.url_for(controller='text', action='index')}">Texts</a></li> 
      60      <li><a href="${h.url_for(controller='search', action='index')}">Search</a></li> 
    57      <li><a href="${h.url_for(controller='site', action='guide')}">Guide</a></li> 61      <li><a href="${h.url_for(controller='site', action='guide')}">Guide</a></li> 
    58      <li><a href="${h.url_for(controller='text', action='index')}">Texts</a></li>   
    59    </ul> 62    </ul> 
    60    <h3 class="hidden">In this section:</h3> 63    <h3 class="hidden">In this section:</h3> 
    61    <ul id="subnav"> 64    <ul id="subnav"> 
    62      <minornavigation> 65      <minornavigation> 
    63      <li><a href="${h.url_for(controller='site', action='index')}">Home</a></li> 66      <li><a href="${h.url_for(controller='site', action='index')}">Home</a></li> 
    64      <py:choose> 67      <py:choose> 
    65      <py:when test="c.user"> 68      <py:when test="c.user"> 
    66      <li><a href="/account/logout/">Logout</a></li> 69      <li><a href="/account/logout/">Logout</a></li> 
    67      </py:when> 70      </py:when> 
    68      <py:otherwise> 71      <py:otherwise> 
    69      <li><a href="/account/">Register</a></li> 72      <li><a href="/account/">Register</a></li> 
    70      <li><a href="/account/login/">Login</a></li> 73      <li><a href="/account/login/">Login</a></li> 
    71      </py:otherwise> 74      </py:otherwise> 
    72      </py:choose> 75      </py:choose> 
    73      <li><a href="/package/new/">New Package</a></li> 76      <li><a href="/package/new/">New Package</a></li> 
    74      </minornavigation> 77      </minornavigation> 
    75    </ul> 78    </ul> 
    76        79        
    77    <!--[if IE]> 80    <!--[if IE]> 
    78    <hr class="holder" /> 81    <hr class="holder" /> 
    79    <![endif]--> 82    <![endif]--> 
    80     83     
    81  </div><!-- /top --> 84  </div><!-- /top --> 
    82   85   
    83  <p class="hidden"><a href="#main" title="Skip to page content">[ Skip to main content ]</a></p>  86  <p class="hidden"><a href="#main" title="Skip to page content">[ Skip to main content ]</a></p>  
    84   87   
    85  <div id="primary" class="sidebar"> 88  <div id="primary" class="sidebar"> 
    86    <div class="box"> 89    <div class="box"> 
    87      <h2>Using </h2> 90      <h2>Further Assistance</h2> 
    88      <p>For information on using Open Shakespeare check out the 91      <p>For information on using Open Shakespeare check out the 
    89      <a href="${h.url_for(action='guide')}">Guide</a>. 92      <a href="${h.url_for(action='guide')}">Guide</a>. 
    90      If you have a question or have found a bug please post to the <a href="http://lists.okfn.org/mailman/listinfo/okfn-help">okfn-help</a> mailing list. 93      If you have a question or have found a bug please post to the <a href="http://lists.okfn.org/mailman/listinfo/okfn-help">okfn-help</a> mailing list. 
    91      </p> 94      </p> 
    92    </div> 95    </div> 
    93    <primarysidebar> 96    <primarysidebar> 
    94    <!-- Primary Side Bar Goes Here --> 97    <!-- Primary Side Bar Goes Here --> 
    95    </primarysidebar> 98    </primarysidebar> 
    96     99     
    97    <!--[if IE]> 100    <!--[if IE]> 
    98    <hr class="primary" /> 101    <hr class="primary" /> 
    99    <![endif]--> 102    <![endif]--> 
    100     103     
    101  </div><!-- /primary --> 104  </div><!-- /primary --> 
    102 105 
    103  <div id="main"> 106  <div id="main"> 
    104    <h2>${page_title()}</h2> 107    <h2>${page_title()}</h2> 
    105    <content> 108    <content> 
    106      <p>Master content template placeholder &hellip; please replace me.</p> 109      <p>Master content template placeholder &hellip; please replace me.</p> 
    107    </content> 110    </content> 
    108     111     
    109    <div id="footer"> 112    <div id="footer"> 
    110      <p> 113      <p> 
    111        <a href="http://validator.w3.org/check/referer" title="Valid XHTML 1.1">XHTML</a> 114        <a href="http://validator.w3.org/check/referer" title="Valid XHTML 1.1">XHTML</a> 
    112        | <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> 115        | <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> 
    113        | <a href="http://www.okfn.org/shakespeare/">Project Home Page</a> 116        | <a href="http://www.okfn.org/shakespeare/">Project Home Page</a> 
    114        | <a href="mailto:info@okfn.org">Contact Us</a> 117        | <a href="mailto:info@okfn.org">Contact Us</a> 
    115      </p> 118      </p> 
    116      <p> 119      <p> 
    117        <img style="margin-bottom: -5px;" src="http://m.okfn.org/images/logo/okf_logo_white_and_green_tiny.png" /> An <a href="http://www.okfn.org/">Open Knowledge Foundation</a> Project 120        <img style="margin-bottom: -5px;" src="http://m.okfn.org/images/logo/okf_logo_white_and_green_tiny.png" /> An <a href="http://www.okfn.org/">Open Knowledge Foundation</a> Project 
    118      </p> 121      </p> 
    119      <p> 122      <p> 
    120        (c) Open Knowledge Foundation 123        (c) Open Knowledge Foundation 
    121        | All material available under an <a href="/license/">open license</a> 124        | All material available under an <a href="/license/">open license</a> 
    122        | <a href="http://www.opendefinition.org/1.0/"><img 125        | <a href="http://www.opendefinition.org/1.0/"><img 
    123            style="border: none; margin-bottom: -4px;" 126            style="border: none; margin-bottom: -4px;" 
    124            src="http://m.okfn.org/images/ok_buttons/ok_90x15_blue.png" 127            src="http://m.okfn.org/images/ok_buttons/ok_90x15_blue.png" 
    125            alt="This Content and Data is Open" /></a> 128            alt="This Content and Data is Open" /></a> 
    126      </p> 129      </p> 
    127    </div><!-- /footer --> 130    </div><!-- /footer --> 
    128     131     
    129    <!--[if IE]> 132    <!--[if IE]> 
    130    <hr class="main" /> 133    <hr class="main" /> 
    131    <![endif]--> 134    <![endif]--> 
    132     135     
    133  </div><!-- /main --> 136  </div><!-- /main --> 
    134 137 
    135</div><!-- /airlock --> 138</div><!-- /airlock --> 
    136</body> 139</body> 
    137</html> 140</html> 
  • trunk/shakespeare/templates/search/index.html

    Revision 167 Revision 170
    1<form name="test" method="GET" action="/search/searchword">  1 <html xmlns:py="http://genshi.edgewall.org/" 
    2Search for: <input type="text" name="searchterm" />  2   xmlns:xi="http://www.w3.org/2001/XInclude"> 
    3               <input type="submit" name="submit" value="Submit" />  3    
    4</form>  4   <py:def function="page_title">Search Shakespeare's Work</py:def> 
       5  
       6   <div py:match="content"> 
       7     <form name="test" method="GET" action=""> 
       8       <input type="text" name="query" /> 
       9       <input type="submit" name="submit" value="Submit" /> 
       10     </form> 
       11  
       12     <div class="search-results" py:if="c.matches is not None"> 
       13       <h3>Search Results</h3> 
       14       There were ${c.total} results. 
       15       <ul> 
       16         <li py:for="m in c.matches"> 
       17         ${m.document.get_data()} 
       18         </li> 
       19       </ul> 
       20     </div> 
       21   </div> 
       22  
       23   <xi:include href="../layout.html" /> 
       24 </html>