Added functionality of creating the index through the html
This commit is contained in:
parent
107d1b2a46
commit
63c9bbee6f
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
|||||||
/__pycache__/
|
/__pycache__/
|
||||||
/test/
|
/test/
|
||||||
merged*
|
merged*
|
||||||
|
test*
|
||||||
|
10
indexer.py
10
indexer.py
@ -232,10 +232,10 @@ class Indexer():
|
|||||||
load_index_index()
|
load_index_index()
|
||||||
|
|
||||||
def create_index(self):
|
def create_index(self):
|
||||||
indexer.get_data_path()
|
self.get_data_path()
|
||||||
print("We have " + str(len(indexer.data_paths)) + " documents to go through !" )
|
print("We have " + str(len(self.data_paths)) + " documents to go through !" )
|
||||||
indexer.start()
|
self.start()
|
||||||
indexer.merge()
|
self.merge()
|
||||||
print("Finished merging into 1 big happy family")
|
print("Finished merging into 1 big happy family")
|
||||||
indexer.set_weight()
|
self.set_weight()
|
||||||
print("I AM DONE INDEXING !")
|
print("I AM DONE INDEXING !")
|
||||||
|
30
launcher.py
30
launcher.py
@ -5,27 +5,33 @@ from flask import render_template
|
|||||||
from flask import request
|
from flask import request
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
def main():
|
errors = list()
|
||||||
indexer = Indexer(False,list(),dict(),list())
|
indexer = Indexer(list(),dict(),list())
|
||||||
indexer.load_index_index()
|
search = None
|
||||||
search = Search()
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/',methods=['POST','GET'])
|
@app.route('/',methods=['POST','GET'])
|
||||||
def index():
|
def index():
|
||||||
|
errors = list()
|
||||||
|
if not indexer:
|
||||||
|
errors.append("Error in creating indexer module")
|
||||||
|
elif not indexer.load_index_index():
|
||||||
|
errors.append("Indexer does not exists, please run it first")
|
||||||
|
if not search:
|
||||||
|
errors.append("Error in creating search module")
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if request.form.get('start-index') == "start":
|
if request.form.get('start-index') == "start":
|
||||||
print("make the indexer")
|
print("Making the indexer")
|
||||||
|
indexer.create_index()
|
||||||
return render_template('index.html',ips="Thanks for waiting you are ready to search.")
|
return render_template('index.html',ips="Thanks for waiting you are ready to search.")
|
||||||
if request.form.get('search_query') != "":
|
if request.form.get('search_query') != "":
|
||||||
search = request.form['search_query']
|
search_query = request.form['search_query']
|
||||||
result = [['lorem','ipsi'],['lores','dolores']]
|
result = [['lorem','ipsi'],['lores','dolores']]
|
||||||
return render_template('index.html',results=result)
|
return render_template('index.html',results=result,errors=errors)
|
||||||
return render_template('index.html')
|
return render_template('index.html',errors=errors)
|
||||||
else:
|
else:
|
||||||
return render_template('index.html')
|
return render_template('index.html',errors=errors)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
main()
|
|
@ -3,4 +3,4 @@ re
|
|||||||
shelve
|
shelve
|
||||||
json
|
json
|
||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
sklearn
|
flask
|
||||||
|
@ -22,4 +22,9 @@
|
|||||||
{% for result in results %}
|
{% for result in results %}
|
||||||
<p>{{result[0]}} at <a href="{{result[1]}}">{{result[1]}}</a></p>
|
<p>{{result[0]}} at <a href="{{result[1]}}">{{result[1]}}</a></p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for error in errors %}
|
||||||
|
<p>{{error}}</p>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user