src/searchOld/elastic/Search.php
public static function buildFilterQuery($params, $index, $types)
    {
        self::filterInput($params);
        $storageToId = (new Query())
            ->from(PropertyStorage::tableName())
            ->select('class_name')
            ->where(['class_name' => array_keys($types)])
            ->indexBy('id')
            ->column();
        $propData = (new Query())
            ->from(Property::tableName())
            ->select(['id', 'data_type', 'storage_id'])
            ->where([
                'id' => array_keys($params),
                'storage_id' => array_keys($storageToId),
                'in_search' => 1
            ])
            ->indexBy('id')
            ->all();
        $query = ['bool' => ['must' => []]];
        $currentLang = LanguageHelper::getCurrent();
        foreach ($params as $propId => $values) {
            $q = ['bool' => ['should' => []]];
            switch ($storageToId[$propData[$propId]['storage_id']]) {
                case EAV::class :
                    foreach ($values as $val) {
                        $q['bool']['should'][] = [
                            'bool' => ['must' => [['term' => [self::STATIC_VALUES_FILED . '.prop_id' => $propId]],
                                ['term' => [self::STATIC_VALUES_FILED . '.value_' . $currentLang . '.raw' => $val]]]]
                        ];
                    }
                    break;
                case StaticValues::class :
                    foreach ($values as $val) {
                        $q['bool']['should'][] = [
                            'bool' => ['must' => [['term' => [self::STATIC_VALUES_FILED . '.prop_id' => $propId]],
                                ['term' => [self::STATIC_VALUES_FILED . '.static_value_id' => $val]]]]
                        ];
                    }
                    break;
            }
            $query['bool']['must'][] = $q;
        }
        //will search against all types in given index by default
        return $a = [
            'index' => $index,
            'body' => [
                'query' => [
                    'constant_score' => [
                        'filter' => $query
                    ]
                ]
            ]
        ];
    }
public static function buildFilterQuery($params, $index, $types)
    {
        self::filterInput($params);
        $storageToId = (new Query())
            ->from(PropertyStorage::tableName())
            ->select('class_name')
            ->where(['class_name' => array_keys($types)])
            ->indexBy('id')
            ->column();
        $propData = (new Query())
            ->from(Property::tableName())
            ->select(['id', 'data_type', 'storage_id'])
            ->where([
                'id' => array_keys($params),
                'storage_id' => array_keys($storageToId),
                'in_search' => 1
            ])
            ->indexBy('id')
            ->all();
        $query = ['bool' => ['must' => []]];
        $currentLang = LanguageHelper::getCurrent();
        foreach ($params as $propId => $values) {
            $q = ['bool' => ['should' => []]];
            switch ($storageToId[$propData[$propId]['storage_id']]) {
                case EAV::class :
                    foreach ($values as $val) {
                        $q['bool']['should'][] = [
                            'bool' => ['must' => [['term' => [self::STATIC_VALUES_FILED . '.prop_id' => $propId]],
                                ['term' => [self::STATIC_VALUES_FILED . '.value_' . $currentLang . '.raw' => $val]]]]
                        ];
                    }
                    break;
                case StaticValues::class :
                    foreach ($values as $val) {
                        $q['bool']['should'][] = [
                            'bool' => ['must' => [['term' => [self::STATIC_VALUES_FILED . '.prop_id' => $propId]],
                                ['term' => [self::STATIC_VALUES_FILED . '.static_value_id' => $val]]]]
                        ];
                    }
                    break;
            }
            $query['bool']['must'][] = $q;
        }
        //will search against all types in given index by default
        return $a = [
            'index' => $index,
            'body' => [
                'query' => [
                    'constant_score' => [
                        'filter' => $query
                    ]
                ]
            ]
        ];
    }
public static function buildFilterQuery ( $ params , $ index , $ types ) { self :: filterInput ( $ params ) ; $ storageToId = ( new Query ( ) ) -> from ( PropertyStorage :: tableName ( ) ) -> select ( 'class_name' ) -> where ( [ 'class_name' => array_keys ( $ types ) ] ) -> indexBy ( 'id' ) -> column ( ) ; $ propData = ( new Query ( ) ) -> from ( Property :: tableName ( ) ) -> select ( [ 'id' , 'data_type' , 'storage_id' ] ) -> where ( [ 'id' => array_keys ( $ params ) , 'storage_id' => array_keys ( $ storageToId ) , 'in_search' => 1 ] ) -> indexBy ( 'id' ) -> all ( ) ; $ query = [ 'bool' => [ 'must' => [ ] ] ] ; $ currentLang = LanguageHelper :: getCurrent ( ) ; foreach ( $ params as $ propId => $ values ) { $ q = [ 'bool' => [ 'should' => [ ] ] ] ; switch ( $ storageToId [ $ propData [ $ propId ] [ 'storage_id' ] ] ) { case EAV :: class : foreach ( $ values as $ val ) { $ q [ 'bool' ] [ 'should' ] [ ] = [ 'bool' => [ 'must' => [ [ 'term' => [ self :: STATIC_VALUES_FILED . '.prop_id' => $ propId ] ] , [ 'term' => [ self :: STATIC_VALUES_FILED . '.value_' . $ currentLang . '.raw' => $ val ] ] ] ] ] ; } break ; case StaticValues :: class : foreach ( $ values as $ val ) { $ q [ 'bool' ] [ 'should' ] [ ] = [ 'bool' => [ 'must' => [ [ 'term' => [ self :: STATIC_VALUES_FILED . '.prop_id' => $ propId ] ] , [ 'term' => [ self :: STATIC_VALUES_FILED . '.static_value_id' => $ val ] ] ] ] ] ; } break ; } $ query [ 'bool' ] [ 'must' ] [ ] = $ q ; } //will search against all types in given index by default return $ a = [ 'index' => $ index , 'body' => [ 'query' => [ 'constant_score' => [ 'filter' => $ query ] ] ] ] ; }
Prepares filter query

@param array $params
@param string $index
@return array
Prepares filter query