<?php
namespace Claromentis\Search;

$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"] ?: array()) + array("_cacda84c05d3266a2ccc76b" . "15553369c" => base64_decode("bWljcm90a" . "W1l"), "_a591754a8ddcdbda9c8" . "0f1db4d911e14" => base64_decode("aXNf" . "bnVs" . "bA=="));
use ClaCache;
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["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_cacda84c05d3266a" . "2ccc76b15553369c"](true);
        $_a440aa35fb31f773bb627701c33c3300 = $sp->GetCacheKey();
        $cache = ClaCache::I(ClaCache::C_USER);
        if ($sp->CacheResult() && $sp->GetHash()) {
            $_5b9e0b249424e083c98c6c774649ba72 = $cache->Get($_a440aa35fb31f773bb627701c33c3300);
            if (!empty($_5b9e0b249424e083c98c6c774649ba72) && $_5b9e0b249424e083c98c6c774649ba72 instanceof Result) {
                return $_5b9e0b249424e083c98c6c774649ba72;
            }
        }
        $_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["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_cacda84c05d3266a2ccc76b15553369" . "c"](true) - $_97163d0c4d6da35d14321fdee5d196e4);
        if ($sp->CacheResult() && $sp->GetHash()) {
            $cache->Set($_a440aa35fb31f773bb627701c33c3300, $_b84d76d5e0190d40b8179a2d1aac1f78, 10000);
            
            
        }
        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["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_a591754a8ddcdbda9c80f1db4d911" . "e14"]($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["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_a591754a8ddcdbda9c80f1db4d911e1" . "4"]($this->url_builder)) {
            $this->url_builder = new HttpInterop\StandardQueryString();
        }
        return $this->url_builder;
    }
    
    
    
    
    public function SetUrlBuilder($_e78bb2ad5a9092a5e2d3d1a6aa295901)
    {
        $this->url_builder = $_e78bb2ad5a9092a5e2d3d1a6aa295901;
    }
}