feat: add search query endpoint

This commit is contained in:
2026-01-31 15:12:31 +00:00
parent 777060420c
commit d0d45fb8b0
2 changed files with 17 additions and 1 deletions

View File

@@ -76,5 +76,18 @@ def word_frequencies():
except Exception as e:
return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500
@app.route('/stats/search', methods=["POST"])
def search_dataset():
if stat_obj is None:
return jsonify({"error": "No data uploaded"}), 400
data = request.get_json(silent=True) or {}
if "query" not in data:
return stat_obj.df
query = data["query"]
return jsonify(stat_obj.get_events_containing(query).to_dict(orient='records')), 200
if __name__ == "__main__":
app.run(debug=True)

View File

@@ -103,3 +103,6 @@ class StatGen:
def get_events_per_day(self) -> pd.DataFrame:
return self.events_per_day
def get_events_containing(self, search_query: str) -> pd.DataFrame:
return self.df[self.df["content"].str.contains(search_query)]