From d70beee51bfec0736e119d657dc82757585c8670 Mon Sep 17 00:00:00 2001 From: Igor Loskutov Date: Thu, 21 Aug 2025 14:52:29 -0400 Subject: [PATCH] fix: include shared rooms to search (#558) * include shared rooms to search * tests vibe * tests vibe * tests vibe * tests vibe * tests vibe * tests vibe * tests vibe * remove tests, thats too much --- server/reflector/db/search.py | 8 +++++++- server/tests/test_search.py | 23 ++++++++++++++++------- server/tests/test_search_long_summary.py | 8 +++++--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/server/reflector/db/search.py b/server/reflector/db/search.py index d60f81e5..8ac25212 100644 --- a/server/reflector/db/search.py +++ b/server/reflector/db/search.py @@ -379,7 +379,13 @@ class SearchController: ) if params.user_id: - base_query = base_query.where(transcripts.c.user_id == params.user_id) + base_query = base_query.where( + sqlalchemy.or_( + transcripts.c.user_id == params.user_id, rooms.c.is_shared + ) + ) + else: + base_query = base_query.where(rooms.c.is_shared) if params.room_id: base_query = base_query.where(transcripts.c.room_id == params.room_id) if params.source_kind: diff --git a/server/tests/test_search.py b/server/tests/test_search.py index 5d2a22b0..61145bf9 100644 --- a/server/tests/test_search.py +++ b/server/tests/test_search.py @@ -74,11 +74,12 @@ async def test_empty_transcript_title_only_match(): "share_mode": "private", "source_kind": "room", "webvtt": None, + "user_id": "test-user-1", } await get_database().execute(transcripts.insert().values(**test_data)) - params = SearchParameters(query_text="empty") + params = SearchParameters(query_text="empty", user_id="test-user-1") results, total = await search_controller.search_transcripts(params) assert total >= 1 @@ -127,11 +128,12 @@ async def test_search_with_long_summary(): 00:00:00.000 --> 00:00:10.000 Basic meeting content without special keywords.""", + "user_id": "test-user-2", } await get_database().execute(transcripts.insert().values(**test_data)) - params = SearchParameters(query_text="quantum computing") + params = SearchParameters(query_text="quantum computing", user_id="test-user-2") results, total = await search_controller.search_transcripts(params) assert total >= 1 @@ -191,23 +193,26 @@ The search feature should support complex queries with ranking. 00:00:30.000 --> 00:00:40.000 We need to implement PostgreSQL tsvector for better performance.""", + "user_id": "test-user-3", } await get_database().execute(transcripts.insert().values(**test_data)) - params = SearchParameters(query_text="planning") + params = SearchParameters(query_text="planning", user_id="test-user-3") results, total = await search_controller.search_transcripts(params) assert total >= 1 found = any(r.id == test_id for r in results) assert found, "Should find test transcript by title word" - params = SearchParameters(query_text="tsvector") + params = SearchParameters(query_text="tsvector", user_id="test-user-3") results, total = await search_controller.search_transcripts(params) assert total >= 1 found = any(r.id == test_id for r in results) assert found, "Should find test transcript by webvtt content" - params = SearchParameters(query_text="engineering planning") + params = SearchParameters( + query_text="engineering planning", user_id="test-user-3" + ) results, total = await search_controller.search_transcripts(params) assert total >= 1 found = any(r.id == test_id for r in results) @@ -220,13 +225,17 @@ We need to implement PostgreSQL tsvector for better performance.""", assert test_result.duration == 1800.0 assert 0 <= test_result.rank <= 1, "Rank should be normalized to 0-1" - params = SearchParameters(query_text="tsvector OR nosuchword") + params = SearchParameters( + query_text="tsvector OR nosuchword", user_id="test-user-3" + ) results, total = await search_controller.search_transcripts(params) assert total >= 1 found = any(r.id == test_id for r in results) assert found, "Should find test transcript with OR query" - params = SearchParameters(query_text='"full-text search"') + params = SearchParameters( + query_text='"full-text search"', user_id="test-user-3" + ) results, total = await search_controller.search_transcripts(params) assert total >= 1 found = any(r.id == test_id for r in results) diff --git a/server/tests/test_search_long_summary.py b/server/tests/test_search_long_summary.py index fe3e9305..8857778b 100644 --- a/server/tests/test_search_long_summary.py +++ b/server/tests/test_search_long_summary.py @@ -54,12 +54,13 @@ The robotics project is making good progress. 00:00:20.000 --> 00:00:30.000 We need to consider various implementation approaches.""", + "user_id": "test-user-priority", } await get_database().execute(transcripts.insert().values(**test_data)) # Search for "robotics" which appears in both long_summary and webvtt - params = SearchParameters(query_text="robotics") + params = SearchParameters(query_text="robotics", user_id="test-user-priority") results, total = await search_controller.search_transcripts(params) assert total >= 1 @@ -131,12 +132,13 @@ Team meeting about general project updates. 00:00:10.000 --> 00:00:20.000 Discussion of timeline and deliverables.""", + "user_id": "test-user-long", } await get_database().execute(transcripts.insert().values(**test_data)) # Search for terms only in long_summary - params = SearchParameters(query_text="cryptocurrency") + params = SearchParameters(query_text="cryptocurrency", user_id="test-user-long") results, total = await search_controller.search_transcripts(params) found = any(r.id == test_id for r in results) @@ -151,7 +153,7 @@ Discussion of timeline and deliverables.""", assert "cryptocurrency" in snippet, "Snippet should contain the search term" # Search for "yield farming" - a more specific term - params2 = SearchParameters(query_text="yield farming") + params2 = SearchParameters(query_text="yield farming", user_id="test-user-long") results2, total2 = await search_controller.search_transcripts(params2) found2 = any(r.id == test_id for r in results2)