returns the number of search hits for a manufacturer.

@param int  $iShopSearchCacheId
@param bool $bApplyActiveFilter - set to true if you want to count only hits that match the current filter

@return int
488135
public function GetNumberOfHitsForSearchCacheId($iShopSearchCacheId, $bApplyActiveFilter = false)
    {
        $iNumHits = 0;

        if ($bApplyActiveFilter) {
            $query = "SELECT COUNT(DISTINCT `shop_search_cache_item`.`id`) AS hits
                    FROM `shop_search_cache_item`
              INNER JOIN `shop_article` ON `shop_search_cache_item`.`shop_article_id` = `shop_article`.`id`
               LEFT JOIN `shop_article_shop_category_mlt` ON `shop_article`.`id` = `shop_article_shop_category_mlt`.`source_id`
                   WHERE `shop_search_cache_item`.`shop_search_cache_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($iShopSearchCacheId)."'
                     AND `shop_article`.`shop_manufacturer_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->id)."'
                  ";
            $sFilter = TdbShop::GetActiveFilterString(TdbShopManufacturer::FILTER_KEY_NAME);
            if (!empty($sFilter)) {
                $query .= " AND {$sFilter}";
            }

            $query .= ' GROUP BY `shop_article`.`shop_manufacturer_id`';
        //        echo "<pre>".$query."</pre><br>";
        } else {
            $query = "SELECT COUNT(DISTINCT `shop_search_cache_item`.`id`) AS hits
                    FROM `shop_search_cache_item`
              INNER JOIN `shop_article` ON `shop_search_cache_item`.`shop_article_id` = `shop_article`.`id`
                   WHERE `shop_search_cache_item`.`shop_search_cache_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($iShopSearchCacheId)."'
                     AND `shop_article`.`shop_manufacturer_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->id)."'
                GROUP BY `shop_article`.`shop_manufacturer_id`
                 ";
        }
        if ($row = MySqlLegacySupport::getInstance()->fetch_assoc(MySqlLegacySupport::getInstance()->query($query))) {
            $iNumHits = $row['hits'];
        }

        return $iNumHits;
    }
1255520
public function countProductStatsLine()
    {
        $em = $this->getEntityManager();
        $query = $em->createQuery(
            'SELECT count(s.visits) as visit, s.day as day FROM EcommerceBundle:ProductStats as s GROUP BY s.day ORDER BY s.day ASC '
        );

        $stats = $query->getResult();

        return $stats;
    }
235977
protected function fetchExistsActivePromotion()
    {
        $query = "select 1 from " . getViewName('oxactions') . " where oxtype=2 and oxactive=1 and oxshopid='" . \OxidEsales\Eshop\Core\Registry::getConfig()->getShopId() . "' limit 1";

        return \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->getOne($query);
    }
694705
protected function _loadActiveUrl($iShopId)
    {
        $sActObject = null;
        if ($this->_sActSeoObject) {
            $sActObject = $this->_sActSeoObject;
        } elseif (is_array($aStatUrl = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('aStaticUrl'))) {
            $sActObject = $aStatUrl['oxseo__oxobjectid'];
        }

        if ($sActObject && $sActObject != '-1') {
            $this->_aViewData['sActSeoObject'] = $sActObject;

            $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
            $sQ = "select oxseourl, oxlang from oxseo where oxobjectid = " . $oDb->quote($sActObject) . " and oxshopid = " . $oDb->quote($iShopId);
            $oRs = $oDb->select($sQ);
            if ($oRs != false && $oRs->count() > 0) {
                while (!$oRs->EOF) {
                    $aSeoUrls[$oRs->fields['oxlang']] = [$sActObject, $oRs->fields['oxseourl']];
                    $oRs->fetchRow();
                }
                $this->_aViewData['aSeoUrls'] = $aSeoUrls;
            }
        }
    }
456482
function count($filter=NULL,array $options=NULL,$ttl=0) {
		$fw=\Base::instance();
		$cache=\Cache::instance();
		$tag='';
		if (is_array($ttl))
			list($ttl,$tag)=$ttl;
		if (!($cached=$cache->exists($hash=$fw->hash($fw->stringify(
			[$filter])).($tag?'.'.$tag:'').'.mongo',$result)) || !$ttl ||
			$cached[0]+$ttl<microtime(TRUE)) {
			$result=$this->collection->count($filter?:[]);
			if ($fw->CACHE && $ttl)
				// Save to cache backend
				$cache->set($hash,$result,$ttl);
		}
		return $result;
	}
