-
Notifications
You must be signed in to change notification settings - Fork 60
Description
Describe the bug 🐛
Thank you so much for all the hard work on this codebase, it's incredibly helpful.
Probably a set up issue on my end and not a bug, but wondering what the recommended way to handle pagination AND facet/filtering together. The example app is fantastic and I was able to create a pretty amazing app quickly, replicating many complicated filter behaviors. The only hangup is when using a pagination with filter facets, the paginated data doesn't automatically refresh when filters are applied.
Specifically, using the algolia.searcher.paginatedData(of: Hit<StockItem>.self) as the hitsViewModel doesn't seem to respond to changes in filter facets. When changing the text query, the results update with the filters applied.
- Are we doing things correctly? tried to follow the examples docs and connect the right things.
- Is there a recommended way or example to handle pagination with filters connected?
- Is there a better example to borrow from in the showcase you'd recommend?
- Is this a config issue (e.g. the facet used in the Algolia portal is actually set to not be searchable or similar issue).
To Reproduce 🔍
Steps to reproduce the behavior:
- Go to Examples Project for Algolia
- Click on Search > PaginationSingleIndex
- Add a
facetListConnectorto theSearchDemoSwiftUI.Controllerusing the demoController.searcher - Add a
facetListControllerto theSearchDemoSwiftUI.Controller - Initialize the facetListConnector with attribute in the index. I used
genderbut other facets might work. - Connect the
facetListConnectorto the controller. - Add
FacetListwidget to the switUI view, using aFacetRow
class Controller {
let demoController: EcommerceDemoController
let hitsController: HitsObservableController<Hit<StoreItem>>
let searchBoxController: SearchBoxObservableController
let statsController: StatsTextObservableController
let loadingController: LoadingObservableController
let facetListConnector: FacetListConnector
let facetListController: FacetListObservableController
init(searchTriggeringMode: SearchTriggeringMode) {
demoController = EcommerceDemoController(searchTriggeringMode: searchTriggeringMode)
hitsController = HitsObservableController()
searchBoxController = SearchBoxObservableController()
statsController = StatsTextObservableController()
loadingController = LoadingObservableController()
facetListController = FacetListObservableController()
facetListConnector = .init(
searcher: demoController.searcher,
attribute: "gender",
operator: .and
)
facetListConnector.connectController(facetListController)
demoController.searchBoxConnector.connectController(searchBoxController)
demoController.hitsInteractor.connectController(hitsController)
demoController.statsConnector.connectController(statsController)
demoController.loadingConnector.connectController(loadingController)
demoController.searcher.search()
}
}The swiftUI view with the facet list added:
struct ContentView: View {
@StateObject var hitsViewModel: PaginatedDataViewModel<AlgoliaHitsPage<Hit<StoreItem>>>
@ObservedObject var searchBoxController: SearchBoxObservableController
@ObservedObject var statsController: StatsTextObservableController
@ObservedObject var loadingController: LoadingObservableController
@ObservedObject var facetsListController: FacetListObservableController
var body: some View {
VStack {
HStack {
Text(statsController.stats)
Spacer()
if loadingController.isLoading {
ProgressView()
}
}
.padding(.trailing, 20)
// Apply Facet List Here
FacetList(facetsListController) { facet, isSelected in
FacetRow(facet: facet, isSelected: isSelected)
}
// Infinite Loading with Pagination
InfiniteList(hitsViewModel) { hit in
ProductRow(storeItemHit: hit)
.padding()
.frame(height: 100)
} noResults: {
Text("No Results")
}
}
.searchable(text: $searchBoxController.query)
.onSubmit(of: .search) {
searchBoxController.submit()
}
.padding(.horizontal, 15)
}
}Expected behavior 💭
A clear and concise description of what you expected to happen.
When filters/facets are changed, paginated data should reload via the searcher in SwiftUI views using the InfiniteList widget.
Screenshots 🖥
If applicable, add screenshots to help explain your problem.
This screenshot shows the code changes showing a filter list used to filter gender.

When applying this filter, the paginated data doesn't update. Only when typing the text "Men" does it actually update.

Environment:
- OS: iOS
- Version 18.1, Xcode 16.1 and Xcode 16.2
Additional context
Add any other context about the problem here.