This commit is contained in:
Alex 2018-06-10 19:22:24 +02:00
parent 932ce9102a
commit b369442e41

View File

@ -20,7 +20,7 @@ import time
from csv import DictWriter, DictReader
import io
from sqlalchemy.inspection import inspect
import autocomplete
#import autocomplete
import sys
import os
@ -399,7 +399,7 @@ def show_instances():
@app.route('/books', methods= ['POST','GET'])
def show_books():
autocomplete.load() #Train markov model once, for autocomplete in search
#autocomplete.load() #Train markov model once, for autocomplete in search
books = db.session.query(Book).all()
search = SearchForm(request.form)
@ -435,28 +435,28 @@ def search_results(searchtype, query):
return render_template('results.html', form=search, books=results, books_all=random_order, searchtype=search.select.data, query=query)
## Search - autocomplete
autocomplete_suggestions = []
autocomplete.load() #Train markov model once, for autocomplete in search
#autocomplete_suggestions = []
#autocomplete.load() #Train markov model once, for autocomplete in search
@app.route('/autocomplete_suggestions', methods=['GET', 'POST'])
def test1():
if request.method == 'POST':
query = request.form['search']
query_tokenized = query.lower().split()
print(query_tokenized)
word_1 = query_tokenized[-2]
word_2 = query_tokenized[-1]
#print(word_1)
autocomplete_output = autocomplete.predict(word_1 , word_2)
autocomplete_suggestions.clear()
for suggestion, score in autocomplete_output:
autocomplete_suggestions.append(suggestion)
session['autocomplete_suggestions'] = str(autocomplete_suggestions)
print(session['autocomplete_suggestions'])
return Response(json.dumps(session['autocomplete_suggestions']), mimetype='application/json')
# @app.route('/autocomplete_suggestions', methods=['GET', 'POST'])
# def test1():
# if request.method == 'POST':
# query = request.form['search']
# query_tokenized = query.lower().split()
# print(query_tokenized)
# word_1 = query_tokenized[-2]
# word_2 = query_tokenized[-1]
# #print(word_1)
# autocomplete_output = autocomplete.predict(word_1 , word_2)
# autocomplete_suggestions.clear()
# for suggestion, score in autocomplete_output:
# autocomplete_suggestions.append(suggestion)
#
# session['autocomplete_suggestions'] = str(autocomplete_suggestions)
#
# print(session['autocomplete_suggestions'])
#
# return Response(json.dumps(session['autocomplete_suggestions']), mimetype='application/json')
## STACKS!