459996
public function getIssuesCount (ContextSpecificationInterface $filter = null)
	{
		$count = count($this->issues);

		foreach ($this->getChildren($filter) as $child)
		{
			$count += $child->getIssuesCount($filter);
		}

		return $count;
	}
1282499
public function &GetFieldPkgShopListfilterItemList()
    {
        $oList = &$this->GetFromInternalCache('FieldPkgShopListfilterItemList');
        if (is_null($oList)) {
            $aTrigger = array('class' => __CLASS__, 'method' => 'GetFieldPkgShopListfilterItemList', 'id' => $this->id);
            $aTrigger['activeFilter'] = TGlobal::instance()->GetUserData(TdbPkgShopListfilterItem::URL_PARAMETER_FILTER_DATA);
            $bCaching = false;
            if (!is_array($aTrigger['activeFilter']) || 0 == count($aTrigger['activeFilter'])) {
                $bCaching = true;
            }
            $oList = null;
            $sKey = null;
            if ($bCaching) {
                /** @var CacheInterface $cache */
                $cache = \ChameleonSystem\CoreBundle\ServiceLocator::get('chameleon_system_core.cache');
                $sKey = $cache->GetKey($aTrigger);
                $oList = $cache->get($sKey);
            }
            if (null === $oList) {
                $oList = TdbPkgShopListfilterItemList::GetListForPkgShopListfilterId($this->id, $this->iLanguageId);
                $oList->bAllowItemCache = true;
                $i = 0;
                while ($oItem = $oList->Next()) {
                    ++$i;
                }
                $oList->GoToStart();
                if ($bCaching) {
                    $aCacheTrigger = array(array('table' => 'pkg_shop_listfilter_item', 'id' => null), array('table' => $this->table, 'id' => $this->id));
                    $cache->set($sKey, $oList, $aCacheTrigger);
                }
            }
            $this->SetInternalCache('FieldPkgShopListfilterItemList', $oList);
        }

        return $oList;
    }
