Join counts for multiple words

This commit is contained in:
rmgr 2023-11-30 17:26:59 +10:30
parent d30397cefa
commit 3d7b72e5ef
2 changed files with 9 additions and 3 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
src/__pycache__

View file

@ -6,7 +6,7 @@ import json
from urllib.parse import unquote from urllib.parse import unquote
app = Flask(__name__) app = Flask(__name__)
## Todo - Boolean search (AND/OR/NOT/"")
@app.route("/search/<query>") @app.route("/search/<query>")
def search(query): def search(query):
with open('data/index.json', 'r') as index_json: with open('data/index.json', 'r') as index_json:
@ -17,9 +17,14 @@ def search(query):
for q in query_split: for q in query_split:
q = q.lower() q = q.lower()
if q in index: if q in index:
result.append(index[q]) for item in index[q]:
matching_results = list(filter(lambda entry: entry['url'] == item["url"], result))
if len(matching_results) == 0:
result.append(item)
else:
matching_results[0]["count"] += item["count"]
#result.append(index[q])
# result.sort(reverse= True,key=lambda entry: int(entry.count)) # result.sort(reverse= True,key=lambda entry: int(entry.count))
print(result)
return result return result