@@ -75,9 +75,11 @@ class SearchClient {
7575 if (hasLikedByMeTag) {
7676 skipCache = true ;
7777 }
78+ final useLikedByMe =
79+ hasLikedByMeTag && requestContext.experimentalFlags.useMyLikedSearch;
7880
7981 List <String >? packages;
80- if (userId != null && hasLikedByMeTag ) {
82+ if (userId != null && useLikedByMe ) {
8183 final likedPackages = await likeBackend.listPackageLikes (userId);
8284 packages = likedPackages.map ((l) => l.package! ).toList ();
8385 }
@@ -88,53 +90,40 @@ class SearchClient {
8890 }) async {
8991 final httpHostPort = prefix ?? activeConfiguration.searchServicePrefix;
9092 try {
91- if (requestContext.experimentalFlags.useMyLikedSearch) {
92- return await withRetryHttpClient (
93- (client) async {
94- var data = query.toSearchRequestData ();
95- if (userId != null && hasLikedByMeTag) {
96- final newQuery = data.query
97- ? .replaceAll (AccountTag .isLikedByMe, ' ' )
98- .trim ();
99- final newTags = data.tags!
100- .where ((e) => e != AccountTag .isLikedByMe)
101- .toList ();
102- data = data.replace (
103- query: newQuery,
104- tags: newTags,
105- packages: packages,
106- );
107- }
108- // NOTE: Keeping the query parameter to help investigating logs.
109- final uri = Uri .parse (
110- '$httpHostPort /search' ,
111- ).replace (queryParameters: {'q' : data.query});
112- final rs = await client.post (
113- uri,
114- headers: {
115- ...? cloudTraceHeaders (),
116- 'content-type' : 'application/json' ,
117- },
118- body: json.encode (data.toJson ()),
93+ return await withRetryHttpClient (
94+ (client) async {
95+ var data = query.toSearchRequestData ();
96+ if (userId != null && useLikedByMe) {
97+ final newQuery = data.query
98+ ? .replaceAll (AccountTag .isLikedByMe, ' ' )
99+ .trim ();
100+ final newTags = data.tags!
101+ .where ((e) => e != AccountTag .isLikedByMe)
102+ .toList ();
103+ data = data.replace (
104+ query: newQuery,
105+ tags: newTags,
106+ packages: packages,
119107 );
120- return (statusCode: rs.statusCode, body: rs.body);
121- },
122- client: _httpClient,
123- retryIf: (e) =>
124- (e is UnexpectedStatusException &&
125- e.statusCode == searchIndexNotReadyCode),
126- );
127- }
128- final serviceUrl = '$httpHostPort /search$serviceUrlParams ' ;
129- return await httpGetWithRetry (
130- Uri .parse (serviceUrl),
108+ }
109+ // NOTE: Keeping the query parameter to help investigating logs.
110+ final uri = Uri .parse (
111+ '$httpHostPort /search' ,
112+ ).replace (queryParameters: {'q' : data.query});
113+ final rs = await client.post (
114+ uri,
115+ headers: {
116+ ...? cloudTraceHeaders (),
117+ 'content-type' : 'application/json' ,
118+ },
119+ body: json.encode (data.toJson ()),
120+ );
121+ return (statusCode: rs.statusCode, body: rs.body);
122+ },
131123 client: _httpClient,
132- headers: cloudTraceHeaders (),
133- perRequestTimeout: Duration (seconds: 5 ),
134124 retryIf: (e) =>
135125 (e is UnexpectedStatusException &&
136126 e.statusCode == searchIndexNotReadyCode),
137- responseFn: (rs) => (statusCode: rs.statusCode, body: rs.body),
138127 );
139128 } on TimeoutException {
140129 return null ;
0 commit comments