WordPress

Briefly unavailable for scheduled maintenance.
Check back in a some hours.
403WebShell
403Webshell
Server IP : 38.242.244.58  /  Your IP : 216.73.217.62
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1486879.contaboserver.net 5.4.0-166-generic #183-Ubuntu SMP Mon Oct 2 11:28:33 UTC 2023 x86_64
User : root ( 0)
PHP Version : 7.4.3-4ubuntu2.19
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/sura/src/SearchRepository/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/sura/src/SearchRepository/StockSearchRepository.php
<?php


namespace App\SearchRepository;


use App\Entity\Stock;
use App\Entity\StockType;
use App\Entity\User;
use Elastica\Query;
use FOS\ElasticaBundle\Repository;

class StockSearchRepository extends Repository
{
    public function search($search, $type, $page=1, $limit=10000)
    {
        $query = new Query();

        $boolQuery = new Query\BoolQuery();

        if (isset($search)){
            //Published
            $publishedQuery = new Query\Term();
            $publishedQuery->setTerm('Published', false);

            //hibernated
            $hibernatedQuery = new Query\Term();
            $hibernatedQuery->setTerm('Hibernated', false);

            //contributor suspended
            $suspendedQuery = new Query\Term();
            $suspendedQuery->setTerm('contributorSuspended', true);

            //$typeQuery = new Query\Match();
            $typeQuery = new Query\Match();
            $typeQuery->setFieldQuery('type.id', $type);
            $typeQuery->setFieldAnalyzer('type.id', "keyword_analyzer");

            //keywords
            $keywordsQuery = new Query\MatchPhrasePrefix();
            $keywordsQuery->setFieldQuery('keywords', $search);
            $keywordsQuery->setFieldAnalyzer("keywords", "keyword_analyzer");
//            $keywordsQuery->setFieldParam("keywords", "analyzer","keyword_analyzer");

            //title
            $titleQuery = new Query\QueryString();
            $titleQuery->setQuery($search);
            $titleQuery->setAnalyzer('keyword_analyzer');

            //id
            $idQuery = new Query\Match();
            $idQuery->setFieldQuery("suraID", (int)$search);
            $idQuery->setFieldAnalyzer("suraID", "keyword_analyzer");

            $innerIdBool = new Query\BoolQuery();
            $innerIdBool->addMustNot($publishedQuery);
            //$innerIdBool->addMustNot($hibernatedQuery);
            $innerIdBool->addShould($idQuery);


            if (count($this->find($innerIdBool)) > 0){
                return $this->find($innerIdBool);
            }

            if($search == ""){
                $innerQuery = new Query();
                $myBool = new Query\BoolQuery();
                $myBool->addMustNot($publishedQuery);
                //$myBool->addMustNot($hibernatedQuery);
                $myBool->addMustNot($suspendedQuery);
                $myBool->addMust($typeQuery);

                $innerQuery->setQuery($myBool);
                return $this->find($innerQuery,$limit);
            }



            $innerBoolQuery = new Query\BoolQuery();
            $innerBoolQuery->addShould($titleQuery);
            $innerBoolQuery->addShould($keywordsQuery);

            $boolQuery->addMust($innerBoolQuery);
            $boolQuery->addMust($typeQuery);
            $boolQuery->addMustNot($publishedQuery);
            //$boolQuery->addMustNot($hibernatedQuery);
            $boolQuery->addMustNot($suspendedQuery);
        }

        $query->setQuery($boolQuery);
        //$query->setSort(["id"=>"DESC"]);
        $query->setSize($limit);

        $results = $this->createPaginatorAdapter($query);

        //return $results;
        return $this->find($query);
    }

