Apply current category settings to the collection.

@return \Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\FilterableAttribute\Category\Collection
509905
public function applyCategory()
    {
        $this->joinCategoryData();
        $this->removeAdditionalTableDuplicateFields();
        $this->getSelect()->columns($this->getAdditionalColumns());

        $subSelect = new \Zend_Db_Expr(sprintf("(%s)", (string) $this->getSelect()));

        $this->_select = $this->getConnection()->select()->from($subSelect);

        return $this;
    }
820606
protected function addFilters()
    {
        if ($this->parser->getFilters()) {

            $this->query->whereRaw($this->parser->getFilters());
        }

        return $this;
    }
649960
protected function setDataCategoriesEditCategory()
    {
        $category_id = $this->getData('category.category_id');

        if (isset($category_id)) {

            $category_group_id = $this->getData('category_group.category_group_id');

            $options = array(
                'parent_id' => $category_id,
                'category_group_id' => $category_group_id
            );

            $children = $this->category->getTree($options);

            $exclude = array($category_id);
            foreach ($children as $child) {
                $exclude[] = $child['category_id'];
            }

            $categories = $this->getData('categories');
            $modified = array_diff_key($categories, array_flip($exclude));
            $this->setData('categories', $modified);
        }
    }
838671
public function current()
    {
        $value = current($this->data);

        return AccessHelper::isCollectionType($value) ? new static($value, $this->options) : $value;
    }
728325
public function getFilterCollection()
    {
        if (null === $this->filterCollection) {
            $this->filterCollection = new Filter\FilterCollection($this);
        }

        return $this->filterCollection;
    }
430321
public function filter()
    {
        $widgets = $this->applyFilters();

        return $widgets->sortBy(function (AbstractWidget $w1) {
            return $w1->getOrder();
        });
    }
1367382
protected function getListCategory()
    {
        $conditions = $this->query_filter;
        $conditions['category_group_id'] = $this->data_category_group['category_group_id'];
        $list = $this->category->getTree($conditions);

        $this->prepareListCategory($list);
        return $list;
    }
1082373
public function getCurrentCategory()
    {
        $currentCategory = $this->_coreRegistry->registry('current_category');
        if (null === $currentCategory) {
            // try if there is a product
            $currentProduct = $this->_coreRegistry->registry('product');
            if (null !== $currentProduct) {
                $productCatIds = $currentProduct->getCategoryIds();
                $firstCatId = reset($productCatIds);
                $currentCategory = $this->_categoryRepository->get(
                    $firstCatId,
                    $this->_storeManager->getStore()->getId()
                );
            }
        }
        return $currentCategory;
    }
260217
public function getSetCollectionAttributes()
    {
        $category = $this->vObj->getObjectAttributeCategory();
        $values = $category->getAttributeValues($this->vObj);
        $attribs = [];
        foreach ($values as $value) {
            $attribs[] = $value->getAttributeKey();
        }

        return $attribs;
    }
33065
private function getCategory()
    {
        $category = $this->loadCategory();

        $this->addVirtualCategoryData($category)
            ->addSelectedProducts($category)
            ->setSortedProducts($category);

        return $category;
    }
22189
protected function getFilters(): FilterCollection
    {
        if ($this->filters === null) {
            $this->filters = new FilterCollection();
            $this->filters->addFilter(new UserFilter());
        }
        return $this->filters;
    }
197362
public function getApplyFormSettings()
    {
        if (!$this->applyFormSettings) {
            $settings = new DisableElementsCapableFormSettings();
            $settings->setForm('Applications/Apply');
            $this->applyFormSettings = $settings;
        }
        return $this->applyFormSettings;
    }
1031202
private function applyFilters()
    {
        $layer      = $this->layerResolver->get();
        $filterList = $this->getFilterList();

        foreach ($filterList->getFilters($layer) as $filter) {
            $filter->apply($this->getRequest());
        }

        $layer->apply();

        return $this;
    }
970297
private function getCategoryCollection()
    {
        $categoryCollection = null;

        $suggestedTerms = $this->getSuggestedTerms();
        $terms          = [$this->queryFactory->get()->getQueryText()];

        if (!empty($suggestedTerms)) {
            $terms = array_merge($terms, $suggestedTerms);
        }

        $categoryCollection = $this->categoryCollectionFactory->create();
        $categoryCollection->addAttributeToSelect("is_active");
        $categoryCollection->setSearchQuery($terms);
        $categoryCollection->setPageSize($this->getResultsPageSize());

        return $categoryCollection;
    }
711215
protected function addFilters()
    {
        $search = static::$versionTransformer->getSearchValue();
        if ($search != '') {
            $this->addAllFilter($search);
        }
        $this->addColumnFilters();
        return $this;
    }
