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(): ...@@ -44,6 +44,4 @@ while not queue.empty():
queue.put(href) queue.put(href)
visited_list.add(href) visited_list.add(href)
#TODO: Analyze it and update the index
print(visited_list) print(visited_list)
...@@ -4,13 +4,30 @@ import indexing ...@@ -4,13 +4,30 @@ import indexing
# Retrieving data # Retrieving data
from whoosh.qparser import QueryParser from whoosh.qparser import QueryParser
ix = indexing.get_index() from flask import Flask, request, render_template
with ix.searcher() as searcher: def search_index(keyword: str):
# find entries with the words 'first' AND 'last' ix = indexing.get_index()
query = QueryParser("content", ix.schema).parse(input("search for something:\n")) with ix.searcher() as searcher:
results = searcher.search(query) # find entries with the words 'first' AND 'last'
query = QueryParser("content", ix.schema).parse(keyword)
results = searcher.search(query)
# print all results # print all results
for r in results: result_links = []
print(r) for r in results:
\ No newline at end of file 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