    public function search_filter($search, $licence, $imageType, $orientation, $people, $category,$contributor,$is_exclusive, $type, $search_category,$video_resolution, $limit=1000)
    {
        $query = new Query();
        $boolQuery = new Query\BoolQuery();
        if (isset($licence) && isset($imageType) && isset($orientation) && isset($people) && isset($category)){
            $licenceQuery = new Query\Match();
            $licenceQuery->setFieldQuery("LicenceType", $licence);
            $licenceQuery->setFieldAnalyzer("LicenceType", "keyword_analyzer");

            $orientationQuery = new Query\MatchPhrasePrefix();
            $orientationQuery->setFieldQuery("orientation", $orientation);
            $orientationQuery->setFieldAnalyzer("orientation", "keyword_analyzer");



            $peopleQuery = new Query\Match();
            $peopleQuery->setFieldQuery("peopleNo", $people);
            $peopleQuery->setFieldAnalyzer("peopleNo", "keyword_analyzer");



            //category
            if ($category != ""){
                $categoryQuery = new Query\Match();
                $category3Query = new Query\Match();
                $categoryQuery->setFieldQuery('category.id', (int)$category);
                $category3Query->setFieldQuery('stocksCats.categoryStockCat.id', (int)$category);
                $categoryQuery->setFieldAnalyzer("category.id", "keyword_analyzer");
                $category3Query->setFieldAnalyzer("stocksCats.categoryStockCat.id", "keyword_analyzer");
                $boolQuery->addShould($categoryQuery);
                $boolQuery->addMust($category3Query);
            }

            //Published
            $publishedQuery = new Query\Term();
            $publishedQuery->setTerm('Published', false);

            if ($licence != ""){
                $boolQuery->addMust($licenceQuery);
            }
            if($imageType != ""){
                $field = $type == 5 ? "videoType" : "image_type";
                $imageTypeQuery = new Query\Match();
                $imageTypeQuery->setField($field, $imageType);
//                $imageTypeQuery->setFieldAnalyzer($field, "keyword_analyzer");
                $boolQuery->addMust($imageTypeQuery);
            }
            if ($people != ""){
                $boolQuery->addMust($peopleQuery);
            }
            if ($orientation != ""){
                $boolQuery->addMust($orientationQuery);
            }

            //contributor
            if ($contributor != ""){
                $contributorQuery = new Query\Match();
                $contributorQuery->setFieldQuery('contributor.id', (int)$contributor);
                $contributorQuery->setFieldAnalyzer('contributor.id', "keyword_analyzer");
                $boolQuery->addMust($contributorQuery);
            }

            //is_exclusive
            if ($is_exclusive){
                $exclusiveQuery = new Query\Term();
                $exclusiveQuery->setTerm('contributor.is_exclusive', true);
                $boolQuery->addMust($exclusiveQuery);
            }

            //video resolution
            if ($video_resolution != "" && $video_resolution != "undefined"){
                $videoResolutionQuery = new Query\Match();
                $videoResolutionQuery->setFieldQuery('videoResolution', $video_resolution);
                $videoResolutionQuery->setFieldAnalyzer("videoResolution", "keyword_analyzer");
                $boolQuery->addMust($videoResolutionQuery);
            }

            $innerBoolQuery = new Query\BoolQuery();

            //if in category
            if ($search_category != "null"){
                $search_category_query = new Query\Match();
                $category3Query = new Query\Match();
                $search_category_query ->setFieldQuery( 'category.id', (int)$search_category );
                $search_category_query->setFieldAnalyzer('category.id', "keyword_analyzer");
                $category3Query->setFieldQuery('stocksCats.categoryStockCat.id', (int)$category);
                $category3Query->setFieldAnalyzer('stocksCats.categoryStockCat.id', "keyword_analyzer");
                $boolQuery->addShould($search_category_query);
                $boolQuery->addMust($category3Query);
            }
            //if in search/type
            if ($type != null && $type != "null"){
                $typeQuery = new Query\Match();
                $typeQuery->setFieldQuery('type.id', $type);
                $typeQuery->setFieldAnalyzer('type.id', "keyword_analyzer");
                $boolQuery->addMust($typeQuery);
            }

            //keywords
            $keywordsQuery = new Query\MatchPhrasePrefix();
            $keywordsQuery->setFieldQuery('keywords', $search);
            $keywordsQuery->setFieldAnalyzer('keywords', "keyword_analyzer");

            //title
            $titleQuery = new Query\QueryString();
            $titleQuery->setQuery($search);
            $titleQuery->setAnalyzer('keyword_analyzer');

            //id
            $idQuery = new Query\Match();
            $idQuery->setFieldQuery("id", (int)$search);
            $idQuery->setFieldAnalyzer('id', "keyword_analyzer");

            //hibernated
            $hibernatedQuery = new Query\Term();
            $hibernatedQuery->setTerm('Hibernated', false);

            if ($search != ""){
                $innerBoolQuery->addShould($keywordsQuery);
                $innerBoolQuery->addShould($titleQuery);
                $innerBoolQuery->addShould($idQuery);
            }

            $suspendedQuery = new Query\Term();
            $suspendedQuery->setTerm('contributorSuspended', true);

            $boolQuery->addMustNot($suspendedQuery);

            $boolQuery->addMustNot($publishedQuery);
            //$boolQuery->addMustNot($hibernatedQuery);
            $boolQuery->addMust($innerBoolQuery);


        }

        $query->setQuery($boolQuery);
        //$query->setSort(["id"=>"DESC"]);
        $query->setSize($limit);

        $results = $this->createPaginatorAdapter($query);

//        return $results;
        return $this->find($query);
    }

