Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(search): score hybrid symbols on content words when there is no identifier (#3677)
Yunus Ozen25413649c8eb
diff --git a/packages/server/src/repowise/server/mcp_server/tool_search.py b/packages/server/src/repowise/server/mcp_server/tool_search.pyindex a0bdef1ce..748c4929e 100644--- a/packages/server/src/repowise/server/mcp_server/tool_search.py+++ b/packages/server/src/repowise/server/mcp_server/tool_search.py@@ -80,6 +80,7 @@ from repowise.server.mcp_server._query_shape import (_symbol_matches_name,path_tokens,)+from repowise.server.mcp_server._query_terms import content_termsfrom repowise.server.mcp_server._references import path_identity, symbol_identityfrom repowise.server.mcp_server._retrieval_rank import (boost_named_paths,@@ -1085,8 +1086,12 @@ async def _structured_search(symbol_query = canonical_symbol[1]if mode == "hybrid":_idents = _embedded_identifiers(query, names)- if _idents:- symbol_query = " ".join(_idents)+ # Without an identifier, score on the content words so stopwords such+ # as "on" can't match symbols like ``test_basic_auth_on_session``. A+ # query made only of stopwords keeps the raw text.+ symbol_query = (+ " ".join(_idents) if _idents else " ".join(content_terms(query)) or query+ )# Only the hybrid window collapses symbol rows, so only it over-fetches# them; path hits are file pages, already one row per file. Symbol modediff --git a/tests/unit/server/mcp/test_search.py b/tests/unit/server/mcp/test_search.pyindex 462d2ad9c..3cbad2fdf 100644--- a/tests/unit/server/mcp/test_search.py+++ b/tests/unit/server/mcp/test_search.py@@ -1194,6 +1194,51 @@ class TestExactMatchSignal:await search_codebase("AuthService", mode="symbol")assert seen == ["AuthService"]+ @pytest.mark.asyncio+ async def test_hybrid_without_identifier_scores_symbols_on_content_words(+ self, setup_mcp, monkeypatch+ ):+ # Regression for #3593: with no identifier in the question the scorer+ # got the raw prose, so "on" matched test_basic_auth_on_session.+ from repowise.server.mcp_server import search_codebase, tool_search++ seen: list[str] = []+ real = tool_search.search_symbols_single++ async def spy(ctx, query, limit, **kwargs):+ seen.append(query)+ return await real(ctx, query, limit, **kwargs)++ monkeypatch.setattr(tool_search, "search_symbols_single", spy)++ await search_codebase("retry on connection failure", mode="hybrid")+ assert seen, "symbol scorer was not called"+ assert "on" not in seen[0].split(), seen+ assert {"retry", "connection", "failure"} <= set(seen[0].split()), seen++ @pytest.mark.asyncio+ async def test_hybrid_stopword_does_not_outrank_the_content_match(self, setup_mcp):+ from repowise.server.mcp_server import search_codebase++ await _seed_symbol("test_basic_auth_on_session")+ await _seed_symbol("RetryTransport")++ result = await search_codebase("retry on connection failure", mode="hybrid", limit=10)+ names = [r.get("name") for r in result["results"] if r.get("type") == "symbol"]+ assert "RetryTransport" in names, names+ if "test_basic_auth_on_session" in names:+ assert names.index("RetryTransport") < names.index("test_basic_auth_on_session")++ @pytest.mark.asyncio+ async def test_symbol_mode_still_matches_stopword_identifiers(self, setup_mcp):+ from repowise.server.mcp_server import search_codebase++ await _seed_symbol("get_on_change")++ result = await search_codebase("get_on_change", mode="symbol")+ names = [r.get("name") for r in result["results"]]+ assert "get_on_change" in names, names+@pytest.mark.asyncioasync def test_exact_hit_sets_true_and_no_fuzzy_note(self, setup_mcp):from repowise.server.mcp_server import search_codebase