feat: add search query endpoint
This commit is contained in:
@@ -76,5 +76,18 @@ def word_frequencies():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500
|
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__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
@@ -103,3 +103,6 @@ class StatGen:
|
|||||||
|
|
||||||
def get_events_per_day(self) -> pd.DataFrame:
|
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