    public function search_stock_category($category, $type, $limit=10000)
    {
        $query = new Query();
        $boolQuery = new Query\BoolQuery();

        //Published
        $publishedQuery = new Query\Term();
        $publishedQuery->setTerm('Published', false);

        //$typeQuery = new Query\Match();
        $typeQuery = new Query\MatchPhrase();
        $typeQuery->setFieldQuery('type.id', $type);
        $typeQuery->setFieldAnalyzer('type.id', "keyword_analyzer");

        //hibernated
        $hibernatedQuery = new Query\Term();
        $hibernatedQuery->setTerm('Hibernated', false);

        //category
        if ($category != ""){
            $innerCatBool = new Query\BoolQuery();
            $categoryQuery = new Query\Match();
            $category2Query = new Query\Match();
            $category3Query = new Query\Match();
            $categoryQuery->setFieldQuery('category.id', (int)$category);
            $categoryQuery->setFieldAnalyzer('category.id', "keyword_analyzer");
            $category2Query->setFieldQuery('category2.id', (int)$category);
            $category2Query->setFieldAnalyzer('category2.id', "keyword_analyzer");
            $category3Query->setFieldQuery('stocksCats.categoryStockCat.id', (int)$category);
            $category3Query->setFieldAnalyzer('stocksCats.categoryStockCat.id', "keyword_analyzer");

            $innerCatBool->addShould($categoryQuery);
            $innerCatBool->addShould($category2Query);
            $innerCatBool->addShould($category3Query);
            $boolQuery->addMust($innerCatBool);
        }
        $suspendedQuery = new Query\Term();
        $suspendedQuery->setTerm('contributorSuspended', true);

        $boolQuery->addMustNot($suspendedQuery);

        $boolQuery->addMustNot($publishedQuery);
        //$boolQuery->addMustNot($hibernatedQuery);
        $boolQuery->addMust($typeQuery);

        $query->setQuery($boolQuery);
        $query->setSize($limit);

//        return $this->createPaginatorAdapter($query);
        return $this->find($query);
    }
    public function search_stock_category_video_filter($category, $licence, $people, $contributor, $is_exclusive, $videoType,  $limit=10000)
    {
        $type = 5;
        $query = new Query();
        $boolQuery = new Query\BoolQuery();

        //Published
        $publishedQuery = new Query\Term();
        $publishedQuery->setTerm('Published', false);

        //$typeQuery = new Query\Match();
        $typeQuery = new Query\MatchPhrase();
        $typeQuery->setFieldQuery('type.id', $type);
        $typeQuery->setFieldAnalyzer('type.id', "keyword_analyzer");

        //hibernated
        $hibernatedQuery = new Query\Term();
        $hibernatedQuery->setTerm('Hibernated', false);

        //category
        if ($category != ""){
            $innerCatBool = new Query\BoolQuery();
            $categoryQuery = new Query\Match();
            $category2Query = new Query\Match();
            $category3Query = new Query\Match();
            $categoryQuery->setFieldQuery('category.id', (int)$category);
            $categoryQuery->setFieldAnalyzer('category.id', "keyword_analyzer");
            $category2Query->setFieldQuery('category2.id', (int)$category);
            $category2Query->setFieldAnalyzer('category2.id', "keyword_analyzer");
            $category3Query->setFieldQuery('stocksCats.categoryStockCat.id', (int)$category);
            $category3Query->setFieldAnalyzer('stocksCats.categoryStockCat.id', "keyword_analyzer");

            $innerCatBool->addShould($categoryQuery);
            $innerCatBool->addShould($category2Query);
            $innerCatBool->addShould($category3Query);
            $boolQuery->addMust($innerCatBool);
        }

        //filter
        if ($licence != ""){
            $licenceQuery = new Query\Match();
            $licenceQuery->setFieldQuery("LicenceType", $licence);
            $licenceQuery->setFieldAnalyzer('LicenceType', "keyword_analyzer");
            $boolQuery->addMust($licenceQuery);
        }
        if ($people != ""){
            $peopleQuery = new Query\Match();
            $peopleQuery->setFieldQuery("peopleNo", $people);
            $peopleQuery->setFieldAnalyzer('peopleNo', "keyword_analyzer");
            $boolQuery->addMust($peopleQuery);
        }
        if ($contributor != ""){
            $contributorQuery = new Query\Match();
            $contributorQuery->setFieldQuery('contributor.id', (int)$contributor);
            $contributorQuery->setFieldAnalyzer('contributor.id', "keyword_analyzer");
            $boolQuery->addMust($contributorQuery);
        }
        if ($is_exclusive){
            $exclusiveQuery = new Query\Term();
            $exclusiveQuery->setTerm('contributor.is_exclusive', true);
            $boolQuery->addMust($exclusiveQuery);
        }
        if($videoType != ""){
            $imageTypeQuery = new Query\Match();
            $imageTypeQuery->setFieldQuery("videoType", $videoType);
            $imageTypeQuery->setFieldAnalyzer('videoType', "keyword_analyzer");
            $boolQuery->addMust($imageTypeQuery);
        }


        $suspendedQuery = new Query\Term();
        $suspendedQuery->setTerm('contributorSuspended', true);

        $boolQuery->addMustNot($suspendedQuery);

        $boolQuery->addMustNot($publishedQuery);
        //$boolQuery->addMustNot($hibernatedQuery);
        $boolQuery->addMust($typeQuery);

        $query->setQuery($boolQuery);
        $query->setSize($limit);

//        return $this->createPaginatorAdapter($query);
        return $this->find($query);
    }

