Skip to content
Snippets Groups Projects
Commit ba1b4e00 authored by srebers's avatar srebers
Browse files

First search engine prototype is running

parent 13590527
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,4 @@ while not queue.empty():
queue.put(href)
visited_list.add(href)
#TODO: Analyze it and update the index
print(visited_list)
......@@ -4,13 +4,30 @@ import indexing
# Retrieving data
from whoosh.qparser import QueryParser
ix = indexing.get_index()
from flask import Flask, request, render_template
with ix.searcher() as searcher:
# find entries with the words 'first' AND 'last'
query = QueryParser("content", ix.schema).parse(input("search for something:\n"))
results = searcher.search(query)
def search_index(keyword: str):
ix = indexing.get_index()
with ix.searcher() as searcher:
# find entries with the words 'first' AND 'last'
query = QueryParser("content", ix.schema).parse(keyword)
results = searcher.search(query)
# print all results
for r in results:
print(r)
\ No newline at end of file
# print all results
result_links = []
for r in results:
result_links.append(r.fields()["url"])
return result_links
search_index("platypus")
app = Flask(__name__)
@app.route("/")
def start():
return render_template("start.html", title="start")
@app.route("/result")
def reverse():
rev = request.args.get('rev')
return render_template("result.html", title="search for: "+rev, result=search_index(rev))
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
<h1>Results:</h1>
<ul>
{% for item in result %}
<li>
<a href= {{ item }}> {{ item }} </a>
</li>
{% endfor %}
</ul>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
<h1>Hello World</h1>
<form action="result" method="GET">
<input type="text" name='rev'>
</form>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment