-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/asuc-octo/berkeleytime in…
…to izzie-sphinx
- Loading branch information
Showing
9 changed files
with
158 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM python:3.8 | ||
|
||
EXPOSE 5000 | ||
|
||
WORKDIR app | ||
|
||
COPY . /app/ | ||
|
||
RUN pip install -r requirements.txt | ||
|
||
CMD python python3/flask/app.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
The search server uses Python 3.8, the latest version. | ||
|
||
Build the search service and run the app. | ||
> make build && make up | ||
The flask server waits for Elasticsearch to boot up before starting. | ||
This may take awhile. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from flask import Flask, escape, request, render_template | ||
from elasticsearch import Elasticsearch | ||
from elasticsearch_dsl import Search | ||
import time | ||
|
||
es = None | ||
app = None | ||
|
||
|
||
def maybe_create_index(): | ||
if not es.indices.exists(index='catalog'): | ||
print('index doesn\'t exist') | ||
es.indices.create(index='catalog') | ||
else: | ||
print('index exists') | ||
|
||
|
||
@app.route("/") | ||
def index(): | ||
return search() | ||
|
||
|
||
@app.route('/search') | ||
def search(): | ||
return render_template('search.html') | ||
|
||
|
||
@app.route('/results', methods=['GET']) | ||
def search_and_serve(): | ||
if request.method == 'POST': | ||
query = escape(request.form['query']) | ||
s = Search(using=es, index='catalog') \ | ||
.query('match', title=query) | ||
res = s.execute() | ||
output = str("Got %d Hits: \n" % res['hits']['total']['value']) | ||
for hit in res['hits']['hits']: | ||
output += hit['_source']['title'] + ', ' | ||
return 'Your query: ' + query + ' | Search Results: ' + output | ||
else: | ||
return 'Failed' | ||
|
||
|
||
@app.route('/add') | ||
def add_class(): | ||
return render_template('index_class.html') | ||
|
||
|
||
@app.route('/index_class', methods=['POST', 'GET']) | ||
def index_class(): | ||
if request.method == 'POST': | ||
title = escape(request.form['class_title']) | ||
doc = {'title': title} | ||
es.index(index='catalog', doc_type='class', body=doc) | ||
return 'Class indexed: ' + title | ||
else: | ||
return 'Failed' | ||
|
||
|
||
if __name__ == '__main__': | ||
es = Elasticsearch(['elasticsearch']) | ||
# Wait for Elasticsearch to boot up | ||
while not es.ping(): | ||
time.sleep(2) | ||
app = Flask(__name__) | ||
app.run(debug=True, host='0.0.0.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Index a Class</title> | ||
</head> | ||
<body> | ||
<h3>Index a Class Title</h3> | ||
<form action="/index_class" method="post"> | ||
<input type="text" name="class_title"><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Search for Classes</title> | ||
</head> | ||
<body> | ||
<h3>Search for Classes</h3> | ||
<form action="/results" method="post"> | ||
<input type="text" name="query"><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
flask==1.1.1 | ||
elasticsearch | ||
elasticsearch-dsl |