Apply PageType specific and Page specific boosts

@return \Elastica\Query\BoolQuery
481587
protected function getPageBoosts()
    {
        $rescoreQueryBool = new BoolQuery();

        //Apply page type boosts
        $pageClasses = $this->em->getRepository('KunstmaanNodeBundle:Node')->findAllDistinctPageClasses();
        foreach ($pageClasses as $pageClass) {
            $page = new $pageClass['refEntityName']();

            if ($page instanceof SearchBoostInterface) {
                $elasticaQueryTypeBoost = new QueryString();
                $elasticaQueryTypeBoost
                    ->setBoost($page->getSearchBoost())
                    ->setDefaultField('page_class')
                    ->setQuery(addslashes($pageClass['refEntityName']));

                $rescoreQueryBool->addShould($elasticaQueryTypeBoost);
            }
        }

        //Apply page specific boosts
        $nodeSearches = $this->em->getRepository('KunstmaanNodeSearchBundle:NodeSearch')->findAll();
        foreach ($nodeSearches as $nodeSearch) {
            $elasticaQueryNodeId = new QueryString();
            $elasticaQueryNodeId
                ->setBoost($nodeSearch->getBoost())
                ->setDefaultField('node_id')
                ->setQuery($nodeSearch->getNode()->getId());

            $rescoreQueryBool->addShould($elasticaQueryNodeId);
        }

        return $rescoreQueryBool;
    }
810569
protected function setPagerIndexCategory()
    {
        $pager = array(
            'total' => $this->data_total,
            'query' => $this->query_filter,
            'limit' => $this->configTheme('catalog_limit', 20)
        );

        return $this->data_limit = $this->setPager($pager);
    }
690807
public function prefixQuery() {
        
        $options = $this->getOptions();
        
        if ($this->validateOptions($options)) {
            $this->queryPrefix = $this->getDriverEscaper()->dbCommand('SELECT') . ' ';
            $fields = $this->setFieldList($options);
            $this->queryPrefix .= $fields . ' ' . $this->getDriverEscaper()->dbCommand('FROM') . ' ' . $this->getDriverEscaper()->reserved($options['table']) . ' ' . $this->getDriverEscaper()->dbCommand('WHERE') . ' ';
        }
        
        return $this;
    }
1266386
protected function wpQuery(): WpQuery
    {
        $hashDecoratedObject = spl_object_hash($this->decoratedWpQuery);
        $globalObject = spl_object_hash(Core::get(WpQuery::class));

        if ($hashDecoratedObject === $globalObject) {
            $this->wpProvider->wpResetQuery();
        }

        return $this->decoratedWpQuery;
    }
11612
private function query()
    {
        foreach ($this->search_models as $model_name => $filters) {
            // Apply search against the original model.
            if ($model_name === 'self') {
                self::applySearch($this->query, $filters);
                continue;
            }

            // Apply search against the related model.
            $this->query->whereHas($model_name, function ($query) use ($filters) {
                self::applySearch($query, $filters);
            });
        }

        return $this->query;
    }
352072
protected function query()
	{
		$query = forward_static_call(
			[
				$this->getModelClass(),
				'query',
			]
		);

		$this->modifyQuery($query);

		$eager_loads = $this->getEagerLoads();

		if ( !empty($eager_loads)) {
			$this->safeWith($query, $eager_loads);
		}

		if ( !empty($modifiers = $this->getModifiers())) {
			foreach ($modifiers as $modifier) {
				$modifier($query);
			}
		}

		return $query;
	}
952402
protected function applyDefaultFilters($query)
    {
        // If not filtering by a Term then skip this altogether
        if (empty($this->params['Term'])) {
            return parent::applyDefaultFilters($query);
        }

        // Get an array of SiteTree record IDs that match the search term in nested element data
        /** @var ArrayList $siteTrees */
        $siteTrees = $query->filterByCallback(function (SiteTree $siteTree) {
            // Filter by elemental PHP
            if (!$siteTree->hasExtension(ElementalPageExtension::class)) {
                return false;
            }

            // Check whether the search term exists in the nested page content
            $pageContent = $siteTree->getElementsForSearch();
            return (bool) stripos($pageContent, $this->params['Term']) !== false;
        });

        if ($siteTrees->count()) {
            // Apply the list of IDs as an extra filter
            $this->extraTermFilters['ID:ExactMatch'] = $siteTrees->column('ID');
        }

        return $this->applyWithExtraTermFilters($query);
    }
607749
protected function baseQuery()
    {
        if (empty($this->baseQuery) && $this->parent->getData()) {
            $pk = $this->parent->getPk();

            $this->query->where([
                [$this->morphKey, '=', $this->parent->$pk],
                [$this->morphType, '=', $this->type],
            ]);
            $this->baseQuery = true;
        }
    }
