@@ -122,7 +122,20 @@ public function find($params = [], $oneItem = false)
122
122
$ params = [$ params ];
123
123
}
124
124
125
+ $ reject = [];
125
126
if (is_array ($ params )) {
127
+
128
+ foreach ($ params as $ key => $ value ) {
129
+ if (is_string ($ value )) {
130
+ if (substr ($ value , 0 , 1 ) == '! ' ) {
131
+ $ reject [$ key ] = substr ($ value , 1 );
132
+ }
133
+ }
134
+ }
135
+ foreach (array_keys ($ reject ) as $ key ) {
136
+ unset($ params [$ key ]);
137
+ }
138
+
126
139
foreach ($ params as $ key => $ value ) {
127
140
if (is_numeric ($ key ) && $ value instanceof Contracts \Entity) {
128
141
$ type = $ this ->type ->getManager ()->findRepository ($ value )->getType ();
@@ -137,7 +150,7 @@ public function find($params = [], $oneItem = false)
137
150
}
138
151
}
139
152
140
- $ findKey = md5 (json_encode ($ query ).($ oneItem ? 'x ' : '' ));
153
+ $ findKey = md5 (json_encode ([ $ query, $ reject ] ).($ oneItem ? 'x ' : '' ));
141
154
if (array_key_exists ($ findKey , $ this ->findCache )) {
142
155
return $ this ->findCache [$ findKey ];
143
156
}
@@ -148,6 +161,26 @@ public function find($params = [], $oneItem = false)
148
161
}
149
162
150
163
$ values = count ($ query ) ? $ this ->type ->getIndexTuple ($ index , $ query ) : [];
164
+
165
+ if (count ($ reject )) {
166
+ $ if = [];
167
+ $ properties = $ this ->type ->getProperties ();
168
+ foreach ($ reject as $ key => $ value ) {
169
+ $ num = array_search ($ key , $ properties ) + 1 ;
170
+ if (!$ num ) {
171
+ throw new Exception ("Unknown property $ key " );
172
+ }
173
+ $ if [] = "tuple[ " .$ num .'] ~= ' .(is_numeric ($ value ) ? intval ($ value ):"' $ value' " );
174
+ }
175
+
176
+ return $ this ->evaluate ("
177
+ local result = {}
178
+ for _, tuple in box.space. " .$ this ->type ->getName ().'.index[ ' .$ index .']:pairs{ ' .implode (', ' , $ values )."} do
179
+ if ( " . implode (" && " , $ if ).") then table.insert(result, tuple) end
180
+ end
181
+ return result " );
182
+ }
183
+
151
184
$ data = $ this ->type ->getSpace ()->select ($ values , $ index );
152
185
153
186
$ result = [];
0 commit comments