@@ -164,42 +164,38 @@ async def search(
164164 client = cast (DuckdbClient , request .state .client )
165165 hrefs = cast (dict [str , list [str ]], request .state .hrefs )
166166
167- hrefs_to_search = []
168167 if search .collections :
169- for collection in search .collections :
170- if collection_hrefs := hrefs .get (collection ):
171- hrefs_to_search .extend (collection_hrefs )
168+ collections = search .collections
172169 else :
173- for collection_hrefs in hrefs .values ():
174- hrefs_to_search .extend (collection_hrefs )
175-
176- if len (hrefs ) > 1 :
177- raise ValidationError (
178- "Cannot search multiple geoparquet files (don't know how to page)"
179- )
180- elif len (hrefs ) == 0 :
181- return ItemCollection ()
182- else :
183- href = hrefs_to_search .pop ()
170+ collections = list (hrefs .keys ())
184171
185172 search_dict = search .model_dump (exclude_none = True )
186- search_dict .update (** kwargs )
187- items = client .search (
188- href ,
189- ** search_dict ,
190- )
173+ search_dict ["offset" ] = kwargs .get ("offset" , 0 )
174+ items : list [dict [str , Any ]] = []
175+ while collections and not (search .limit and len (items ) >= search .limit ):
176+ collection = collections .pop (0 )
177+ if collection_hrefs := hrefs .get (collection ):
178+ collection_search_dict = copy .deepcopy (search_dict )
179+ collection_search_dict ["collections" ] = [collection ]
180+ for href in collection_hrefs :
181+ items .extend (client .search (href , ** collection_search_dict ))
182+ if search .limit and len (items ) >= search .limit :
183+ collections .insert (0 , collection )
184+ break
185+ search_dict ["offset" ] = 0
186+
191187 item_collection = {
192188 "type" : "FeatureCollection" ,
193189 "features" : [self .item_with_links (item , request ) for item in items ],
194190 }
195191 num_items = len (item_collection ["features" ])
196- limit = int (search_dict .get ("limit" , None ) or num_items )
197192 offset = int (search_dict .get ("offset" , None ) or 0 )
198193
199- if limit <= num_items :
194+ if search . limit and search . limit <= num_items :
200195 next_search = copy .deepcopy (search_dict )
201- next_search ["limit" ] = limit
202- next_search ["offset" ] = offset + limit
196+ next_search ["limit" ] = search .limit
197+ next_search ["offset" ] = offset + search .limit
198+ next_search ["collections" ] = collections
203199 else :
204200 next_search = None
205201
@@ -220,6 +216,8 @@ async def search(
220216 }
221217 )
222218 if next_search :
219+ if "collections" in next_search :
220+ next_search ["collections" ] = "," .join (collections )
223221 links .append (
224222 {
225223 "href" : url + "?" + urllib .parse .urlencode (next_search ),
0 commit comments