/upstream/templates/search/subjects.tmpl
Type: /type/template
body: value: $def with (get_results)

$ q = query_param('q')
$ results_per_page = 100
$ page = query_param('page')
$if page:
    $ page = int(page)
$else:
    $ page = 1
$ offset = (page - 1) * results_per_page
$ url_map = { 'person': 'person:', 'place': 'place:', 'time': 'time:' }

<div id="contentHead">
    <h1>
        $_("Subject Search")
    </h1>

$if q:
    $ results = get_results(q, offset=offset, limit=results_per_page)
    $if 'error' not in results:
        $ response = results['response']
        $ num_found = int(response['numFound'])
        <p class="sansserif darkgreen collapse"><strong>$commify(response['numFound']) hit$("s" if response['numFound'] != 1 else "")</strong></p>
</div>
    
<div id="contentMeta">
    
    <div class="section">
    
    <form class="siteSearch olform" action="">
        <input type="text" class="larger" name="q" size="100" style="width: 505px;" value="$q"/>
        <button type="submit" class="larger">$_('Search')</button>
    </form>
    
    </div>
    
$if q and 'error' in results:
    <strong>
        $for line in results['error'].splitlines():
            $line
            $if not loop.last:
                <br>
    </strong>

$if q and 'error' not in results:
    <ul class="subjectList">
    $for doc in response['docs']:
        $ n = doc['name']
        $ key = '/subjects/' + url_map.get(doc['type'], '') + n.lower().replace(' ', '_').replace('?', '').replace(',', '')
        
        <li>
            <a href="$key">$n</a>
            $code: 
                def find_type():
                    if doc['type'] == 'time':
                        return "type_time"
                    elif doc['type'] == 'subject':
                        return "type_subject"
                    elif doc['type'] == 'place':
                        return "type_place"
                    elif doc['type'] == 'org':
                        return "type_org"
                    elif doc['type'] == 'event':
                        return "type_event"
                    elif doc['type'] == 'person':
                        return "type_person"
                    elif doc['type'] == 'work':
                        return "type_work"
                    else:
                        return "other"
                type = find_type()
                if type == "type_time":
                    note = _('<span class="teal">time</span>')
                elif type == "type_subject":
                    note = _('<span class="darkgreen">subject</span>')
                elif type == "type_place":
                    note = _('<span class="orange">place</span>')
                elif type == "type_org":
                    note = _('<span class="blue">org</span>')
                elif type == "type_event":
                    note = _('<span class="grey">event</span>')
                elif type == "type_person":
                    note = _('<span class="red">person</span>')
                elif type == "type_work":
                    note = _('<span class="black">work</span>')
                else:
                    note = doc['type']
            <span class="count">&nbsp;&nbsp;<b>$commify(doc['count']) book$("s" if doc['count'] != 1 else "")</b>, $:note</span>
        </li>
    </ul>
    $:macros.Pager(page, num_found, results_per_page)

</div>
plugin: worksearch
m: edit