Skip to content

Commit db29289

Browse files
authored
Some documentation on how conditions are constructed
1 parent 2cc2335 commit db29289

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,62 @@ However, you should be able to leave all that conversion to be handled in the
102102
background by the client - just give it array/string/int/etc. data and get
103103
models and arrays back.
104104

105+
# Search Criteria
106+
107+
The search criteria is an array of search terms and logic operators,
108+
expressed in Polish Notation.
109+
110+
The logic operators, for comparing search terms, are:
111+
112+
* `&` - logical AND
113+
* `|` - logical OR
114+
* `!` - logical NOT
115+
116+
Each search term is a tuple of the form:
117+
118+
[field_name, operator, value]
119+
120+
The search term operators are:
121+
122+
* =
123+
* !=
124+
* >
125+
* >=
126+
* <
127+
* <=
128+
* like
129+
* ilike
130+
* in
131+
* not in
132+
* child_of
133+
* parent_left
134+
* parent_right
135+
136+
Example: search for a record where the name is like 'Fred%' or 'Jane%'
137+
and the partner ID is 1 or 2, would look like this:
138+
139+
```php
140+
[
141+
'&',
142+
'|',
143+
['name', 'like', 'Fred%'],
144+
['name', 'like', 'Jane%'],
145+
['partner_id', 'in', [1, 2]],
146+
]
147+
```
148+
149+
The Polish Notation works inner-most to outer-most.
150+
The first `&` operator takes the next two terms and 'AND's them.
151+
The first of the two terms is a `|` operator.
152+
The `|` operator then takes the next two terms and 'OR`s them,
153+
making a single condition as a result, which is fed to the 'AND'.
154+
The final term is fed to the 'AND' condition.
155+
The result is equivalent to:
156+
157+
```sql
158+
(name like 'Fred%' or 'Jane%') and partner_id in (1, 2)
159+
```
160+
105161
# Query methods
106162

107163
The following methods are supported and will return a collection:

0 commit comments

Comments
 (0)