    public function search_filter_category($search, $licence, $imageType, $orientation, $people, $category,$contributor,$is_exclusive,$type, $limit=1000 )
    {
        $query = new Query();
        $boolQuery = new Query\BoolQuery();
        if (isset($licence) && isset($imageType) && isset($orientation) && isset($people) && isset($category)){
            $licenceQuery = new Query\Match();
            $licenceQuery->setFieldQuery("LicenceType", $licence);
            $licenceQuery->setFieldAnalyzer('LicenceType', "keyword_analyzer");

            $orientationQuery = new Query\MatchPhrasePrefix();
            $orientationQuery->setFieldQuery("orientation", $orientation);
            $orientationQuery->setFieldAnalyzer('orientation', "keyword_analyzer");



            $peopleQuery = new Query\Match();
            $peopleQuery->setFieldQuery("peopleNo", $people);
            $peopleQuery->setFieldAnalyzer('peopleNo', "keyword_analyzer");

            //Published
            $publishedQuery = new Query\Term();
            $publishedQuery->setTerm('Published', false);

            if ($licence != ""){
                $boolQuery->addMust($licenceQuery);
            }
            if($imageType != ""){
                $imageTypeQuery = new Query\Match();
                $imageTypeQuery->setFieldQuery("image_type", $imageType);
//                $imageTypeQuery->setFieldAnalyzer('image_type', "keyword_analyzer");
                $boolQuery->addMust($imageTypeQuery);
            }
            if ($people != ""){
                $boolQuery->addMust($peopleQuery);
            }
            if ($orientation != ""){
                $boolQuery->addMust($orientationQuery);
            }

            //contributor
            if ($contributor != ""){
                $contributorQuery = new Query\Match();
                $contributorQuery->setFieldQuery('contributor.id', (int)$contributor);
                $contributorQuery->setFieldAnalyzer('contributor.id', "keyword_analyzer");
                $boolQuery->addMust($contributorQuery);
            }

            //is_exclusive
            if ($is_exclusive){
                $exclusiveQuery = new Query\Term();
                $exclusiveQuery->setTerm('contributor.is_exclusive', true);
                $boolQuery->addMust($exclusiveQuery);
            }

            $innerBoolQuery = new Query\BoolQuery();

            //if in search/type
            if ($type != null && $type != "null"){
                $typeQuery = new Query\Match();
                $typeQuery->setFieldQuery('type.id', $type);
                $typeQuery->setFieldAnalyzer('type.id', "keyword_analyzer");
                $boolQuery->addMust($typeQuery);
            }

            //category
            if ($category != ""){
                $innerCatBool = new Query\BoolQuery();
                $categoryQuery = new Query\Match();
                $category2Query = new Query\Match();
                $category3Query = new Query\Match();
                $categoryQuery->setFieldQuery('category.id', (int)$category);
                $categoryQuery->setFieldAnalyzer('category.id', "keyword_analyzer");

                $category2Query->setFieldQuery('category2.id', (int)$category);
                $category2Query->setFieldAnalyzer('category2.id', "keyword_analyzer");

                $category3Query->setFieldQuery('stocksCats.categoryStockCat.id', (int)$category);
                $category3Query->setFieldAnalyzer('stocksCats.categoryStockCat.id', "keyword_analyzer");

                $innerCatBool->addShould($categoryQuery);
                $innerCatBool->addShould($category2Query);
                $innerCatBool->addShould($category3Query);
                $boolQuery->addMust($innerCatBool);
            }

            //keywords
            $keywordsQuery = new Query\MatchPhrasePrefix();
            $keywordsQuery->setFieldQuery('keywords', $search);
            $keywordsQuery->setFieldAnalyzer('keywords', "keyword_analyzer");

            //title
            $titleQuery = new Query\Match();
            $titleQuery->setFieldQuery("title", $search);
            $titleQuery->setFieldAnalyzer('title', "keyword_analyzer");

            //id
            $idQuery = new Query\Match();
            $idQuery->setFieldQuery("id", (int)$search);
            $idQuery->setFieldAnalyzer('id', "keyword_analyzer");

            //hibernated
            $hibernatedQuery = new Query\Term();
            $hibernatedQuery->setTerm('Hibernated', false);

            if ($search != ""){
                $innerBoolQuery->addShould($keywordsQuery);
                $innerBoolQuery->addShould($titleQuery);
                $innerBoolQuery->addShould($idQuery);
            }

            $suspendedQuery = new Query\Term();
            $suspendedQuery->setTerm('contributorSuspended', true);

            $boolQuery->addMustNot($suspendedQuery);



            $boolQuery->addMustNot($publishedQuery);
            //$boolQuery->addMustNot($hibernatedQuery);
            $boolQuery->addMust($innerBoolQuery);


        }

        $query->setQuery($boolQuery);
        //$query->setSort(["id"=>"DESC"]);
        $query->setSize($limit);

        $results = $this->createPaginatorAdapter($query);

//        return $results;
        return $this->find($query);
    }

    public function search_by_keywords($keyword, $type, $limit=1000)
    {
        $query = new Query();
        $boolQuery = new Query\BoolQuery();

        if (isset($keyword)){
            //Published
            $publishedQuery = new Query\Term();
            $publishedQuery->setTerm('Published', false);

            //hibernated
            $hibernatedQuery = new Query\Term();
            $hibernatedQuery->setTerm('Hibernated', false);

            //$typeQuery = new Query\Match();
            $typeQuery = new Query\Match();
            $typeQuery->setFieldQuery('type.id', $type);
            $typeQuery->setFieldAnalyzer('type.id', "keyword_analyzer");

            //keywords
            $keywordsQuery = new Query\MatchPhrasePrefix();
            $keywordsQuery->setFieldQuery('keywords', $keyword);
            $keywordsQuery->setFieldAnalyzer('keywords', "keyword_analyzer");

            $suspendedQuery = new Query\Term();
            $suspendedQuery->setTerm('contributorSuspended', true);

            $boolQuery->addMustNot($suspendedQuery);

            $boolQuery->addMustNot($publishedQuery);
            //$boolQuery->addMustNot($hibernatedQuery);
            $boolQuery->addMust($keywordsQuery);
            $boolQuery->addMust($typeQuery);

        }
        $query->setQuery($boolQuery);
        //$query->setSort(["id"=>"DESC"]);
        $query->setSize($limit);

        $results = $this->createPaginatorAdapter($query);

//        return $results;

        return $this->find($query);
    }

