@@ -104,6 +104,7 @@ class ElasticSearchQueryBuilder implements QueryBuilderInterface, ProtectedConte
104104 *
105105 * @param string $nodeType the node type to filter for
106106 * @return ElasticSearchQueryBuilder
107+ * @throws QueryBuildingException
107108 * @api
108109 */
109110 public function nodeType ($ nodeType )
@@ -224,14 +225,11 @@ public function from($from)
224225 * @param mixed $value Value for comparison
225226 * @return ElasticSearchQueryBuilder
226227 * @api
228+ * @throws QueryBuildingException
227229 */
228230 public function exactMatch ($ propertyName , $ value )
229231 {
230- if ($ value instanceof NodeInterface) {
231- $ value = $ value ->getIdentifier ();
232- }
233-
234- return $ this ->queryFilter ('term ' , [$ propertyName => $ value ]);
232+ return $ this ->queryFilter ('term ' , [$ propertyName => $ this ->convertValue ($ value )]);
235233 }
236234
237235 /**
@@ -241,10 +239,11 @@ public function exactMatch($propertyName, $value)
241239 * @param mixed $value Value for comparison
242240 * @return ElasticSearchQueryBuilder
243241 * @api
242+ * @throws QueryBuildingException
244243 */
245244 public function greaterThan ($ propertyName , $ value )
246245 {
247- return $ this ->queryFilter ('range ' , [$ propertyName => ['gt ' => $ value ]]);
246+ return $ this ->queryFilter ('range ' , [$ propertyName => ['gt ' => $ this -> convertValue ( $ value) ]]);
248247 }
249248
250249 /**
@@ -253,11 +252,12 @@ public function greaterThan($propertyName, $value)
253252 * @param string $propertyName Name of the property
254253 * @param mixed $value Value for comparison
255254 * @return ElasticSearchQueryBuilder
255+ * @throws QueryBuildingException
256256 * @api
257257 */
258258 public function greaterThanOrEqual ($ propertyName , $ value )
259259 {
260- return $ this ->queryFilter ('range ' , [$ propertyName => ['gte ' => $ value ]]);
260+ return $ this ->queryFilter ('range ' , [$ propertyName => ['gte ' => $ this -> convertValue ( $ value) ]]);
261261 }
262262
263263 /**
@@ -267,10 +267,11 @@ public function greaterThanOrEqual($propertyName, $value)
267267 * @param mixed $value Value for comparison
268268 * @return ElasticSearchQueryBuilder
269269 * @api
270+ * @throws QueryBuildingException
270271 */
271272 public function lessThan ($ propertyName , $ value )
272273 {
273- return $ this ->queryFilter ('range ' , [$ propertyName => ['lt ' => $ value ]]);
274+ return $ this ->queryFilter ('range ' , [$ propertyName => ['lt ' => $ this -> convertValue ( $ value) ]]);
274275 }
275276
276277 /**
@@ -279,11 +280,12 @@ public function lessThan($propertyName, $value)
279280 * @param string $propertyName Name of the property
280281 * @param mixed $value Value for comparison
281282 * @return ElasticSearchQueryBuilder
283+ * @throws QueryBuildingException
282284 * @api
283285 */
284286 public function lessThanOrEqual ($ propertyName , $ value )
285287 {
286- return $ this ->queryFilter ('range ' , [$ propertyName => ['lte ' => $ value ]]);
288+ return $ this ->queryFilter ('range ' , [$ propertyName => ['lte ' => $ this -> convertValue ( $ value) ]]);
287289 }
288290
289291 /**
@@ -775,4 +777,21 @@ public function __call($method, array $arguments)
775777
776778 return $ this ;
777779 }
780+
781+ /**
782+ * @param $value
783+ * @return mixed
784+ */
785+ protected function convertValue ($ value )
786+ {
787+ if ($ value instanceof NodeInterface) {
788+ return $ value ->getIdentifier ();
789+ }
790+
791+ if ($ value instanceof \DateTime) {
792+ return $ value ->format ('Y-m-d\TH:i:sP ' );
793+ }
794+
795+ return $ value ;
796+ }
778797}
0 commit comments