askorama / orama

🌌 Fast, dependency-free, full-text and vector search engine with typo tolerance, filters, facets, stemming, and more. Works with any JavaScript runtime, browser, server, service!
https://docs.askorama.ai
Other
8.27k stars 273 forks source link

The sorting of search results randomly changes order after running the update function #629

Closed hawkup closed 4 months ago

hawkup commented 4 months ago

Describe the bug

When using a custom document ID and after running the update function, the ordering of search results randomly changes.

Here's a screen recording comparing the behavior between using a custom document ID and an auto-generated document ID.

https://github.com/oramasearch/orama/assets/2748846/2b532796-3f4b-4f39-8707-763bbd655215

To Reproduce

Link to code example: https://codesandbox.io/p/sandbox/zealous-lederberg-mc48tf?file=%2Fsrc%2FApp.tsx%3A30%2C52

  1. Create a schema with a custom document ID.
  2. Insert data with a custom document ID.
  3. Search with sorting (using another field, in my case, I use createdAt for sorting). The results from the search are ordered correctly.
  4. Run the update function to update one entity.
  5. Search with the same parameters again. The ordering of the results has changed.

Expected behavior

When using a custom document ID and after running the update function, the ordering of search results should not change.

Environment Info

OS: macOS Ventura 13.4.1
node: 18.19.0
orama: 2.0.5

Affected areas

Search

Additional context

No response

micheleriva commented 4 months ago

@allevo could you take a look when you have a moment?

allevo commented 4 months ago

Thanks for the report! I reproduced the issue in a test and sent a PR to fix it!

hawkup commented 4 months ago

@allevo Thank you so much. Tested it on the latest version, and it's fixed.