    public function search_by_keywords_filter($keyword, $licence, $imageType, $orientation, $people, $category,$contributor,$is_exclusive,$type, $video_resolution, $limit=1000)
    {
        $query = new Query();
        $boolQuery = new Query\BoolQuery();

        if (isset($keyword)){
            if (isset($licence) && isset($imageType) && isset($orientation) && isset($people) && isset($category)){
                $licenceQuery = new Query\Match();
                $licenceQuery->setFieldQuery("LicenceType", $licence);
                $licenceQuery->setFieldAnalyzer('LicenceType', "keyword_analyzer");

                $orientationQuery = new Query\MatchPhrasePrefix();
                $orientationQuery->setFieldQuery("orientation", $orientation);
                $orientationQuery->setFieldAnalyzer('orientation', "keyword_analyzer");



                $peopleQuery = new Query\Match();
                $peopleQuery->setFieldQuery("peopleNo", $people);
                $peopleQuery->setFieldAnalyzer('peopleNo', "keyword_analyzer");



                //category
                if ($category != ""){
                    $categoryQuery = new Query\Match();
                    $category3Query = new Query\Match();
                    $categoryQuery->setFieldQuery('category.id', (int)$category);
                    $categoryQuery->setFieldAnalyzer('category.id', "keyword_analyzer");

                    $category3Query->setFieldQuery('stocksCats.categoryStockCat.id', (int)$category);
                    $category3Query->setFieldAnalyzer('stocksCats.categoryStockCat.id', "keyword_analyzer");

                    $boolQuery->addShould($categoryQuery);
                    $boolQuery->addMust($category3Query);
                }

                //Published
                $publishedQuery = new Query\Term();
                $publishedQuery->setTerm('Published', false);

                if ($licence != ""){
                    $boolQuery->addMust($licenceQuery);
                }
                if($imageType != ""){
                    $field = $type && $type == 5 ? "videoType" : "image_type";
                    $imageTypeQuery = new Query\Match();
                    $imageTypeQuery->setField($field, $imageType);
//                    $imageTypeQuery->setFieldAnalyzer($field, "keyword_analyzer");
                    $boolQuery->addMust($imageTypeQuery);

                    /*$imageTypeQuery = new Query\Match();
                    $imageTypeQuery->setFieldQuery("image_type", $imageType);
                    $boolQuery->addMust($imageTypeQuery);*/
                }
                if ($people != ""){
                    $boolQuery->addMust($peopleQuery);
                }
                if ($orientation != ""){
                    $boolQuery->addMust($orientationQuery);
                }
                //contributor
                if ($contributor != ""){
                    $contributorQuery = new Query\Match();
                    $contributorQuery->setFieldQuery('contributor.id', (int)$contributor);
                    $contributorQuery->setFieldAnalyzer('contributor.id', "keyword_analyzer");
                    $boolQuery->addMust($contributorQuery);
                }

                //is_exclusive
                if ($is_exclusive){
                    $exclusiveQuery = new Query\Term();
                    $exclusiveQuery->setTerm('contributor.is_exclusive', true);
                    $boolQuery->addMust($exclusiveQuery);
                }

                //video resolution
                if ($video_resolution != "" && $video_resolution != "undefined"){
                    $videoResolutionQuery = new Query\Match();
                    $videoResolutionQuery->setFieldQuery('videoResolution', $video_resolution);
                    $videoResolutionQuery->setFieldAnalyzer("videoResolution", "keyword_analyzer");
                    $boolQuery->addMust($videoResolutionQuery);
                }

                $innerBoolQuery = new Query\BoolQuery();


                $suspendedQuery = new Query\Term();
                $suspendedQuery->setTerm('contributorSuspended', true);

                $boolQuery->addMustNot($suspendedQuery);

                $boolQuery->addMustNot($publishedQuery);
                //$boolQuery->addMustNot($hibernatedQuery);
                $boolQuery->addMust($innerBoolQuery);


            }


            //Published
            $publishedQuery = new Query\Term();
            $publishedQuery->setTerm('Published', false);

            //hibernated
            $hibernatedQuery = new Query\Term();
            $hibernatedQuery->setTerm('Hibernated', false);

            //$typeQuery = new Query\Match();
            $typeQuery = new Query\Match();
            $typeQuery->setFieldQuery('type.id', $type);
            $typeQuery->setFieldAnalyzer('type.id', "keyword_analyzer");

            //keywords
            $keywordsQuery = new Query\MatchPhrasePrefix();
            $keywordsQuery->setFieldQuery('keywords', $keyword);
            $keywordsQuery->setFieldAnalyzer('keywords', "keyword_analyzer");

            $suspendedQuery = new Query\Term();
            $suspendedQuery->setTerm('contributorSuspended', true);

            $boolQuery->addMustNot($suspendedQuery);

            $boolQuery->addMustNot($publishedQuery);
            //$boolQuery->addMustNot($hibernatedQuery);
//            $boolQuery->addShould($keywordsQuery);
            $boolQuery->addMust($keywordsQuery);
            $boolQuery->addMust($typeQuery);

        }
        $query->setQuery($boolQuery);
        //$query->setSort(["id"=>"DESC"]);
        $query->setSize($limit);

        $results = $this->createPaginatorAdapter($query);

        return $this->find($query);
    }

    //get similar stock
    public function search_similar_stock(Stock $stock,$limit=10000)
    {
        $query = new Query();
        $boolQuery = new Query\BoolQuery();
        //Published
        $publishedQuery = new Query\Term();
        $publishedQuery->setTerm('Published', false);

        //$typeQuery = new Query\Match();
        $typeQuery = new Query\MatchPhrase();
        $typeQuery->setFieldQuery('type.id', $stock->getType()->getId());
        $typeQuery->setFieldAnalyzer('type.id', "keyword_analyzer");

        //hibernated
        $hibernatedQuery = new Query\Term();
        $hibernatedQuery->setTerm('Hibernated', false);

        //ID Query
        $idQuery = new Query\Match();
        $idQuery->setFieldQuery("id", (int)$stock->getId());
        $idQuery->setFieldAnalyzer('id', "keyword_analyzer");

        $keywords = $stock->getKeywords();
        $fieldQuery = new Query\Match();
        $fieldQuery->setFieldQuery("keywords", $keywords);
        $boolQuery->addMust($fieldQuery);

        $suspendedQuery = new Query\Term();
        $suspendedQuery->setTerm('contributorSuspended', true);

        $boolQuery->addMustNot($suspendedQuery);

        $boolQuery->addMustNot($publishedQuery);
        //$boolQuery->addMustNot($hibernatedQuery);
        $boolQuery->addMust($typeQuery);
//        $boolQuery->addMustNot($idQuery);

        $query->setQuery($boolQuery);
        //$query->setMinScore(1);
        $query->setSize($limit);

//        return $this->createPaginatorAdapter($query);

        return $this->find($query);
    }

