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

Rerun of the search request #86

Open
Ragnarokr45 opened this issue Jun 12, 2023 · 4 comments
Open

Rerun of the search request #86

Ragnarokr45 opened this issue Jun 12, 2023 · 4 comments
Assignees

Comments

@Ragnarokr45
Copy link

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

@MaximusAshraf99
Copy link

MaximusAshraf99 commented Sep 21, 2023

I am facing the same issue.
any updates?

@MaximusAshraf99
Copy link

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 VladislavFitz self-assigned this Nov 23, 2023
@VladislavFitz
Copy link
Contributor

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.

@nerder
Copy link

nerder commented Mar 5, 2024

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.

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

4 participants