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

Add wildcards to each search token #48

Merged
merged 6 commits into from
Jan 31, 2024
Merged

Conversation

marijoo
Copy link
Contributor

@marijoo marijoo commented Jan 31, 2024

This PR resolves #47 by adding a new config setting wildcard_all_tokens which defaults to false and a setting wildcard_min_length which defines a minimum length for tokens before wildcards are applied.

I migratet the phpunit XML to the new version. If this is undesired, let me know and I will revert the commit.

Excerpt from the config file:

This setting controls whether all tokens of a search query shoudld be
handled using a wildcard instead of an exact match. This basically
means that for a search input of "hell wor", the query will match
documents containing "hell%" or "wor%" where % is the SQL wildcard of
a "like" condition. The wildcard will only be applied for
search tokens that have a minimum length of `wilcard_min_length`.
     
Setting this to `true` will add a wildcard to the end of each search
token. You may also set this to "both" to add wildcards to the beginning
and the end of each search token, for example: "%hell%" and "%wor%.
       
Note: Please not that changing this setting may negatively impact the
performance of search queries. Also you might want to make sure that
`require_match_for_all_tokens` is set to `false` when using this.

I added some test cases:

 ✔ Does not find documents if wildcard all tokens is disabled and no exact match is given
 ✔ Finds documents if wildcard all tokens is enabled and no exact match is given
 ✔ Finds documents if wildcard all tokens is set to both
 ✔ Does not find documents by wildcard if minimum token length is not reached
 ✔ Finds documents by wildcard if minimum token length is reached
 ✔ Adds wildcard to last token even if minimum length is not reached

Copy link
Owner

@Namoshek Namoshek left a comment

Choose a reason for hiding this comment

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

Thanks, looks good so far! Just some minor points that need adjustment

src/DatabaseSeeker.php Show resolved Hide resolved
src/SearchConfiguration.php Outdated Show resolved Hide resolved
src/SearchConfiguration.php Outdated Show resolved Hide resolved
@Namoshek Namoshek merged commit fba91e2 into Namoshek:master Jan 31, 2024
15 checks passed
@Namoshek
Copy link
Owner

Thank you!

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

Successfully merging this pull request may close these issues.

Question: Would another wildcard setting be an option?
2 participants