627634
public function applyRulesets()
    {
        // List of fields which actually need validation at this time.
        $fields = $this->getActualFields();

        foreach ($fields as $field) {
            $rulesets = $this->getRules($field);
            $this->active_field = $field;
            $this->prefix = '';
            $this->caption = '';
            foreach ($rulesets as $rules) {
                $this->applyRules($field, $rules);
            }
        }

        return $this;
    }
692102
protected function applyMetaFilters()
	{
		if (isset($this->meta_filters_applied)) {
			return $this->meta_filters_applied;
		}
		
		if (empty($this->filters)) {
			return $this->meta_filters_applied = false;
		}
		
		$meta_model = $this->model->metaModel();
		$meta_instance = new $meta_model;
		$meta_query = $meta_instance->newQuery();
		
		if (isset($this->meta_context)) {
			if (method_exists($meta_model, 'applyQueryContext')) {
				call_user_func_array(array($meta_model, 'applyQueryContext'), array($meta_query, $this->meta_context));
			}
		}
		
		$filters = $this->filters;
		$meta_query->where(function ($query) use ($filters) {
			foreach ($filters as $filter) {
				foreach ($filter['metas'] as $sub_filter) {
					if (isset($sub_filter['id'])) {
						$query->orWhere('id', $sub_filter['id']);
					}
					else if (isset($sub_filter['name'])) {
						$query->orWhere('name', $sub_filter['name']);
					}
				}
			}
		});
		
		$metas = $meta_query->get();
		$meta_items = $metas->lists('num_items', 'id');
		
		$found = array(
			'id'   => $metas->lists('id', 'id'),
			'name' => $metas->lists('id', 'name'),
		);
		
		foreach ($filters as &$filter) {
			$found_one = false;
			
			foreach ($filter['metas'] as $idx => &$sub_filter) {
				$key = isset($sub_filter['id']) ? 'id' : 'name';
				$key_value = $sub_filter[$key];
				
				if (!array_key_exists($key_value, $found[$key])) {
					unset($filter['metas'][$idx]);
					continue;
				}
				
				$found_one = true;
				$sub_filter['id'] = $found[$key][$key_value];
				
				$num_items = $meta_items[$found[$key][$key_value]];
				if (!isset($filter['num_items']) || $num_items > $filter['num_items']) {
					$filter['num_items'] = $num_items;
				}
			}
			
			if (!$found_one) {
				return $this->meta_filters_applied = false;
			}
			
			if (count($filter['metas']) > 1) {
				$filter['num_items'] += 100000000;
			}
		}
		
		usort($filters, function ($a, $b) {
			return ($a['num_items'] < $b['num_items']) ? -1 : 1;
		});
		
		$set_distinct = false;
		
		$first_filter = current(array_splice($filters, 0, 1));
		if (count($first_filter['metas']) > 1) {
			$this->where(function ($query) use ($first_filter) {
				foreach ($first_filter['metas'] as $f) {
					if (isset($f['value'])) {
						$query->orWhere(function ($query) use ($f) {
							$query->where('m.meta_id', $f['id']);
							$query->where('m.value', $f['operator'], $f['value']);
						});
					}
					else {
						$query->orWhere('m.meta_id', $f['id']);
					}
				}
			});
			
			if (!$set_distinct) {
				$this->distinct();
				$set_distinct = true;
			}
		}
		else {
			foreach ($first_filter['metas'] as $f) {
				$this->where('m.meta_id', $f['id']);
				if (isset($f['value'])) {
					$this->where('m.value', $f['operator'], $f['value']);
				}
			}
		}
		
		foreach ($filters as $i => $cur_filter) {
			$this->join("{$this->model->metableTable()} AS m{$i}", function ($join) use ($i, $cur_filter) {
				$join_query = $join->on('m.xref_id', '=', "m{$i}.xref_id");
				
				if (count($cur_filter['metas']) <= 1) {
					foreach ($cur_filter['metas'] as $f) {
						if (isset($f['value'])) {
							$join_query->where("m{$i}.meta_id", '=', $f['id']);
							$join_query->where("m{$i}.value", $f['operator'], $f['value']);
						}
						else {
							$join_query->where("m{$i}.meta_id", '=', $f['id']);
						}
					}
				}
			});
			
			if (count($cur_filter['metas']) > 1) {
				$this->where(function ($query) use ($cur_filter, $i) {
					foreach ($cur_filter['metas'] as $f) {
						if (isset($f['value'])) {
							$query->orWhere(function ($query2) use ($f, $i) {
								$query2->where("m{$i}.meta_id", $f['id']);
								$query2->where("m{$i}.value", $f['operator'], $f['value']);
							});
						}
						else {
							$query->orWhere("m{$i}.meta_id", $f['id']);
						}
					}
				});
				
				if (!$set_distinct) {
					$this->distinct();
					$set_distinct = true;
				}
			}
		}
		
		return $this->meta_filters_applied = true;
	}