    public function similar_stock_filter(Stock $stock, $search, $licence, $imageType, $orientation, $people, $category,$contributor,$is_exclusive, $search_category,$video_resolution,$limit=1000){
        $query = new Query();
        $boolQuery = new Query\BoolQuery();

        //Published
        $publishedQuery = new Query\Term();
        $publishedQuery->setTerm('Published', false);

        //hibernated
        $hibernatedQuery = new Query\Term();
        $hibernatedQuery->setTerm('Hibernated', false);

        //ID Query
        $idQuery = new Query\Match();
        $idQuery->setFieldQuery("id", (int)$stock->getId());
//        $idQuery->setFieldAnalyzer('id', "keyword_analyzer");

        //StockType query
        $typeQuery = new Query\Match();
        $typeQuery->setFieldQuery('type.id', $stock->getType()->getId());
        $typeQuery->setFieldAnalyzer('type.id', "keyword_analyzer");

        //similarity
        $keywords = $stock->getKeywords();
        $fieldQuery = new Query\Match();
        $fieldQuery->setFieldQuery("keywords", $keywords);
        $boolQuery->addMust($fieldQuery);


        /////////////////filter///////////////
        $licenceQuery = new Query\Match();
        $licenceQuery->setFieldQuery("LicenceType", $licence);
        $licenceQuery->setFieldAnalyzer('LicenceType', "keyword_analyzer");
//        dd($licence);
        $orientationQuery = new Query\MatchPhrasePrefix();
        $orientationQuery->setFieldQuery("orientation", $orientation);
        $orientationQuery->setFieldAnalyzer('orientation', "keyword_analyzer");
        $peopleQuery = new Query\Match();
        $peopleQuery->setFieldQuery("peopleNo", $people);
        $peopleQuery->setFieldAnalyzer('peopleNo', "keyword_analyzer");

        //category
        if ($category != ""){
            $categoryQuery = new Query\Match();
            $category3Query = new Query\Match();
            $categoryQuery->setFieldQuery('category.id', (int)$category);
            $categoryQuery->setFieldAnalyzer('category.id', "keyword_analyzer");
            $category3Query->setFieldQuery('stocksCats.categoryStockCat.id', (int)$category);
            $category3Query->setFieldAnalyzer('stocksCats.categoryStockCat.id', "keyword_analyzer");
            $boolQuery->addShould($categoryQuery);
            $boolQuery->addMust($category3Query);
        }

        //video resolution
        if ($video_resolution != "" && $video_resolution != "undefined"){
            $videoResolutionQuery = new Query\Match();
            $videoResolutionQuery->setFieldQuery('videoResolution', $video_resolution);
            $videoResolutionQuery->setFieldAnalyzer("videoResolution", "keyword_analyzer");
            $boolQuery->addMust($videoResolutionQuery);
        }

        if ($licence != ""){
            $boolQuery->addMust($licenceQuery);
        }
        if($imageType != ""){
            $field = $stock->getType()->getId() == 5 ? "videoType" : "image_type";
            $imageTypeQuery = new Query\Match();
            $imageTypeQuery->setField($field, $imageType);
//            $imageTypeQuery->setFieldAnalyzer($field, "keyword_analyzer");
            $boolQuery->addMust($imageTypeQuery);

            /*$imageTypeQuery = new Query\Match();
            $imageTypeQuery->setFieldQuery("image_type", $imageType);
            $boolQuery->addMust($imageTypeQuery);*/
        }
        if ($people != ""){
            $boolQuery->addMust($peopleQuery);
        }
        if ($orientation != ""){
            $boolQuery->addMust($orientationQuery);
        }
        //contributor
        if ($contributor != ""){
            $contributorQuery = new Query\Match();
            $contributorQuery->setFieldQuery('contributor.id', (int)$contributor);
            $contributorQuery->setFieldAnalyzer('contributor.id', "keyword_analyzer");
            $boolQuery->addMust($contributorQuery);
        }

        //is_exclusive
        if ($is_exclusive){
            $exclusiveQuery = new Query\Term();
            $exclusiveQuery->setTerm('contributor.is_exclusive', true);
            $boolQuery->addMust($exclusiveQuery);
        }
        //if in category
        if ($search_category != "null"){
            $search_category_query = new Query\Match();
            $category3Query = new Query\Match();
            $search_category_query ->setFieldQuery( 'category.id', (int)$search_category );
            $search_category_query->setFieldAnalyzer('category.id', "keyword_analyzer");
            $category3Query->setFieldQuery('stocksCats.categoryStockCat.id', (int)$category);
            $category3Query->setFieldAnalyzer('stocksCats.categoryStockCat.id', "keyword_analyzer");
            $boolQuery->addShould($search_category_query);
            $boolQuery->addMust($category3Query);
        }

        /////////////////////////////////////////

        //must

        $suspendedQuery = new Query\Term();
        $suspendedQuery->setTerm('contributorSuspended', true);

        $boolQuery->addMustNot($suspendedQuery);
        $boolQuery->addMustNot($publishedQuery);
        //$boolQuery->addMustNot($hibernatedQuery);
//        $boolQuery->addMustNot($idQuery);
        $boolQuery->addMust($typeQuery);


        $query->setQuery($boolQuery);
        //$query->setMinScore(1);
        $query->setSize($limit);

//        return $this->createPaginatorAdapter($query);

        return $this->find($query);

    }