557877
public function VirtualPages()
    {
        $pages = parent::VirtualPages();

        // Disable subsite filter for these pages
        if ($pages instanceof DataList) {
            return $pages->setDataQueryParam('Subsite.filter', false);
        }
        return $pages;
    }
220028
public function PageTypes()
    {
        $classes = SiteTree::page_type_classes();

        $result = new ArrayList();

        foreach ($classes as $class) {
            $instance = SiteTree::singleton($class);
            if ($instance instanceof HiddenClass) {
                continue;
            }

            // skip this type if it is restricted
            $needPermissions = $instance->config()->get('need_permission');
            if ($needPermissions && !$this->can($needPermissions)) {
                continue;
            }

            $result->push(new ArrayData(array(
                'ClassName' => $class,
                'AddAction' => $instance->i18n_singular_name(),
                'Description' => $instance->i18n_classDescription(),
                'IconURL' => $instance->getPageIconURL(),
                'Title' => $instance->i18n_singular_name(),
            )));
        }

        $result = $result->sort('AddAction');

        return $result;
    }
379862
public function defineSearch($query, $type)
    {
        $query = Util::escapeTerm($query);

        $elasticaQueryString = new Match();
        $elasticaQueryString
            ->setFieldMinimumShouldMatch('content', '80%')
            ->setFieldQuery('content', $query);

        if ($this->useMatchQueryForTitle) {
            $elasticaQueryTitle = new Match();
            $elasticaQueryTitle
              ->setFieldQuery('title', $query)
              ->setFieldMinimumShouldMatch('title', '80%')
              ->setFieldBoost(2);
        } else {
            $elasticaQueryTitle = new QueryString();
            $elasticaQueryTitle
              ->setDefaultField('title')
              ->setQuery($query);
        }

        $elasticaQueryBool = new BoolQuery();
        $elasticaQueryBool
            ->addShould($elasticaQueryTitle)
            ->addShould($elasticaQueryString)
            ->setMinimumShouldMatch(1);

        $this->applySecurityFilter($elasticaQueryBool);

        if (!is_null($type)) {
            $elasticaQueryType = new Term();
            $elasticaQueryType->setTerm('type', $type);
            $elasticaQueryBool->addMust($elasticaQueryType);
        }

        $rootNode = $this->domainConfiguration->getRootNode();
        if (!is_null($rootNode)) {
            $elasticaQueryRoot = new Term();
            $elasticaQueryRoot->setTerm('root_id', $rootNode->getId());
            $elasticaQueryBool->addMust($elasticaQueryRoot);
        }

        $rescore = new \Elastica\Rescore\Query();
        $rescore->setRescoreQuery($this->getPageBoosts());

        $this->query->setQuery($elasticaQueryBool);
        $this->query->setRescore($rescore);
        $this->query->setHighlight(
            array(
                'pre_tags' => array('<strong>'),
                'post_tags' => array('</strong>'),
                'fields' => array(
                    'content' => array(
                        'fragment_size' => 150,
                        'number_of_fragments' => 3,
                    ),
                ),
            )
        );
    }
655320
public static function fetchAllPagesPageTypes()
    {
        $types = Symphony::Database()->fetch("SELECT `page_id`,`type` FROM `tbl_pages_types`");
        $page_types = array();

        if (is_array($types)) {
            foreach ($types as $type) {
                $page_types[$type['page_id']][] = $type['type'];
            }
        }

        return $page_types;
    }
493577
public function index()
    {
        $entries = WinkPage::when(request()->has('search'), function ($q) {
            $q->where('title', 'LIKE', '%'.request('search').'%');
        })
            ->orderBy('created_at', 'DESC')
            ->paginate(30);

        return PagesResource::collection($entries);
    }
749357
public function index()
    {
        $query = $this->Extensions->find('search', $this->Extensions->filterParams($this->request->getQueryParams()));

        $this
            ->set('plugins', $this->paginate($query))
            ->set('page_title', __d('extensions', 'The list of available plugins'));
    }
262210
public function getSearchPage() {

		$pages = ExtensibleSearchPage::get();

		// This is required to support multiple sites.

		if(ClassInfo::exists(Multisites::class)) {
			$pages = $pages->filter('SiteID', $this->owner->SiteID);
		}
		return $pages->first();
	}
23785
public function apply(Query $query) : Query
    {
        return $query->where(
            (new QueryExpression())->gt(
                $this->field,
                $this->value,
                $query->getTypeMap()->type($this->field)
            )
        );
    }
131756
public function PagedReplies()
    {
        $list = $this->Replies();

        // Add pagination
        $list = new PaginatedList($list, Controller::curr()->getRequest());
        $list->setPaginationGetVar('repliesstart' . $this->ID);
        $list->setPageLength($this->getOption('comments_per_page'));

        $this->extend('updatePagedReplies', $list);
        return $list;
    }