public function allWords() { $group = Input::get('group_id'); if ($group == null) { return Word::all(); } else { if (is_array($group)) { $groups = JsonController::array_to_sql_list($group); return Word::whereRaw("group_id in {$groups}")->get(); } return Word::where('group_id', '=', $group)->get(); } }
public function saveSegmentMap($dataaccount) { /* $deleteIds = Word::where('dataaccount', $dataaccount)->get( array('id') ); $notDeleteIds = []; $tmp = []; */ //return Response::json( count(Input::get('idsToBeDeleted')) ); if (count(Input::get('idsToBeDeleted')) > 0) { Keyword::destroy(Input::get('idsToBeDeleted')); // refresh wordcloud only if some keyword is deleted Word::where('dataaccount', $dataaccount)->delete(); Word::createWordCloud($dataaccount); } foreach (Input::get('segmentMap') as $k => $word) { Word::where('dataaccount', $dataaccount)->where('word', $word['word'])->update(array('segment' => $word['segment'], 'brand' => $word['brand'], 'compete' => $word['compete'], 'negativeword' => $word['negativeword'], 'stopword' => $word['stopword'])); // 'numword'=>$word['numword'], // 'dataaccount'=>$word['dataaccount']) ); //$notDeleteIds[] = $word['id']; //Word::find( $word['id'] )->update($word); } /* foreach($deleteIds as $k=>$v) { if(in_array($v['id'], $notDeleteIds)) $tmp[] = $v['id']; } return $tmp; */ return Response::json(array('success' => true)); /* //return Response::json( count(Input::get('toBeDeleted')) ); if( count(Input::get('toBeDeleted')) > 0 ) Keyword::destroy(Input::get('toBeDeleted')); $tempId = []; $tempSeg = []; //return Response::json( count(Input::get('segmentMap')) ); if( count(Input::has('segmentMap')) > 0) { foreach(Input::get('segmentMap') as $key => $val) { $tempId[] = $val['id']; $tempSeg[] = $val['segment']; Keyword::find($val['id'])->update( array('usersegment' => $val['segment']) ); } } //Keyword::find($tempId)->update( array('usersegment' => $tempSeg) )->save(); return Response::json( Keyword::find($tempId) ); //return Response::json( array('success' => true) ); //return Response::json( Input::get('segmentMap') ); */ }
public function refreshPhrases($dataaccountid) { //$result = DB::statement(" call keyword_count( 1 ) " ); /* $result = DB::statement(" call keyword_count( '". $dataaccountid ."', 2 ) " ); return " call keyword_count( '". $dataaccountid ."', 2 ) "; return ( array('success' => true) ); */ $startTime = microtime(true); $keywords = Keyword::where('dataAccount', $dataaccountid)->get(); $wordCloud = Word::where('dataAccount', $dataaccountid)->get(); $landingPageIds = DataAccount::find($dataaccountid)->landingPageUrls()->get(); // Laravel's magic $landingPageWordCloud = []; foreach ($landingPageIds as $lp) { $landingPageWordCloud[$lp->landingpageurl] = DB::table('landingpagewordcloud')->where('landing_page_urls_id', $lp->id)->orderBy('freq', 'DESC')->get(array('word', 'freq')); } //return $landingPageWordCloud; $insertData = []; DB::table('keywords_segment')->truncate(); foreach ($keywords as $keyword) { $seg = ''; $brand = 0; $compete = 0; foreach ($wordCloud as $word) { //if(strpos($keyword['keyword'], $word['word']) !== false) // found word (cloud) found in keyword if (preg_match("/\\b" . $word['word'] . "\\b/", $keyword['keyword']) === 1) { //$seg .= $word['segment'] . ','; if ($word['segment'] != '' && $word['segment'] != null && $word['segment'] != ' ') { $seg .= $word['segment'] . ','; } $brand = $brand || $word['brand']; $compete = $compete || $word['compete']; } } if ($seg != '') { $seg = substr($seg, 0, -1); } $seg = array_unique(explode(',', $seg)); // remove duplicates and sort sort($seg); $seg = implode(",", $seg); //return calcLPScore($keyword['keyword'], $landingPageWordCloud); $insertData[] = array('adGroup' => $keyword['adGroup'], 'keyword' => $keyword['keyword'], 'lpscore' => $this->calcLPScore($keyword['keyword'], $landingPageWordCloud), 'currency' => $keyword['currency'], 'avMonthlySearches' => $keyword['avMonthlySearches'], 'competition' => $keyword['competition'], 'suggestedBid' => $keyword['suggestedBid'], 'impressionShare' => $keyword['impressionShare'], 'inAccount' => $keyword['inAccount'], 'inPlan' => $keyword['inPlan'], 'extractedFrom' => $keyword['extractedFrom'], 'segment' => $seg, 'brand' => $brand, 'compete' => $compete, 'dataAccount' => $keyword['dataAccount']); //return $ind . " | " . $keyword['keyword'] . " | " . $word['word'] . " | " . $seg; //return $insertData; } DB::table('keywords_segment')->insert($insertData); //return Response::json( array('success' => true) ); return "Elapsed time is: " . (microtime(true) - $startTime) . " seconds"; return Response::json($insertData); }
public function actionQuerySearch($keySearch) { if ($this->validate->validateSpecialChar($keySearch)) { $list['keySearch'] = $keySearch; $list['result'] = Word::where('word', 'like', '%' . $keySearch . '%')->paginate(20); for ($i = 0; $i < count($list['result']); $i++) { $list['result'][$i]->course_name = $this->convertNameCourse($list['result'][$i]->id_course); } } else { $list['error'] = 'Từ khóa tìm kiếm chứa ký tự đặc biệt hoặc trống'; } return View::make('data.search', $list); }
}); Route::any('index', function () { $keyword = Input::get('auto'); $models = Word::where('word', '=', $keyword)->orderby('word')->take(10)->skip(0)->get(); $count = count($models); return View::make('Dictionary.index')->with("contents", $models)->with("counts", $count); }); Route::POST('words/means/', function () { $keyword = Str::lower(Input::get('auto')); $models = Word::where('word', '=', $keyword)->orderby('word')->take(10)->skip(0)->get(); $count = count($models); return View::make('Dictionary.definition.means')->with("contents", $models)->with("counts", $count); }); // 3: create this route to process the user input (Input::get('term')) in the database query. Route::any('getdata', function () { $term = Str::lower(Input::get('term')); // 4: check if any matches found in the database table $data = DB::table("words")->distinct()->select('word')->where('word', 'LIKE', $term . '%')->groupBy('word')->take(10)->get(); foreach ($data as $v) { $return_array[] = array('value' => $v->word); } // if matches found it first create the array of the result and then convert it to json format so that // it can be processed in the autocomplete script return Response::json($return_array); }); Route::any('/thesaurus', function () { $keyword = Str::lower(Input::get('auto')); $models = Word::where('word', '=', $keyword)->orderby('word')->take(10)->skip(0)->get(); $count = count($models); return View::make('Dictionary.synonymns.synonyms')->with("contents", $models)->with("counts", $count); });