public function randomMovie(Request $request, Pio $pio)
 {
     if (session('user_id')) {
         $movies_viewed = session('movies_viewed');
         $es_client = new \Elasticsearch\Client();
         $search_params['index'] = 'movierecommendation_app';
         $search_params['type'] = 'movie';
         $search_params['id'] = mt_rand(1, 1000);
         $movie = $es_client->get($search_params);
         if (!empty($request->input('movie_id'))) {
             $user_id = session('user_id');
             $movie_id = $request->input('movie_id');
             $action = $request->input('action');
             $pio_eventclient = $pio->eventClient();
             $pio_eventclient->recordUserActionOnItem($action, $user_id, $movie_id);
             $movies_viewed += 1;
             if ($movies_viewed == 20) {
                 $movie['has_recommended'] = true;
             }
             $movie['movies_viewed'] = $movies_viewed;
             session(array('movies_viewed' => $movies_viewed));
         }
         return $movie;
     }
 }
Esempio n. 2
0
function requete2($id)
{
    $paramsH['hosts'] = array('5.135.106.169:9200');
    $client = new Elasticsearch\Client($paramsH);
    $params['type'] = 'oeuvre';
    $params['index'] = 'arts';
    $params['id'] = $id;
    return $client->get($params);
}
Esempio n. 3
0
 public function get()
 {
     $client = new Elasticsearch\Client();
     $getParams = array();
     $getParams['index'] = 'utano';
     $getParams['type'] = 'sti';
     $getParams['id'] = '1';
     $retDoc = $client->get($getParams);
     $data = array('results' => $retDoc);
     $this->load->view('welcome_message', $data);
 }
 public function api($key)
 {
     $client = new Elasticsearch\Client($this->elastic);
     $getParams = array();
     $getParams['index'] = 'images';
     $getParams['type'] = 'string';
     $getParams['id'] = $key;
     $file = $client->get($getParams);
     $filename = $file['_source']['file_name'] . '.png';
     $im = imagecreatefrompng("./uploads/" . $filename);
     header('Content-Type: image/png');
     imagepng($im);
 }
Esempio n. 5
0
//    'https://192.168.1.3:9200',         // SSL to IP + Port
//    'http://*****:*****@localhost:9200',  // HTTP Basic Auth
//    'https://*****:*****@localhost:9200',  // SSL + HTTP Basic Auth
//);
$params['hosts'] = array('localhost:9200');
$client = new Elasticsearch\Client($params);
$t = $_GET['t'];
try {
    switch (strtoupper($t)) {
        case 'GET':
            $params = array();
            $params['index'] = 'acotel';
            $params['type'] = 'eiplus_dev_status';
            $params['id'] = '5521983059028';
            if ($client->exists($params)) {
                $retDoc = $client->get($params);
                print_r($retDoc['_source']);
            } else {
                echo "INEXISTENT VALUE";
            }
            break;
        case 'SEARCH':
            $searchParams['index'] = 'acotel';
            $searchParams['type'] = 'eiplus_dev_status';
            $searchParams['body']['query']['match']['msisdn'] = '5521983059028';
            $queryResponse = $client->search($searchParams);
            print_r($queryResponse);
            //echo $queryResponse['hits']['hits'][0]['_id']; // Outputs 'abc'
            break;
        case 'SAVE':
            $params = array();
Esempio n. 6
0
    $mainHitValue['direction']['code'] = $dirStructured[2];
    switch ($dirStructured[1]) {
        case 'I':
            $mainHitValue['direction']['direction'] = 'Inbound';
            break;
        case 'O':
            $mainHitValue['direction']['direction'] = 'Outbound';
            break;
        default:
            $mainHitValue['direction']['direction'] = "Direction \"" . $dirStructured[1] . "\"";
            break;
    }
    $fullResult['vehicle'] = $mainHitValue;
    if ($includeRoute) {
        $route = $type == 'phantom' ? $mainHitValue['_source']['direction']['route'] : $mainHitValue['_source']['routeTag'];
        try {
            $routeResults = $client->get(array('index' => 'transitauthority', 'type' => 'route', 'id' => 'route-' . $route));
            $fullResult['route'] = $routeResults['_source']['path'];
        } catch (Exception $e) {
        }
    }
    if ($includeNearestStop) {
        try {
            $nearestStopResults = $client->get(array('index' => 'transitauthority', 'type' => 'stop', 'routing' => 'route-' . $mainHitValue['_source']['routeTag'], 'id' => $mainHitValue['_source']['nearestStop']['id']));
            $fullResult['stop'] = $nearestStopResults;
        } catch (Exception $e) {
        }
    }
    $resultList[] = $fullResult;
}
echo json_encode($resultList);
Esempio n. 7
0
 public function fetchPost($id)
 {
     //Fetch Post
     //@return Encrypted string
     $client = new Elasticsearch\Client();
     $params['index'] = 'blog';
     $params['type'] = 'posts';
     if (isset($id)) {
         $params['id'] = $id;
     }
     $allData = array();
     $results = $client->get($params);
     $allData['id'] = $id;
     if (isset($results['_source']['author'])) {
         $allData['author'] = $results['_source']['author'];
     }
     if (isset($results['_source']['title'])) {
         $allData['title'] = $results['_source']['title'];
     }
     if (isset($results['_source']['content'])) {
         $allData['content'] = $results['_source']['content'];
     }
     $allData = json_encode($allData);
     return $allData;
 }
Esempio n. 8
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use RecipeSearch\Constants;
use Elasticsearch\Common\Exceptions\Missing404Exception;
$message = $_REQUEST['message'];
// Check if recipe ID was provided
if (empty($_REQUEST['id'])) {
    $message = 'No recipe requested! Please provide a recipe ID.';
} else {
    // Connect to Elasticsearch (1-node cluster)
    $esPort = getenv('APP_ES_PORT') ?: 9200;
    $client = new Elasticsearch\Client(['hosts' => ['localhost:' . $esPort]]);
    // Try to get recipe from Elasticsearch
    try {
        $recipe = $client->get(['id' => $_REQUEST['id'], 'index' => Constants::ES_INDEX, 'type' => Constants::ES_TYPE]);
        $recipe = $recipe['_source'];
    } catch (Missing404Exception $e) {
        $message = 'Requested recipe not found :(';
    }
}
?>
<html>
<head>
  <title>Recipe Search</title>
  <link rel="stylesheet" href="/css/bootstrap.min.css" />
</head>
<body>
<div class="container bg-danger" id="message">
<?php 
if (!empty($message)) {