def search_wikipedia_view(): """Return JSON containing search results for Wikipedia index""" query = request.args.get('q') pagelen = request.args.get('pagelen', 0, int) page = request.args.get('page', 1, int) ws = WikipediaSearch("wikititles_index") results = ws.search(query, pagelen=pagelen, page=page) j = json.dumps(results, indent=4) return Response(j, mimetype='application/json')
def search_counts_view(): """Returns JSON containing the counts of matches in each major type of search""" query = request.args.get('q') counts = {} # Query wikipedia titles for matches ws = WikipediaSearch("wikititles_index") counts['wikipedia'] = ws.count(query) # Add additional search types here # Dump all matches to JSON j = json.dumps(counts, indent=4) return Response(j, mimetype='application/json')
from wikipedia_search import WikipediaSearch ws = WikipediaSearch() #exception case #print(ws.brief_search("fsfsfsfs").get_result()) print(ws.brief_search("Jimi Hendrix")) print(ws.brief_search("Nikola Tesla")) ws.set_language("fr") print(ws.brief_search("Thomas Edison")) #assertion error #print(ws.brief_search("Nikola Tesla", sentences=11))