    //same shoot stock
    public function search_same_shoot_stock(Stock $stock,$limit=1000)
    {
        $query = new Query();
        $boolQuery = new Query\BoolQuery();
        //Published
        $publishedQuery = new Query\Term();
        $publishedQuery->setTerm('Published', false);

        //$typeQuery = new Query\Match();
        $typeQuery = new Query\MatchPhrase();
        $typeQuery->setFieldQuery('type.id', $stock->getType()->getId());
        $typeQuery->setFieldAnalyzer('type.id', "keyword_analyzer");

        //hibernated
        $hibernatedQuery = new Query\Term();
        $hibernatedQuery->setTerm('Hibernated', false);

        //ID Query
        $idQuery = new Query\Match();
        $idQuery->setFieldQuery("id", (int)$stock->getId());
        $idQuery->setFieldAnalyzer('id', "keyword_analyzer");

        //shoot-code
        $code = $stock->getSameShootCode();
        $fieldQuery = new Query\Match();
        $fieldQuery->setFieldQuery("SameShootCode", $code);
        $boolQuery->addMust($fieldQuery);

        $suspendedQuery = new Query\Term();
        $suspendedQuery->setTerm('contributorSuspended', true);

        $boolQuery->addMustNot($suspendedQuery);

        $boolQuery->addMustNot($publishedQuery);
        //$boolQuery->addMustNot($hibernatedQuery);
        $boolQuery->addMust($typeQuery);
//        $boolQuery->addMustNot($idQuery);

        $query->setQuery($boolQuery);
        //$query->setMinScore(1);
        $query->setSize($limit);

//        return $this->createPaginatorAdapter($query);
        return $this->find($query);
    }

    //same shoot filter
    public function same_shoot_stock_filter(Stock $stock, $search, $licence, $imageType, $orientation, $people, $category,$contributor,$is_exclusive, $search_category,$video_resolution,$limit=1000){
        $query = new Query();
        $boolQuery = new Query\BoolQuery();

        //Published
        $publishedQuery = new Query\Term();
        $publishedQuery->setTerm('Published', false);

        //hibernated
        $hibernatedQuery = new Query\Term();
        $hibernatedQuery->setTerm('Hibernated', false);

        //ID Query
        $idQuery = new Query\Match();
        $idQuery->setFieldQuery("id", (int)$stock->getId());
        $idQuery->setFieldAnalyzer('id', "keyword_analyzer");

        //StockType query
        $typeQuery = new Query\Match();
        $typeQuery->setFieldQuery('type.id', $stock->getType()->getId());
        $typeQuery->setFieldAnalyzer('type.id', "keyword_analyzer");

        //similarity
        //shoot-code
        $code = $stock->getSameShootCode();
        $fieldQuery = new Query\Match();
        $fieldQuery->setFieldQuery("SameShootCode", $code);
        $boolQuery->addMust($fieldQuery);


        /////////////////filter///////////////
        $licenceQuery = new Query\Match();
        $licenceQuery->setFieldQuery("LicenceType", $licence);
        $licenceQuery->setFieldAnalyzer('LicenceType', "keyword_analyzer");
//        dd($licence);
        $orientationQuery = new Query\MatchPhrasePrefix();
        $orientationQuery->setFieldQuery("orientation", $orientation);
        $orientationQuery->setFieldAnalyzer('orientation', "keyword_analyzer");
        $peopleQuery = new Query\Match();
        $peopleQuery->setFieldQuery("peopleNo", $people);
        $peopleQuery->setFieldAnalyzer('peopleNo', "keyword_analyzer");

        //category
        if ($category != ""){
            $categoryQuery = new Query\Match();
            $category3Query = new Query\Match();
            $categoryQuery->setFieldQuery('category.id', (int)$category);
            $categoryQuery->setFieldAnalyzer('category.id', "keyword_analyzer");
            $category3Query->setFieldQuery('stocksCats.categoryStockCat.id', (int)$category);
            $category3Query->setFieldAnalyzer('stocksCats.categoryStockCat.id', "keyword_analyzer");
            $boolQuery->addShould($categoryQuery);
            $boolQuery->addMust($category3Query);
        }
        //video resolution
        if ($video_resolution != "" && $video_resolution != "undefined"){
            $videoResolutionQuery = new Query\Match();
            $videoResolutionQuery->setFieldQuery('videoResolution', $video_resolution);
            $videoResolutionQuery->setFieldAnalyzer("videoResolution", "keyword_analyzer");
            $boolQuery->addMust($videoResolutionQuery);
        }
        if ($licence != ""){
            $boolQuery->addMust($licenceQuery);
        }
        if($imageType != ""){
            $field = $stock->getType()->getId() == 5 ? "videoType" : "image_type";
            $imageTypeQuery = new Query\Match();
            $imageTypeQuery->setField($field, $imageType);
//            $imageTypeQuery->setFieldAnalyzer($field, "keyword_analyzer");
            $boolQuery->addMust($imageTypeQuery);
        }
        if ($people != ""){
            $boolQuery->addMust($peopleQuery);
        }
        if ($orientation != ""){
            $boolQuery->addMust($orientationQuery);
        }
        //contributor
        if ($contributor != ""){
            $contributorQuery = new Query\Match();
            $contributorQuery->setFieldQuery('contributor.id', (int)$contributor);
            $contributorQuery->setFieldAnalyzer('contributor.id', "keyword_analyzer");
            $boolQuery->addMust($contributorQuery);
        }

        //is_exclusive
        if ($is_exclusive){
            $exclusiveQuery = new Query\Term();
            $exclusiveQuery->setTerm('contributor.is_exclusive', true);
            $boolQuery->addMust($exclusiveQuery);
        }
        //if in category
        if ($search_category != "null"){
            $search_category_query = new Query\Match();
            $category3Query = new Query\Match();
            $search_category_query ->setFieldQuery( 'category.id', (int)$search_category );
            $search_category_query->setFieldAnalyzer('category.id', "keyword_analyzer");
            $category3Query->setFieldQuery('stocksCats.categoryStockCat.id', (int)$category);
            $category3Query->setFieldAnalyzer('stocksCats.categoryStockCat.id', "keyword_analyzer");
            $boolQuery->addShould($search_category_query);
            $boolQuery->addMust($category3Query);
        }

        /////////////////////////////////////////

        //must

        $suspendedQuery = new Query\Term();
        $suspendedQuery->setTerm('contributorSuspended', true);

        $boolQuery->addMustNot($suspendedQuery);
        $boolQuery->addMustNot($publishedQuery);
        //$boolQuery->addMustNot($hibernatedQuery);
//        $boolQuery->addMustNot($idQuery);
        $boolQuery->addMust($typeQuery);


        $query->setQuery($boolQuery);
        //$query->setMinScore(1);
        $query->setSize($limit);

//        return $this->createPaginatorAdapter($query);

        return $this->find($query);

    }

