Skip to content

fix: ensure exact:true matches entire property value, not tokens #942

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

luffy-orf
Copy link

PR Description

  • Fixes exact search behavior:

    • Ensures that exact: true matches only when the entire property value (not just a token/word) matches the search term, case-insensitively.
    • This prevents partial/token matches (e.g., "First Note.md" will not match "first" with exact: true).
  • Distinguishes between property-value and token-level exactness:

    • exact: true → matches the whole property value.
    • exactToken: true → matches individual tokens/words exactly.
  • Adds/clarifies documentation and code comments:

    • Clearly explains the difference between exact and exactToken in both code and types.
  • How this solves the issue:

    • Users searching with exact: true now get results only when the property value is an exact match, as expected.
    • No more false positives from partial/token matches.

Solves - #866
/claim #866

Copy link

vercel bot commented May 24, 2025

@luffy-orf is attempting to deploy a commit to the OramaSearch Team on Vercel.

A member of the Team first needs to authorize it.

@luffy-orf
Copy link
Author

@zeroliu @micheleriva ,
Could you please review the PR and let me know if any changes are needed?

Also, just wanted to mention that this is my first time contributing here — happy to be part of the project!

Thanks!

@zeroliu
Copy link

zeroliu commented May 24, 2025

Do you know what the best way is to test these changes on my end? Can some unit tests be included? I only used Orama as a user and not very familiar with the process either

* If true, only documents where individual tokens (words) in the property match the search term exactly will be returned.
* This is different from `exact`, which matches the entire property value.
*/
exactToken?: boolean
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this props used?

@vachmara
Copy link

Hi @luffy-orf,

I wanted to clarify the context between PR #941 (my submission) and PR #942.
PR #942 appears to be a direct copy of my code from #941, with only a comment added, so it doesn’t address the full scope, including test coverage and refactoring, that I provided.

Regarding the renaming of exact to exactToken @zeroliu :
I introduced this breaking change to avoid removing a feature that existing Orama users may rely on. By making the distinction explicit, we can support both behaviors more clearly. All related tests have been updated to reflect this.

I do recognize that introducing a breaking change isn’t ideal for everyone, and I’m open to suggestions, such as creating a new search option like strictlyExact to maintain full backward compatibility if that’s preferred.

If you’d like to test the changes locally, I recommend:

git clone https://github.com/vachmara/orama.git
cd packages/orama
pnpm i 
pnpm run test

You can experiment further in the search.test.ts file.

Happy to iterate on this based on the maintainers’ and community’s feedback!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants