Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paged Data Source doesn't refresh when filters are applied, only when text query is active (possible bug, example requested) #334

Open
RGG-jayoung opened this issue Dec 10, 2024 · 0 comments

Comments

@RGG-jayoung
Copy link

RGG-jayoung commented Dec 10, 2024

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.

  1. Are we doing things correctly? tried to follow the examples docs and connect the right things.
  2. Is there a recommended way or example to handle pagination with filters connected?
  3. Is there a better example to borrow from in the showcase you'd recommend?
  4. 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:

  1. Go to Examples Project for Algolia
  2. Click on Search > PaginationSingleIndex
  3. Add a facetListConnector to the SearchDemoSwiftUI.Controller using the demoController.searcher
  4. Add a facetListController to the SearchDemoSwiftUI.Controller
  5. Initialize the facetListConnector with attribute in the index. I used gender but other facets might work.
  6. Connect the facetListConnector to the controller.
  7. Add FacetList widget to the switUI view, using a FacetRow
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.
image

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

Environment:

  • OS: iOS
  • Version 18.1, Xcode 16.1 and Xcode 16.2

Additional context
Add any other context about the problem here.

@RGG-jayoung RGG-jayoung changed the title Paged Data Source doesn't refresh when filters are applied, only when text query is active (example requested) Paged Data Source doesn't refresh when filters are applied, only when text query is active (possible bug, example requested) Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant