You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/api/nonsense.py
+41
Original file line number
Diff line number
Diff line change
@@ -107,3 +107,44 @@ async def import_nonsense(
107
107
finally:
108
108
# Ensure that the database session is closed, regardless of whether an error occurred or not
109
109
awaitdb_session.close()
110
+
111
+
112
+
# TODO: add websocket to full text search postgres database for nonsense description
113
+
114
+
# To add a WebSocket to full text search a PostgreSQL database for the `nonsense` description, you can use the `websockets` library in Python. Here's a step-by-step plan:
115
+
#
116
+
# 1. Install the `websockets` library if you haven't done so already.
117
+
# 2. Create a new WebSocket route in your FastAPI application.
118
+
# 3. In the WebSocket route, accept a search query from the client.
119
+
# 4. Use the search query to perform a full text search on the `nonsense` table in your PostgreSQL database.
120
+
# 5. Send the search results back to the client through the WebSocket connection.
# WHERE to_tsvector('english', description) @@ plainto_tsquery('english', :q)
139
+
# """)
140
+
# result = await db_session.execute(query, {"q": data})
141
+
# await websocket.send_json(result.fetchall())
142
+
# # ```
143
+
#
144
+
# This code creates a new WebSocket route at `/ws/nonsense`. When a client connects to this route and sends a message, the message is used as a search query in a full text search on the `nonsense` table. The search results are then sent back to the client through the WebSocket connection.
145
+
#
146
+
# Please note that this is a basic implementation and might need adjustments based on your specific needs. For example, you might want to add error handling, handle disconnections, or format the search results before sending them back to the client.
0 commit comments