yiisoft / yii2-elasticsearch

Yii 2 Elasticsearch extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
427 stars 253 forks source link

implemented `like,match,match_pharse` in `Query::where()` #317

Closed Barton0403 closed 2 years ago

Barton0403 commented 2 years ago
Q A
Is bugfix?
New feature? ✔️
Breaks BC?
Fixed issues
beowulfenator commented 2 years ago

Hi! Thank you for your contribution. Could you make a few tiny changes to make this behave like the standard "like" query? To quote [the docs](https://www.yiiframework.com/doc/api/2.0/yii-db-queryinterface#where()-detail):

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%'. The method will properly quote the column name and escape special characters in the values. Sometimes, you may want to add the percentage characters to the matching value by yourself, you may supply a third operand false to do so. For example, ['like', 'name', '%tester', false] will generate name LIKE '%tester'.

Can you make sure that:

  1. Your code automatically adds the wildcard character to the beginning and the end of the query, so foo becomes *foo*?
  2. Your code does not do that if the third parameter is false.
  3. Your code handles the case when the second operand is an array?
  4. Could you add these cases to tests?

Thank you so much!

Barton0403 commented 2 years ago

Sorry, after the test, I found the wildcard was not like like . If I search for yii*, I still get I love yii!. So I decide not to implement like query.