views
This commit is contained in:
parent
932ce9102a
commit
b369442e41
46
app/views.py
46
app/views.py
@ -20,7 +20,7 @@ import time
|
|||||||
from csv import DictWriter, DictReader
|
from csv import DictWriter, DictReader
|
||||||
import io
|
import io
|
||||||
from sqlalchemy.inspection import inspect
|
from sqlalchemy.inspection import inspect
|
||||||
import autocomplete
|
#import autocomplete
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -399,7 +399,7 @@ def show_instances():
|
|||||||
|
|
||||||
@app.route('/books', methods= ['POST','GET'])
|
@app.route('/books', methods= ['POST','GET'])
|
||||||
def show_books():
|
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()
|
books = db.session.query(Book).all()
|
||||||
search = SearchForm(request.form)
|
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)
|
return render_template('results.html', form=search, books=results, books_all=random_order, searchtype=search.select.data, query=query)
|
||||||
|
|
||||||
## Search - autocomplete
|
## Search - autocomplete
|
||||||
autocomplete_suggestions = []
|
#autocomplete_suggestions = []
|
||||||
autocomplete.load() #Train markov model once, for autocomplete in search
|
#autocomplete.load() #Train markov model once, for autocomplete in search
|
||||||
|
|
||||||
@app.route('/autocomplete_suggestions', methods=['GET', 'POST'])
|
# @app.route('/autocomplete_suggestions', methods=['GET', 'POST'])
|
||||||
def test1():
|
# def test1():
|
||||||
if request.method == 'POST':
|
# if request.method == 'POST':
|
||||||
query = request.form['search']
|
# query = request.form['search']
|
||||||
query_tokenized = query.lower().split()
|
# query_tokenized = query.lower().split()
|
||||||
print(query_tokenized)
|
# print(query_tokenized)
|
||||||
word_1 = query_tokenized[-2]
|
# word_1 = query_tokenized[-2]
|
||||||
word_2 = query_tokenized[-1]
|
# word_2 = query_tokenized[-1]
|
||||||
#print(word_1)
|
# #print(word_1)
|
||||||
autocomplete_output = autocomplete.predict(word_1 , word_2)
|
# autocomplete_output = autocomplete.predict(word_1 , word_2)
|
||||||
autocomplete_suggestions.clear()
|
# autocomplete_suggestions.clear()
|
||||||
for suggestion, score in autocomplete_output:
|
# for suggestion, score in autocomplete_output:
|
||||||
autocomplete_suggestions.append(suggestion)
|
# autocomplete_suggestions.append(suggestion)
|
||||||
|
#
|
||||||
session['autocomplete_suggestions'] = str(autocomplete_suggestions)
|
# session['autocomplete_suggestions'] = str(autocomplete_suggestions)
|
||||||
|
#
|
||||||
print(session['autocomplete_suggestions'])
|
# print(session['autocomplete_suggestions'])
|
||||||
|
#
|
||||||
return Response(json.dumps(session['autocomplete_suggestions']), mimetype='application/json')
|
# return Response(json.dumps(session['autocomplete_suggestions']), mimetype='application/json')
|
||||||
|
|
||||||
## STACKS!
|
## STACKS!
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user