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

Support like query (issue #37) #132

Closed
wants to merge 1 commit into from

Conversation

lunaticusz
Copy link

Q A
Is bugfix? no
New feature? yes
Breaks BC? no
Tests pass? yes
Fixed issues #37

Pull request for issue #37

@beowulfenator
Copy link
Collaborator

Thank you for taking the time to do this. However, the LIKE query is not as simple as it looks, so I suggest you make a few improvements before we pull this into the repo.

Take a look at how the original QueryBuilder implements LIKE queries:

...operand 1 should be a column or DB expression, and operand 2 be a string or an array representing the values that the column or DB expression should be like. For example, ['like', 'name', 'tester'] will generate name LIKE '%tester%'. When the value range is given as an array, multiple LIKE predicates will be generated and concatenated using AND. For example, ['like', 'name', ['test', 'sample']] will generate name LIKE '%test%' AND name LIKE '%sample%'. You may also provide an optional third operand to specify how to escape special characters in the values. The operand should be an array of mappings from the special characters to their escaped counterparts. If this operand is not provided, a default escape mapping will be used. You may use false or an empty array to indicate the values are already escaped and no escape should be applied. Note that when using an escape mapping (or the third operand is not provided), the values will be automatically enclosed within a pair of percentage characters.

Let's take our default escape values from this doc on Lucene.

So, try making the implementation resemble the original QueryBuilder:

  • Allow third parameter with escape character mappings
  • Allow second parameter to be array (not just a single string)
  • Join multiple likes with AND
  • Only add stars to the string if third parameter is empty

@beowulfenator
Copy link
Collaborator

Oh, and don't worry about the tests, an update is underway to fix that issue.

@beowulfenator
Copy link
Collaborator

To be implemented in 2.1, if at all.

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

Successfully merging this pull request may close these issues.

3 participants