feat: add search query endpoint
This commit is contained in:
@@ -75,6 +75,19 @@ def word_frequencies():
|
||||
return jsonify({"error": f"Malformed or missing data: {str(e)}"}), 400
|
||||
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)
|
||||
@@ -102,4 +102,7 @@ class StatGen:
|
||||
return self.word_frequencies
|
||||
|
||||
def get_events_per_day(self) -> pd.DataFrame:
|
||||
return self.events_per_day
|
||||
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)]
|
||||
Reference in New Issue
Block a user