public function where($items, array $keyValuePairs, $comparator = 'eq', $booleanOperator = 'and')
    {
        if (is_array($items)) {
            $items = new ArrayCollection($items);
        }
        if ($items instanceof PersistentCollection && !$items->isInitialized()) {
            $items->initialize();
        }

        $whereMethod = $booleanOperator . 'Where';

        $eb = new ExpressionBuilder();
        $criteria = new Criteria();
        foreach ($keyValuePairs as $key => $value) {
            if (is_array($value)) {
                if ($comparator === 'eq') {
                    $criteria->$whereMethod($eb->in($key, $value));
                    continue;
                } elseif ($comparator === 'neq') {
                    $criteria->$whereMethod($eb->notIn($key, $value));
                    continue;
                }
            }
            $criteria->$whereMethod($eb->$comparator($key, $value));
        }

        return $items->matching($criteria);
    }