323603
public function GetQueryRestrictionForActiveFilter()
    {
        $sQuery = $this->GetFromInternalCache('sQueryRestrictionForActiveFilter');
        if (null === $sQuery) {
            $databaseConnection = $this->getDatabaseConnection();
            $aValues = $this->aActiveFilterData;
            if (is_array($aValues) && count($aValues) > 0) {
                $sItemListQuery = $this->GetSQLQueryForQueryRestrictionForActiveFilter();
                $aIdList = array();
                if (!empty($sItemListQuery)) {
                    $tRes = MySqlLegacySupport::getInstance()->query($sItemListQuery);
                    $aIdList = array();
                    while ($aItemRow = MySqlLegacySupport::getInstance()->fetch_assoc($tRes)) {
                        $aIdList[] = $databaseConnection->quote($aItemRow['source_id']);
                    }
                }

                if (count($aIdList) > 0) {
                    if (defined(
                            'PKG_SHOP_LISTFILTER_ATTRIBUTE_FILTER_SELECT_VARIANTS'
                        ) && PKG_SHOP_LISTFILTER_ATTRIBUTE_FILTER_SELECT_VARIANTS
                    ) {
                        //now we have a list of variant article ids but we need parent ids so we fetch the parent id for each variant id without duplicates
                        $sParentQuery = 'SELECT `shop_article`.`variant_parent_id`
                                 FROM `shop_article`
                                WHERE `shop_article`.`id` IN ('.implode(',', $aIdList).")
                                AND `shop_article`.`variant_parent_id` != '' ";
                        $rResult = MySqlLegacySupport::getInstance()->query($sParentQuery);
                        $aIdList = array();

                        while ($aRow = MySqlLegacySupport::getInstance()->fetch_assoc($rResult)) {
                            if (!in_array($aRow['variant_parent_id'], $aIdList)) {
                                $aIdList[] = $databaseConnection->quote($aRow['variant_parent_id']);
                            }
                        }
                    }

                    $sQuery = '`shop_article`.`id` IN ('.implode(',', $aIdList).')';
                }
            }
            $this->SetInternalCache('sQueryRestrictionForActiveFilter', $sQuery);
        }

        return $sQuery;
    }
1285500
public static function &GetListForShopKeywords($iShopId, $aKeywordList, $iLanguageId = null)
    {
        if (null === $iLanguageId) {
            $iLanguageId = self::getMyLanguageService()->getActiveLanguageId();
        }
        $aKeywordList = TTools::MysqlRealEscapeArray($aKeywordList);
        $query = self::GetDefaultQuery($iLanguageId, "`shop_search_keyword_article`.`shop_id`= '".MySqlLegacySupport::getInstance()->real_escape_string($iShopId)."' AND `shop_search_keyword_article`.`name` IN ('".implode("','", $aKeywordList)."') AND (`shop_search_keyword_article`.`cms_language_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($iLanguageId)."' OR `shop_search_keyword_article`.`cms_language_id` = '') ");

        return TdbShopSearchKeywordArticleList::GetList($query, $iLanguageId);
    }
602672
public function GetNumberOfHits()
    {
        if ($this->fieldNumberOfRecordsFound < 0) {
            $query = "SELECT COUNT(*) AS recs FROM `shop_search_cache_item` WHERE `shop_search_cache_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->id)."'";
            if ($row = MySqlLegacySupport::getInstance()->fetch_assoc(MySqlLegacySupport::getInstance()->query($query))) {
                $this->fieldNumberOfRecordsFound = $row['recs'];
                $this->sqlData['number_of_records_found'] = $this->fieldNumberOfRecordsFound;
                $this->AllowEditByAll(true);
                $this->Save();
            }
        }

        return $this->fieldNumberOfRecordsFound;
    }
299414
public function searchIncidents($search, $by, $limit = 1, $num = 1000, $page = 1)
    {
        $incidents = $this->indexIncidents($num, $page)['data'];

        $filtered = array_filter(
            $incidents,
            function ($incident) use ($search, $by) {

                if (array_key_exists($by, $incident)) {
                    if (strpos($incident[$by], $search) !== false) {
                        return $incident;
                    }
                    if ($incident[$by] === $search) {
                        return $incident;
                    }
                }

                return false;
            }
        );

        if ($limit == 1) {
            return array_shift($filtered);
        }

        return array_slice($filtered, 0, $limit);
    }
1058468
public function searchTotal(array $filter, $or = false)
    {
        Argument::i()->test(2, 'bool');

        if (!$this->socket) {
            $this->connect();
        }

        //build a search criteria
        $search = array();
        foreach ($filter as $where) {
            $item = $where[0].' "'.$where[1].'"';
            if (isset($where[2])) {
                $item .= ' "'.$where[2].'"';
            }

            $search[] = $item;
        }

        //if this is an or search
        if ($or) {
            $search = 'OR ('.implode(') (', $search).')';
        } else {
            //this is an and search
            $search = implode(' ', $search);
        }

        $response = $this->call('UID SEARCH '.$search);

        //get the result
        $result = array_pop($response);

        //if we got some results
        if (strpos($result, 'OK') !== false) {
            //parse out the uids
            $uids = explode(' ', $response[0]);
            array_shift($uids);
            array_shift($uids);

            return count($uids);
        }

        //it's not okay just return 0
        return 0;
    }
1133820
@Override
	public List<CommerceWarehouse> findByG_A_P(long groupId, boolean active,
		boolean primary) {
		return findByG_A_P(groupId, active, primary, QueryUtil.ALL_POS,
			QueryUtil.ALL_POS, null);
	}
799554
public function search()
    {
        $this->load($this->params, '');
        $query = $this->getBasicQuery();
        $languageId = Language::getCurrent()->id;
        $category = Category::findOne($this->categoryId);

        if(!empty($this->filterModel) && $this->filterModel instanceof FilterModel) {
            if(!empty($this->filterModel->pfrom) && $this->filterModel->pfrom != $this->filterModel->minPrice) {
                $query->andWhere(['>=', $this->discountPriceQuery, $this->convertPrice($this->filterModel->pfrom)]);
            }
            if(!empty($this->filterModel->pto) && $this->filterModel->pto != $this->filterModel->maxPrice) {
                $query->andWhere(['<=', $this->discountPriceQuery, $this->convertPrice($this->filterModel->pto)]);
            }
            if(!empty($this->filterModel->vendors)) {
                $query->andWhere(['in', 'shop_product.vendor_id', $this->filterModel->vendors]);
            }
            if(!empty($this->filterModel->availabilities)) {
                $query->andWhere(['in', 'shop_product.availability', $this->filterModel->availabilities]);
            }

            if(!empty($this->filterModel->params)) {
                foreach ($category->filter->params as $filterParam) {
                    if(array_key_exists($filterParam->key, $this->filterModel->params)) {
                        $paramValues = $this->filterModel->params[$filterParam->key];
                        if(!empty($paramValues)) {
                            $key = $filterParam->key;
                            $paramName = $filterParam->translation->param_name;
                            $query->leftJoin("shop_param param_$key", "shop_product.id = param_$key.product_id");
                            $query->leftJoin("shop_param_translation paramt_$key", "param_$key.id = paramt_$key.param_id AND paramt_$key.language_id = $languageId AND paramt_$key.name = '$paramName'");
                            $whereQuery = ['or'];
                            for ($i = 0; $i < count($paramValues); $i++) {
                                $paramValue = $paramValues[$i];
                                $whereQuery[] = ['or',
                                    ["paramt_$key.value" => $paramValue],
                                    new Expression("FIND_IN_SET(:param$i" . "Value1_$key, paramt_$key.value)", [":param$i" . "Value1_$key" => $paramValue]),
                                    new Expression("FIND_IN_SET(:param$i" . "Value2_$key, paramt_$key.value)", [":param$i" . "Value2_$key" => " " . $paramValue])
                                ];
                            }
                            $query->andWhere($whereQuery);
                        }
                    }
                }
            }
        }


        switch (ArrayHelper::getValue($this->params, 'sort')) {
            case self::SORT_CHEAP:
                $query->select([
                    '`shop_product`.*',
                    $this->discountPriceQuery . ' AS discount_price'
                ]);

                $query->orderBy(['discount_price' => SORT_ASC]);
                break;

            case self::SORT_EXPENSIVE:
                $query->select([
                    '`shop_product`.*',
                    $this->discountPriceQuery . ' AS discount_price'
                ]);

                $query->orderBy(['discount_price' => SORT_DESC]);
                break;

            case self::SORT_OLD:
                $query->orderBy(['creation_time' => SORT_ASC]);
                break;

            case self::SORT_NEW:
                $query->orderBy(['creation_time' => SORT_DESC]);
                break;

            default:
                $query->orderBy(['category_id' => SORT_ASC, 'position' => SORT_ASC]);
        }

        $query->groupBy(['id']);

        $dataProvider = new ActiveDataProvider([
            'query' => $query
        ]);

        if ($this->validate()) {
            return $dataProvider;
        }
        else throw new Exception();
    }
493207
def search(self):
        """"""
        # Retrieve all Or filters pertinent to the special coverage query.
        should_filters = [
            es_filter.Terms(pk=self.query.get("included_ids", [])),
            es_filter.Terms(pk=self.query.get("pinned_ids", []))
        ]
        should_filters += self.get_group_filters()

        # Compile list of all Must filters.
        must_filters = [
            es_filter.Bool(should=should_filters),
            ~es_filter.Terms(pk=self.query.get("excluded_ids", []))
        ]

        return Content.search_objects.search().filter(es_filter.Bool(must=must_filters))
456087
public function getProductPageCount(int $pageSize = 100) : int
    {
        Assert::that($pageSize)->greaterThan(0, 'The $pageSize has to be positive');

        return (int)$this->master->doRequest(
            'GET',
            sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductDataService/{KEY}/ProductPageCount/%d', $pageSize)
        );
    }
988659
private static function getInstanceForCategory(TdbShopCategory $activeCategory, TdbShop $oShop)
    {
        $sPkgShopListfilterId = $activeCategory->GetFieldPkgShopListfilterIdRecursive();
        if (empty($sPkgShopListfilterId)) {
            if (!empty($oShop->fieldPkgShopListfilterCategoryFilterId)) {
                $sPkgShopListfilterId = $oShop->fieldPkgShopListfilterCategoryFilterId;
            }
        }

        if (!empty($sPkgShopListfilterId)) {
            return TdbPkgShopListfilter::GetNewInstance($sPkgShopListfilterId);
        }

        return null;
    }