Improvements in CDbCriteria->compare()

The intelligence in the CDBCriteria->compare() method for assessing the comparison operator is very good. However, if it allowed for multiple criteria, exact criteria, and exclusion terms to be passed for the same column at the same time, it would be great! I’m using the CGridView widget to display a list of products, however, the data in a column can only be filtered using one operator at a time. This makes it impossible for an end user to perform advanced filtering/searching.

Multiple Criteria Examples

For instance, if someone is using the grid to filter RAM, they may want to look for RAM with capacity between 4GB and 8GB. In it’s current state, compare() would only allow to search on those >=4 or <=8, but not both at the same time. Being able to combine the <>,>,>=,<,<= operators in a single compare() operation would be excellent.

A user may also want to include multiple text terms, such as:

  • corsair pc8500 ddr3

  • kingston or corsair

  • "GeIL Black Dragon"

If multiple operators are used, they should behave much as they do in search engines. All keywords should be included by default, but searched for separately (i.e. each individual word added to the search criteria using AND operators). Keywords separated by "or" should include results with one or both keywords on either side of the or (so one criteria added with an AND operator, with two keywords joined by an OR operator). Keywords enclosed in quotes should be sought for exactly.

Exclusion Criteria Example

Now let’s say I want to find a single RAM module that is 4GB. Well, when I search for RAM for sale with a 4GB capacity, I get a lot of results of 2 packaged 2GB modules which is not what I want. So I would want to add an exclusion criteria for “2 x 2GB”. The criteria could be entered as: -“2 x 2GB” (a combination of exclusion and an exact query, so an AND operator would be added to the criteria with a NOT on the entire phrase).

Has anyone done any work to further enhance the intelligence in the compare() method in a similar manner to what I’ve described? I think such enhancements would help to further advance Yii as the best framework. It certainly makes it easier and more intuitive for the end-user of a Web application.

I think this method "addBetweenCondition()" does what you describe? I may be incorrectly understanding your problem thou.