algolia / algoliasearch-helper-flutter

⚡️ Building block to create instant-search applications with Flutter
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/flutter/
Other
21 stars 14 forks source link

Rerun of the search request #86

Open Ragnarokr45 opened 1 year ago

Ragnarokr45 commented 1 year ago

Describe the bug 🐛
Im faced with issue when Im sending the same search query using 'searcher.rerun()' method Im not receiving any results, and it can only be fixed by sending another request with new text. It was working while ago but now it's not. I also tried to do it with searcher.query('query') method but it's also not working

To Reproduce 🔍
Steps to reproduce the behavior:

  1. Send search query
  2. Receive search results
  3. Send the same search query again
  4. No results, no errors from searcher

Expected behavior 💭
Receiving search results after sending the same search query again

Screenshots 🖥
image

Environment:

Additional context

MaximusAshraf99 commented 9 months ago

I am facing the same issue. any updates?

MaximusAshraf99 commented 9 months ago

As a workaround, you can add a space to your query if it is the same as the last one, and it will be handled like a new search and return the expected result

VladislavFitz commented 7 months ago

Hi @Ragnarokr45, @MaximusAshraf99,

Apologies for the late response.

We have a unit test that verifies the expected behavior of the rerun method. To further investigate, could you set up a basic test on your end? Here's what you'd need to do:

This test procedure might be structured like this:

final searcher = HitsSearcher(
  applicationID: 'your_app_id',
  apiKey: 'your_api_key',
  indexName: 'your_index',
);

final responses = <SearchResponse>[];
searcher.responses.listen(responses.add);

for (var i = 0; i < 3; i++) {
  searcher.query('sony');
  await Future.delayed(const Duration(milliseconds: 500));
}

expect(
  responses.length,
  1,
  reason: 'Only one response should be emitted for duplicate queries',
);

searcher.rerun();
await Future.delayed(const Duration(milliseconds: 500));

expect(
  responses.length,
  2,
  reason: '2 responses should be emitted after rerun',
);

If this test works as expected and you receive two responses, it indicates that the functionality is operating correctly. In such a case, I would recommend reviewing your implementation to pinpoint potential discrepancies that might be causing different behavior in your environment.

nerder commented 4 months ago

I'm facing the same issue, here my workaround:

NOT working

    hitsSearcher.applyState((state) => state.copyWith(
          page: page,
          hitsPerPage: pageSize,
        ));
    hitsSearcher.rerun();

    //or

    hitsSearcher.applyState((state) => state.copyWith(
      query: state.query,
      page: page,
      hitsPerPage: pageSize,
    ));

working

    hitsSearcher.applyState((state) => state.copyWith(
          query: "${state.query ?? ""} ",
          page: page,
          hitsPerPage: pageSize,
        ));

The listen callback of hitsSearcher.responses is not triggered when using rerun nor when using applyState using the same exact query. My suspect is that there is some kind of caching happening in the sink that prevents the listen callback to be triggered.