<commit_before><?php

namespace App\Http\Controllers;


use App\Comments;
use App\Project;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;

use App\Http\Requests;


class SearchController extends Controller
{

    public function p_search()
    {
//        $projects = Project::all();
//        $test = new Builder(DB::table('projects'));
//        $test2 = $test->paginate(5);
//        $projects = DB::table('projects')->paginate(5);

        return view('p_search/p_search');
//        return view('p_search', compact('projects'));
//        return view('p_search', ['todos'=> $todos]);

    }

    public function detail($id)
    {
        $detailProject = Project::where('id', '=', $id)->get();
        $comment = Comments::where('project_id', '=', $id)->get();
        return view('p_detail', compact('detailProject', 'comment'));
    }

    public function pagination($start, $end)
    {
        return view('pagination', ['start' => $start, 'end' => $end]);
    }


    public function get_p_list($SearchOption, $page, $sort, $keyword = "%")
    {
        $SearchOption = intval($SearchOption);
        $page = intval($page);
//        $keyword1 ="";
//        $keyword2 = "";
        $keyword3 = "";

        if($keyword != "%"){
//            $keyword1 = $keyword."%";
//            $keyword2 = "%".$keyword;
            $keyword3 = "%".$keyword."%";
        }

        if ($SearchOption == 0) {

//            $projects = Project::all();
            $projects = Project::where("step", "!=", "검수")
                ->where('title','LIKE', $keyword)
//                ->union(Project::where("step", "!=", "검수")->where('title','LIKE', $keyword1))
//                ->union(Project::where("step", "!=", "검수")->where('title','LIKE', $keyword2))
                ->union(Project::where("step", "!=", "검수")->where('title','LIKE', $keyword3))
                ->get();

            $count = $projects->count();

            //sort
            if ($sort == "3") {
                $projects = $projects->sortBy('updated_at');
            } else {
                $projects = $projects->sortBy('updated_at');
            }

            $projects = $projects->forPage($page, 10);
            $projects['count'] = $count;

            return view('p_search/p_searchSort', compact('projects'));
        }


        $optionArr = [];
        $projects = new Collection();

        if (($SearchOption & 1) == true) {
            $optionArr[] = "광고 의뢰";
            $query = Project::where('area','=','광고 의뢰')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 2) == true) {
            $optionArr[] = "운영 대행";
            $query = Project::where('area','=','운영 대행')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 4) == true) {
            $optionArr[] = "Viral";
            $query = Project::where('area','=','Viral')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 8) == true) {
            $optionArr[] = "1회성 프로젝트";
            $query = Project::where('area','=','1회성 프로젝트')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 16) == true) {
            $optionArr[] = "의료";
            $query = Project::where('category','=','의료')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 32) == true) {
            $optionArr[] = "법률";
            $query = Project::where('category','=','법률')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 64) == true) {
            $optionArr[] = "스타트업";
            $query = Project::where('category','=','스타트업')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 128) == true) {
            $optionArr[] = "프랜차이즈";
            $query = Project::where('category','=','프랜차이즈')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 256) == true) {
            $optionArr[] = "교육/대학교";
            $query = Project::where('category','=','교육/대학교')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 512) == true) {
            $optionArr[] = "쇼핑몰";
            $query = Project::where('category','=','쇼핑몰')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }



//        for ($i = 0; $i < count($optionArr); $i++) {
//            if ($i == 0) {
//                $query = $query->where('category', '=', $optionArr[$i])->where('step', '!=', '검수');
//            } else {
//                $query = $query->union(Project::where('category', '=', $optionArr[$i])
//                    ->where('step', '!=', '검수'));
//            }
//        }

//        $projects = $query->get();<commit_msg>Project Search Devided into area and category optimized<commit_after><?php

namespace App\Http\Controllers;


use App\Comments;
use App\Project;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;

use App\Http\Requests;


class SearchController extends Controller
{

    public function p_search()
    {
//        $projects = Project::all();
//        $test = new Builder(DB::table('projects'));
//        $test2 = $test->paginate(5);
//        $projects = DB::table('projects')->paginate(5);

        return view('p_search/p_search');
//        return view('p_search', compact('projects'));
//        return view('p_search', ['todos'=> $todos]);

    }

    public function detail($id)
    {
        $detailProject = Project::where('id', '=', $id)->get();
        $comment = Comments::where('project_id', '=', $id)->get();
        return view('p_detail', compact('detailProject', 'comment'));
    }

    public function pagination($start, $end)
    {
        return view('pagination', ['start' => $start, 'end' => $end]);
    }


    public function get_p_list($SearchOption, $page, $sort, $keyword = "%")
    {
        $SearchOption = intval($SearchOption);
        $page = intval($page);
//        $keyword1 ="";
//        $keyword2 = "";
        $keyword3 = "";

        if($keyword != "%"){
//            $keyword1 = $keyword."%";
//            $keyword2 = "%".$keyword;
            $keyword3 = "%".$keyword."%";
        }

        if ($SearchOption == 0) {

//            $projects = Project::all();
            $projects = Project::where("step", "!=", "검수")
                ->where('title','LIKE', $keyword)
//                ->union(Project::where("step", "!=", "검수")->where('title','LIKE', $keyword1))
//                ->union(Project::where("step", "!=", "검수")->where('title','LIKE', $keyword2))
                ->union(Project::where("step", "!=", "검수")->where('title','LIKE', $keyword3))
                ->get();

            $count = $projects->count();

            //sort
            if ($sort == "3") {
                $projects = $projects->sortBy('updated_at');
            } else {
                $projects = $projects->sortBy('updated_at');
            }

            $projects = $projects->forPage($page, 10);
            $projects['count'] = $count;

            return view('p_search/p_searchSort', compact('projects'));
        }



        $projects = new Collection();

        if (($SearchOption & 1) == true) {

            $query = Project::where('area','=','광고 의뢰')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 2) == true) {

            $query = Project::where('area','=','운영 대행')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 4) == true) {

            $query = Project::where('area','=','Viral')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 8) == true) {

            $query = Project::where('area','=','1회성 프로젝트')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 16) == true) {

            $query = Project::where('category','=','의료')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 32) == true) {

            $query = Project::where('category','=','법률')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 64) == true) {

            $query = Project::where('category','=','스타트업')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 128) == true) {

            $query = Project::where('category','=','프랜차이즈')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 256) == true) {

            $query = Project::where('category','=','교육/대학교')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }
        if (($SearchOption & 512) == true) {
            
            $query = Project::where('category','=','쇼핑몰')->get();

            foreach ($query as $q){
                $projects = $projects->push($q);
            }
        }



//        for ($i = 0; $i < count($optionArr); $i++) {
//            if ($i == 0) {
//                $query = $query->where('category', '=', $optionArr[$i])->where('step', '!=', '검수');
//            } else {
//                $query = $query->union(Project::where('category', '=', $optionArr[$i])
//                    ->where('step', '!=', '검수'));
//            }
//        }

//        $projects = $query->get();
{'fraction_non_alphanumeric': 0.21082894106372785, 'fraction_numerical': 0.0073790129372304746, 'mean_word_length': 1.7205422314911365, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '660736', 'n_tokens_mistral': 3229, 'n_tokens_neox': 3210, 'n_words': 564}