Exemple #1
0
 def search_page():
     """Main search page."""
     query = request.GET.get('query', '').strip()
     # Convert query to unicode.
     query = query.decode('utf-8')
     log.info('Web query: ' + query)
     answers = []
     if query:
         banana = Banana()
         answers = banana.search(query)
     return dict(answers=answers)
Exemple #2
0
def _search(args):
    """
    Internal module level method directly called by the argparse argument parse.
    """
    if not args.query:
        raise Exception('Unable to perform a search for an empty query.')

    # Build the full query concatenating the query terms.
    full_query = ' '.join(args.query).strip()

    # Get the answer of the searcher to this query.
    banana = Banana()
    answers = banana.search(full_query)

    # Print the answer to the user.
    print('\nBanana searched!\n\"%s\"?' % full_query)
    for answer in answers:
        print('\n' + answer.title + '\n' +
            'Scored ' + str(answer.score) + '\n' +
            answer.url + '\n' +
            answer.snippet)
Exemple #3
0
def _crawl(args):
    """
    Internal module level method directly called by the argparse argument parse.
    """
    banana = Banana()
    banana.crawl(args.restart, args.seed)