    public function search_contributor_public_profile_stocks(User $user, StockType $stockType, $limit=1000){
        $query=new Query();
        $boolQuery = new Query\BoolQuery();

        //Published
        $publishedQuery = new Query\Term();
        $publishedQuery->setTerm('Published', false);

        //hibernated
        $hibernatedQuery = new Query\Term();
        $hibernatedQuery->setTerm('Hibernated', false);

        //StockType query
        $typeQuery = new Query\Match();
        $typeQuery->setFieldQuery('type.id', $stockType->getId());
        $typeQuery->setFieldAnalyzer('type.id', "keyword_analyzer");

        //contributor
        $contributorQuery = new Query\Match();
        $contributorQuery->setFieldQuery('contributor.id', $user->getId());
        $contributorQuery->setFieldAnalyzer('contributor.id', "keyword_analyzer");

        //must

        $suspendedQuery = new Query\Term();
        $suspendedQuery->setTerm('contributorSuspended', true);

        $boolQuery->addMustNot($suspendedQuery);

        $boolQuery->addMustNot($publishedQuery);
        // $boolQuery->addMustNot($hibernatedQuery);
        $boolQuery->addMust($typeQuery);
        $boolQuery->addMust($contributorQuery);

        $query->setQuery($boolQuery);
        $query->setSize($limit);

//        return $this->createPaginatorAdapter($query);
        return $this->find($query);
    }

    public function search_contributor_public_profile_stocks_filter(User $user, StockType $stockType,$licence, $imageType, $orientation, $people, $category,$is_exclusive,$video_resolution,  $limit=1000){
        $query=new Query();
        $boolQuery = new Query\BoolQuery();

        //Published
        $publishedQuery = new Query\Term();
        $publishedQuery->setTerm('Published', false);

        //hibernated
        $hibernatedQuery = new Query\Term();
        $hibernatedQuery->setTerm('Hibernated', false);

        //StockType query
        $typeQuery = new Query\Match();
        $typeQuery->setFieldQuery('type.id', $stockType->getId());
        $typeQuery->setFieldAnalyzer('type.id', "keyword_analyzer");

        //contributor
        $contributorQuery = new Query\Match();
        $contributorQuery->setFieldQuery('contributor.id', $user->getId());
        $contributorQuery->setFieldAnalyzer('contributor.id', "keyword_analyzer");

        //must
        $boolQuery->addMustNot($publishedQuery);
        //$boolQuery->addMustNot($hibernatedQuery);
        $boolQuery->addMust($typeQuery);
        $boolQuery->addMust($contributorQuery);

        $suspendedQuery = new Query\Term();
        $suspendedQuery->setTerm('contributorSuspended', true);

        $boolQuery->addMustNot($suspendedQuery);


        /////////////////filter///////////////
        $licenceQuery = new Query\Match();
        $licenceQuery->setFieldQuery("LicenceType", $licence);
        $licenceQuery->setFieldAnalyzer('LicenceType', "keyword_analyzer");
        $orientationQuery = new Query\MatchPhrasePrefix();
        $orientationQuery->setFieldQuery("orientation", $orientation);
        $orientationQuery->setFieldAnalyzer('orientation', "keyword_analyzer");
        $peopleQuery = new Query\Match();
        $peopleQuery->setFieldQuery("peopleNo", $people);
        $peopleQuery->setFieldAnalyzer('peopleNo', "keyword_analyzer");

        //category
        if ($category != "" && $category != "null"){
            $categoryQuery = new Query\Match();
            $category3Query = new Query\Match();
            $categoryQuery->setFieldQuery('category.id', (int)$category);
            $categoryQuery->setFieldAnalyzer('category.id', "keyword_analyzer");
            $category3Query->setFieldQuery('stocksCats.categoryStockCat.id', (int)$category);
            $category3Query->setFieldAnalyzer('stocksCats.categoryStockCat.id', "keyword_analyzer");
            $boolQuery->addShould($categoryQuery);
            $boolQuery->addMust($category3Query);
        }
        //video resolution
        if ($video_resolution != "" && $video_resolution != "undefined"){
            $videoResolutionQuery = new Query\Match();
            $videoResolutionQuery->setFieldQuery('videoResolution', $video_resolution);
            $videoResolutionQuery->setFieldAnalyzer("videoResolution", "keyword_analyzer");
            $boolQuery->addMust($videoResolutionQuery);
        }
        if ($licence != ""){
            $boolQuery->addMust($licenceQuery);
        }
        if($imageType != ""){
            $field = $stockType->getId() == 5 ? "videoType" : "image_type";
            $imageTypeQuery = new Query\Match();
            $imageTypeQuery->setField($field, $imageType);
//            $imageTypeQuery->setFieldAnalyzer($field, "keyword_analyzer");
            $boolQuery->addMust($imageTypeQuery);
        }
        if ($people != ""){
            $boolQuery->addMust($peopleQuery);
        }
        if ($orientation != ""){
            $boolQuery->addMust($orientationQuery);
        }

        //is_exclusive
        if ($is_exclusive){
            $exclusiveQuery = new Query\Term();
            $exclusiveQuery->setTerm('contributor.is_exclusive', true);
            $boolQuery->addMust($exclusiveQuery);
        }

        /////////////////////////////////////////


        $query->setQuery($boolQuery);
        $query->setSize($limit);

        return $this->find($query);
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit