algoliasearch-helper-flutter icon indicating copy to clipboard operation
algoliasearch-helper-flutter copied to clipboard

Rerun of the search request

Open Ragnarokr45 opened this issue 2 years ago • 4 comments
trafficstars

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:

  • OS: iOS 16.4
  • Library Version 0.2.3, 0.3.1

Additional context

Ragnarokr45 avatar Jun 12 '23 10:06 Ragnarokr45

I am facing the same issue. any updates?

MaximusAshraf99 avatar Sep 21 '23 09:09 MaximusAshraf99

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

MaximusAshraf99 avatar Sep 21 '23 10:09 MaximusAshraf99

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:

  • Instantiate a searcher.
  • Subscribe to its responses stream and collect the responses in a list.
  • Use the query method to initiate a search.
  • Rerun the same search.
  • Afterwards, verify if your list of responses contains exactly 2 entries.

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.

VladislavFitz avatar Nov 23 '23 22:11 VladislavFitz

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.

nerder avatar Mar 05 '24 12:03 nerder