<?php
namespace Claromentis\Search;

$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"] ?: array()) + array("_cacda84c05d3266a2ccc76b155" . "53369c" => base64_decode("bWlj" . "cm90" . "aW1l"), "_a591754a8ddcdbda9" . "c80f1db4d911e14" => base64_decode("aXN" . "fbn" . "Vsb" . "A=="));
use Claromentis\Core\Services;
use Claromentis\Search\Client\ClientInterface as SearchClient;
use Claromentis\Search\Client\ElasticsearchResult;
use Claromentis\Search\Client\QueryInterface;
use ErrorHandler;




class Search extends ErrorHandler
{
    
    
    
    
    protected $search_client;
    
    
    
    
    protected $query_builder;
    
    
    
    
    protected $sp = null;
    
    
    
    
    protected $url_builder;
    
    
    
    
    
    
    
    
    public function Execute(Parameters $sp)
    {
        $_97163d0c4d6da35d14321fdee5d196e4 = $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_cacda84c05d3266a2ccc76b15" . "553369c"](true);
        $_5b59b1de7eda25d82d151750fd82a6c2 = $this->GetQueryBuilder();
        $_5b59b1de7eda25d82d151750fd82a6c2->SetParameters($sp);
        $this->sp = $sp;
        
        
        $_da20d5136ba7f273c040c2fbfb1a6ba2 = $this->ExecuteQuery($_5b59b1de7eda25d82d151750fd82a6c2);
        
        
        $sp->SetHash($sp->Save($sp->GetHash()));
        
        
        $_e579d55980ff9509e815eb197510a92f = $this->sp->GetPagesize();
        $_ccd9e402149a4aff4a20de187781aa41 = $this->sp->GetStart();
        $_5bad710f602ba712d6fc0b828fa42806 = clone $this->sp;
        $_5bad710f602ba712d6fc0b828fa42806->SetStart(0);
        $_30e40f3c8404df316effbfe6d1480b2c = $this->GetUrlBuilder()->BuildUrl($_5bad710f602ba712d6fc0b828fa42806);
        $_b84d76d5e0190d40b8179a2d1aac1f78 = new Result($_da20d5136ba7f273c040c2fbfb1a6ba2);
        $_b84d76d5e0190d40b8179a2d1aac1f78->InitPagination($_e579d55980ff9509e815eb197510a92f, $_ccd9e402149a4aff4a20de187781aa41, $_30e40f3c8404df316effbfe6d1480b2c);
        $_b84d76d5e0190d40b8179a2d1aac1f78->SetActualSearchTime($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_cacda84c05d3266a2ccc76b15553" . "369c"](true) - $_97163d0c4d6da35d14321fdee5d196e4);
        return $_b84d76d5e0190d40b8179a2d1aac1f78;
    }
    
    
    
    
    
    
    public function ExecuteQuery(QueryInterface $query)
    {
        $_da20d5136ba7f273c040c2fbfb1a6ba2 = $this->GetSearchClient()->Search($query);
        return $_da20d5136ba7f273c040c2fbfb1a6ba2;
    }
    
    
    
    
    
    
    
    
    
    
    public function GetSearchResults(Parameters $sp)
    {
        return $this->Execute($sp);
    }
    
    
    
    
    
    
    protected function GetSearchClient()
    {
        if (!$this->search_client) {
            $this->search_client = Services::I()->searcher;
        }
        return $this->search_client;
    }
    
    
    
    
    
    
    
    
    public function SetSearchClient(SearchClient $_68ffaaa31e3ba49ed9d6159fbee9f043)
    {
        $this->search_client = $_68ffaaa31e3ba49ed9d6159fbee9f043;
        return $this;
    }
    
    
    
    
    protected function GetQueryBuilder()
    {
        if ($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_a591754a8ddcdbd" . "a9c80f1db4d911e1" . "4"]($this->query_builder)) {
            $this->query_builder = new QueryBuilder();
        }
        return $this->query_builder;
    }
    
    
    
    
    public function SetQueryBuilder($_714e1da7f6235557a4490c30b448e1ad)
    {
        $this->query_builder = $_714e1da7f6235557a4490c30b448e1ad;
    }
    
    
    
    
    protected function GetUrlBuilder()
    {
        if ($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_a591754a8ddcdbda9c80f1db4d" . "911e14"]($this->url_builder)) {
            $this->url_builder = new HttpInterop\StandardQueryString();
        }
        return $this->url_builder;
    }
    
    
    
    
    public function SetUrlBuilder($_e78bb2ad5a9092a5e2d3d1a6aa295901)
    {
        $this->url_builder = $_e78bb2ad5a9092a5e2d3d1a6aa295901;
    }
}