@@ -93,23 +93,47 @@ public function where(string $field, mixed $operator, mixed $value = null): stat
9393 return $ this ->whereNot ($ field , $ value );
9494 }
9595
96- if (func_num_args () === 2 ) {
97- [$ operator , $ value ] = ['= ' , $ operator ];
96+ $ this ->filter ->add ($ this ->makeWhere (...func_get_args ()));
97+
98+ return $ this ;
99+ }
100+
101+ public function orWhere (string $ field , mixed $ operator , mixed $ value = null ): static
102+ {
103+ if ($ operator === '!= ' ) {
104+ return $ this ->orWhereNot ($ field , $ value );
98105 }
99106
100- $ criteria = $ this ->createComparisonCriteria ($ this ->absolutePath ($ field ), $ operator , $ value );
101- $ this ->filter ->add ($ criteria );
107+ $ this ->should ->add ($ this ->makeWhere (...func_get_args ()));
102108
103109 return $ this ;
104110 }
105111
112+ protected function makeWhere (string $ field , mixed $ operator , mixed $ value = null ): Criteria
113+ {
114+ if (func_num_args () === 2 ) {
115+ [$ operator , $ value ] = ['= ' , $ operator ];
116+ }
117+
118+ return $ operator === '= '
119+ ? new Term ($ this ->absolutePath ($ field ), $ value )
120+ : new RangeBound ($ this ->absolutePath ($ field ), $ operator , $ value );
121+ }
122+
106123 public function whereNot (string $ field , mixed $ value ): static
107124 {
108125 $ this ->mustNot ->add (new Term ($ this ->absolutePath ($ field ), $ value ));
109126
110127 return $ this ;
111128 }
112129
130+ public function orWhereNot (string $ field , mixed $ value ): static
131+ {
132+ $ this ->should ->add (new Term ($ this ->absolutePath ($ field ), $ value ));
133+
134+ return $ this ;
135+ }
136+
113137 public function whereIn (string $ field , array |Arrayable $ values ): static
114138 {
115139 $ this ->filter ->add (new Terms ($ this ->absolutePath ($ field ), $ values ));
@@ -240,13 +264,6 @@ protected function addNestedCriteria(string $nested, Closure $filter, CriteriaCo
240264 return $ this ;
241265 }
242266
243- protected function createComparisonCriteria (string $ field , string $ operator , mixed $ value ): Criteria
244- {
245- return $ operator === '= ' || $ operator === '!= '
246- ? new Term ($ field , $ value )
247- : new RangeBound ($ field , $ operator , $ value );
248- }
249-
250267 protected function basePath (): string
251268 {
252269 return $ this ->path ;
0 commit comments