@@ -22,21 +22,14 @@ import { useEffect, useMemo, useState } from "react";
2222import { communityCreationFormURL , routeToCommunity } from "routes" ;
2323import { listAllCommunities , searchCommunities } from "service/communities" ;
2424
25- // The visible name is what we rank/filter on (issue #9129). We only read the
26- // fields both ListAllCommunities (CommunitySummary) and SearchCommunities
27- // (Community) responses share.
2825type CommunityOption = Pick <
2926 Community . AsObject ,
3027 "communityId" | "name" | "slug" | "parentsList"
3128> ;
3229
33- // Backend SearchCommunities requires >= 3 chars; below that we browse/filter the
34- // full list client-side. 400 ms debounce mirrors the confirmed #8837 decision.
3530const MIN_SEARCH_LENGTH = 3 ;
3631const COMMUNITY_SEARCH_DEBOUNCE_MS = 400 ;
3732
38- // parentsList is ordered root -> ... -> immediate parent -> self (the node itself
39- // is the last entry), so the region context is the second-to-last entry.
4033const regionOf = ( option : CommunityOption ) : string => {
4134 const parents = option . parentsList ;
4235 if ( ! parents || parents . length < 2 ) return "" ;
@@ -69,8 +62,6 @@ export default function CommunitySearch() {
6962 const query = debouncedInput . trim ( ) ;
7063 const isSearching = query . length >= MIN_SEARCH_LENGTH ;
7164
72- // Server-side, name-ranked, typo-tolerant search (pg_trgm). react-query caches
73- // by query string, so re-typing/backspacing hits the cache, not the network.
7465 const { data : searchData , isLoading : searchLoading } = useQuery <
7566 SearchCommunitiesRes . AsObject ,
7667 RpcError
@@ -80,7 +71,6 @@ export default function CommunitySearch() {
8071 enabled : isSearching ,
8172 } ) ;
8273
83- // Full list for the browse / short-query state (dropdown opened, < 3 chars).
8474 const { data : browseData , isLoading : browseLoading } = useQuery <
8575 ListAllCommunitiesRes . AsObject ,
8676 RpcError
@@ -90,9 +80,6 @@ export default function CommunitySearch() {
9080 enabled : ! isSearching ,
9181 } ) ;
9282
93- // Ranked search results are used verbatim (no client re-sort). Browse results
94- // are filtered by visible name and ordered region -> name so region groups stay
95- // contiguous. Neither path uses the hidden hierarchical path (the #9129 bug).
9683 const options = useMemo < CommunityOption [ ] > ( ( ) => {
9784 if ( isSearching ) {
9885 return searchData ?. communitiesList ?? [ ] ;
@@ -141,8 +128,7 @@ export default function CommunitySearch() {
141128 onInputChange = { handleInputChange }
142129 onChange = { handleChange }
143130 getOptionLabel = { ( option ) => option . name }
144- // Server results are already ranked (and typo-tolerant); browse results are
145- // pre-filtered. Disable MUI's built-in filter so it can't drop/reorder them.
131+ // don't let MUI re-filter: it would drop the typo-tolerant server results
146132 filterOptions = { ( x ) => x }
147133 groupBy = { isSearching ? undefined : ( option ) => regionOf ( option ) }
148134 renderOption = { ( props , option ) => {
0 commit comments