コード例 #1
0
def debug(response):
    # query = response.get_argument('storyquery')
    query = 'gandalf'
    response.write('{}<br/>'.format(search(conn.cursor(), conn, query)))
    index = load_index(conn.cursor(), conn)
    for doc in index:
        response.write('{};<br/>'.format(doc))
        for word in index[doc]:
            response.write('<div style="margin-left:20px;">{}; {}</div>'.format(word, index[doc][word]))
        response.write('<br/>')
コード例 #2
0
def main():
    # make sure we are using the same database as the rest of the code
    from dbapi import conn
    cursor = conn.cursor()

    searchindex.create_table(conn, True)

    # do the search function
    results = search(cursor, conn, input('Q? '))
    print()
    for result in results:
        print(Story.find('id', result[0])[0].title, '-->', result[1])

    conn.close()
コード例 #3
0
def search_results(response):
    context = defaultdict()

    user = response.get_secure_cookie('username')
    stories = Story.find('all', '')

    try:
        context.update({
            'current_user': User.find('username', str(user, 'utf-8'))[0]})
    except TypeError:
        context.update({
            'current_user': None})

    cursor = conn.cursor()

    if response.get_arguments('storyquery') != []:
        query = response.get_argument('storyquery')
        results = search(cursor, conn, query)
        stories = []
        for result in results:
            stories.append(Story.find('id', int(result[0]))[0])

        context['stories'] = stories
        context['query'] = query
        context['story'] = ''

        assert 'query' in context
        print("QUERY", repr(query))
        html = template.render_file('templates/storylist.html', context)
        # html = template.render_file('templates/minimal.html', context)
        response.write(html)

    elif response.get_arguments('sort') != []:
        # filter logic here
        pass
    else:
        context['stories'] = stories
        context['story'] = None
        html = template.render_file('templates/storylist.html', context)
        response.write(html)