Example #1
0
 public function indexAction()
 {
     $keyword = trim($this->request->getQuery("q"));
     if (!$keyword) {
         $tag = new Tag();
         $tags = $tag->getPopularTags(30);
         $this->view->setVar('tags', $tags);
         return;
     }
     $client = new \Elasticsearch\Client(array('hosts' => $this->getDI()->getConfig()->EvaSearch->elasticsearch->servers->toArray()));
     $searchParams['index'] = 'wallstreetcn';
     $type = $this->request->getQuery('type');
     $type = in_array($type, array('article', 'wiki', 'livenews')) ? $type : 'article';
     $searchParams['type'] = $type;
     $searchParams['size'] = 15;
     $page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
     $page = $page > 0 ? $page : 1;
     $searchParams['from'] = ($page - 1) * $searchParams['size'];
     $searchParams['body']['query']['multi_match'] = array('query' => $keyword, "fields" => array("title", "content"), "tie_breaker" => 0.3);
     $searchParams['body']['highlight'] = array("fields" => array("title" => array("type" => "plain"), "content" => array("fragment_size" => 50, "number_of_fragments" => 3, "type" => "plain")));
     $searchParams['body']['filter'] = array("bool" => array("should" => array("term" => array("status" => "published"))));
     $searchParams['body']['sort'] = array('createdAt' => array('order' => 'desc'), '_score' => array('order' => 'desc'));
     $ret = $client->search($searchParams);
     $this->view->setVar('hits', $ret['hits']);
     $pager = new PurePaginator($searchParams['size'], $ret['hits']['total'], $ret['hits']['hits']);
     $this->view->setVar('pager', $pager);
     $this->view->setVar('keyword', $keyword);
 }
Example #2
0
 public function buscar($q, $tipos, $limit = NULL, $start = NULL)
 {
     $client_params = array('hosts' => $this->config->item('elasticsearch_hosts'));
     $types = '';
     $campos = array();
     $ultimo = count($tipos);
     $ultimo_tipo = $tipos[$ultimo - 1];
     $client = new Elasticsearch\Client($client_params);
     foreach ($tipos as $tipo) {
         if ($tipo == $ultimo_tipo) {
             $types .= $tipo;
             $campos = array_merge($campos, $this->get_campos($tipo));
         } else {
             $types .= $tipo . ',';
             $campos = array_merge($campos, $this->get_campos($tipo));
         }
     }
     $params['index'] = 'varadouro';
     $params['type'] = $types;
     $filter = array();
     $query = array();
     if (strlen($q) > 0) {
         $query['multi_match'] = array('query' => $q, 'fields' => $campos);
     } else {
         $query['match_all'] = array();
     }
     $params['body']['from'] = $start;
     $params['body']['size'] = $limit;
     $params['body']['highlight'] = array('pre_tags' => array('<span class="highlight">'), 'post_tags' => array('</span>'), 'fields' => array('nome_responsavel' => array('type' => 'plain'), 'atividades_culturais' => array('type' => 'plain')));
     $params['body']['query']['filtered'] = array('filter' => $filter, 'query' => $query);
     $results = $client->search($params);
     return $results;
 }
Example #3
0
 public function findArticles($params)
 {
     $query = $params['query'];
     # берем основу слов, если нету собственных имен (заглавных)
     if (!preg_match('/[A-Z]/', $query) && !preg_match('/[А-Я]/u', $query)) {
         $query = $this->lingua->stem_string($query);
     }
     # каждое слово дополняется с конца звездочкой (wildcard)
     $words = explode(' ', $query);
     $query = implode('* ', $words) . '*';
     $client = new \Elasticsearch\Client();
     $searchParams['index'] = 'evrika';
     $searchParams['type'] = 'article';
     $searchParams['body']['from'] = $params['from'];
     $searchParams['body']['size'] = $params['size'];
     $searchParams['body']['query']['filtered']['query']['query_string']['query'] = $query;
     $searchParams['body']['query']['filtered']['query']['query_string']['default_operator'] = 'OR';
     $searchParams['body']['query']['filtered']['filter']['term']['enabled'] = true;
     $searchParams['body']['query']['filtered']['filter']['term']['type'] = $params['type'] == 'event' ? 'event' : 'publication';
     if ($params['order'] == 'created') {
         $searchParams['body']['query']['filtered']['query']['query_string']['fields'] = array('title', 'shortText', 'body');
         $searchParams['body']['sort']['created'] = 'desc';
     } else {
         $searchParams['body']['query']['filtered']['query']['query_string']['fields'] = array('title^15', 'shortText^5', 'body^1');
     }
     $retDoc = $client->search($searchParams);
     return $retDoc;
 }
Example #4
0
 public function highlight()
 {
     $client = new Elasticsearch\Client();
     $params['body'] = array('_source' => array('profile.female.not_pregnant.a', 'title'), 'query' => array('match' => array('profile.female.not_pregnant.a' => 'v****a')), 'highlight' => array('fields' => array('profile.female.not_pregnant.a' => new \stdClass())));
     $results = $client->search($params);
     $data = array('results' => $results);
     $this->load->view('welcome_message', $data);
 }
Example #5
0
 public function search($gender, $age, $state = "not_pregnant")
 {
     $client = new Elasticsearch\Client();
     $searchParams['index'] = 'utano';
     $searchParams['type'] = 'sti';
     $profile = "profile." . $gender . "." . $state . "." . $age;
     $searchParams['body'] = array('_source' => 'profile.female.not_pregnant.a', 'query' => array('match_all' => new \stdClass()), 'highlight' => array('fields' => array('profile.female.not_pregnant.a' => new \stdClass())));
     $retDoc = $client->search($searchParams);
     return $retDoc;
 }
Example #6
0
function requete($q)
{
    $paramsH['hosts'] = array('5.135.106.169:9200');
    $client = new Elasticsearch\Client($paramsH);
    // Requete JSON Globale
    $json = $q;
    //'{"query":{"bool":{"must":[{"query_string":{"default_field":"oeuvre.pubDate","query":"alaoui"}}],"must_not":[],"should":[{"query_string":{"default_field":"oeuvre.pubDate","query":"Figuratif"}},{"query_string":{"default_field":"_all","query":"tendance"}}]}},"from":0,"size":10,"sort":[],"facets":{}}';
    //$json = '{"query":{"bool":{"must":[{"match_all":{}}],"must_not":[],"should":[]}},"from":0,"size":5000,"sort":[],"facets":{}}';
    $params['body'] = $json;
    $params['type'] = 'oeuvre';
    $params['index'] = 'arts';
    return $client->search($params);
}
 public function recommendedMovies(Pio $pio)
 {
     $recommended_movies = array();
     try {
         $user_id = session('user_id');
         $pio_predictionclient = $pio->predictionClient();
         $recommended_movies_raw = $pio_predictionclient->sendQuery(array('user' => $user_id, 'num' => 9));
         $movie_ids = array_map(function ($item) {
             return $item['item'];
         }, $recommended_movies_raw['itemScores']);
         $es_client = new \Elasticsearch\Client();
         $search_params['index'] = 'movierecommendation_app';
         $search_params['type'] = 'movie';
         $search_params['body']['query']['bool']['must']['terms']['_id'] = $movie_ids;
         $es_response = $es_client->search($search_params);
         $recommended_movies = $es_response['hits']['hits'];
     } catch (Exception $e) {
         echo 'Caught exception: ', $e->getMessage(), "\n";
     }
     session(array('movies_viewed' => 0, 'user_id' => null));
     return view('recommended_movies', array('recommended_movies' => $recommended_movies));
 }
Example #8
0
 public function fetchPosts($searchterms)
 {
     //Fetch Posts
     //@return Encrypted string
     $client = new Elasticsearch\Client();
     $params['index'] = 'blog';
     $params['type'] = 'posts';
     if (isset($searchterms['author']) && !empty($searchterms['author'])) {
         $params['body']['query']['match']['author'] = $searchterms['author'];
     }
     if (isset($searchterms['title']) && !empty($searchterms['title'])) {
         $params['body']['query']['match']['title'] = $searchterms['title'];
     }
     if (isset($searchterms['content']) && !empty($searchterms['content'])) {
         $params['body']['query']['match']['content'] = $searchterms['content'];
     }
     $allData = array();
     $results = $client->search($params)['hits'];
     $counter = 0;
     foreach ($results['hits'] as $row) {
         if (isset($row['_id'])) {
             $allData[$row['_id']]['id'] = $row['_id'];
         }
         if (isset($row['_source']['author'])) {
             $allData[$row['_id']]['author'] = $row['_source']['author'];
         }
         if (isset($row['_source']['title'])) {
             $allData[$row['_id']]['title'] = $row['_source']['title'];
         }
         if (isset($row['_source']['content'])) {
             $allData[$row['_id']]['content'] = $row['_source']['content'];
         }
     }
     $allData = json_encode($allData);
     return $allData;
 }
Example #9
0
 /**
  * [AJAX] Автозаполнение городов
  * @Route("/ajax/city", name="ajax_city", options={"expose"=true})
  */
 public function ajaxCityAction(Request $request)
 {
     if ($request->query->has('term') == false) {
         return new JsonResponse();
     }
     $term = $request->query->get('term');
     $words = explode(' ', $term);
     $query = implode('* ', $words) . '*';
     $client = new \Elasticsearch\Client();
     $s['index'] = 'website';
     $s['type'] = 'autocomplete_city';
     $s['body']['size'] = 10;
     $s['body']['query']['filtered']['query']['query_string']['query'] = $query;
     $s['body']['query']['filtered']['query']['query_string']['fields'] = array('name', 'title');
     $s['body']['highlight']['fields']['name'] = array("fragment_size" => 100);
     $s['body']['sort']['name']['order'] = 'asc';
     $results = $client->search($s);
     $titles = array();
     if (isset($results['hits']['hits']) && !empty($results['hits']['hits'])) {
         foreach ($results['hits']['hits'] as $result) {
             $titles[] = $result['_source']['title'];
         }
     }
     if (!empty($titles)) {
         return new JsonResponse($titles);
     }
     $em = $this->getDoctrine()->getManager();
     $titles = $em->getRepository('VidalMainBundle:City')->findAutocomplete($term);
     return new JsonResponse($titles);
 }
Example #10
0
<?php

require '../vendor/autoload.php';
header('Content-type: application/json');
$type = $_REQUEST['type'] ? $_REQUEST['type'] : 'nearstop';
$client = new Elasticsearch\Client(array('hosts' => array('127.0.0.1:9200')));
$mainSearchParams['index'] = 'vehicleevents';
$mainSearchParams['type'] = 'event';
$mainSearchParams['body']['aggs']['vehicleevents']['filter']['not']['filter']['term']['eventType'] = $type;
$mainSearchParams['body']['aggs']['vehicleevents']['aggs']['routeevents']['terms']['field'] = 'routeTag';
$mainSearchParams['body']['aggs']['vehicleevents']['aggs']['routeevents']['terms']['size'] = 0;
$mainSearchParams['body']['size'] = 0;
$mainResults = $client->search($mainSearchParams);
echo json_encode($mainResults['aggregations']['vehicleevents']['routeevents']);
Example #11
0
define(ROOT_NODE, 'ROOT');
define(SEARCH_CONTEXT_MIN_WEIGHT, 0.8);
// WME 13072015: disabled since this is already done in search_settings.php
// that one is currently always loaded before this one (see Deltaskin.skin.php)
// Load parameters from parameters.yml
//$settings = Yaml::parse(file_get_contents(__DIR__ .'/parameters.yml'));
//$parameters = $settings['parameters'];
// Check if a query was given
if (!isset($_GET['q'])) {
    header("Location: {$indexUrl}");
    exit;
}
// Create an ElasticSearch client
$esclient = new Elasticsearch\Client(array('hosts' => array($parameters['elastic.server'])));
// Retrieve all contexts
$contexts = $esclient->search(array('index' => $parameters['elastic.index'], 'type' => 'context', 'size' => 1000, 'body' => array('query' => array('match_all' => array()))));
$contexts = $contexts['hits']['hits'];
// Get search results
$search_results = $esclient->search(array('index' => $parameters['elastic.index'], 'size' => 100, 'body' => array('query' => array('multi_match' => array('query' => $_GET['q'], 'fields' => array("skos:prefLabel^3", "skos:definition", "title^3", "content", "concerns_readable^2", "context_readable^2"))))));
$search_results = $search_results['hits']['hits'];
// only take results with VN page
$search_results = array_filter($search_results, function ($res) {
    return count($res['_source']['suggest']['payload']['vn_pages']) > 0;
});
// This helper returns the VN page that should be visited
// when a link is clicked (if available)
function vn_url($source)
{
    if (count($source['suggest']['payload']['vn_pages']) > 0) {
        return $source['suggest']['payload']['vn_pages'][0];
    } else {
Example #12
0
    $locationField = 'point';
    $mainSearchParams['body']['aggs']['events']['geohash_grid']['field'] = 'point';
} else {
    array_push($filters, array('term' => ['eventType' => $type]));
    $mainSearchParams['index'] = 'vehicleevents';
    $mainSearchParams['type'] = 'event';
    $mainSearchParams['body']['aggs']['events']['geohash_grid']['field'] = 'location';
}
array_push($filters, array('geo_bounding_box' => [$locationField => ['top_left' => ['lat' => 37.850636, 'lon' => -122.551841], 'bottom_right' => ['lat' => 37.665367, 'lon' => -122.276801]]]));
if ($route) {
    array_push($filters, array('term' => ['routeTag' => $route]));
}
$mainSearchParams['body']['query']['bool']['must'] = $filters;
$mainSearchParams['body']['aggs']['events']['geohash_grid']['precision'] = 8;
$mainSearchParams['body']['aggs']['events']['geohash_grid']['size'] = 1000;
$mainHits = $client->search($mainSearchParams);
$maxCount = -1;
$mainResults = array();
$geotools = new \League\Geotools\Geotools();
foreach ($mainHits['aggregations']['events']['buckets'] as $mainHitId => $mainHitValue) {
    $geoKey = $mainHitValue['key'];
    $docs = $mainHitValue['doc_count'];
    if ($maxCount == -1) {
        $maxCount = $docs;
    }
    $decodedGeo = $geotools->geohash()->decode($geoKey);
    $lat = $decodedGeo->getCoordinate()->getLatitude();
    $lon = $decodedGeo->getCoordinate()->getLongitude();
    $mainResults[] = array('lat' => $lat, 'lon' => $lon, 'score' => 3 * sprintf("%.5f", $docs / $maxCount));
}
echo json_encode($mainResults);
Example #13
0
function esquery()
{
    global $clientparams;
    $filter = hextostr($_REQUEST['filter']);
    $logtype = hextostr($_REQUEST['logtype']);
    $timestamp = hextostr($_REQUEST['se']);
    $tests = 0;
    $msg = "";
    // Check timestamps
    $pattern = '/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\|\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}/';
    if (!preg_match($pattern, $timestamp)) {
        $tests = 1;
        $msg = "Bad time format!";
    }
    list($start, $end) = explode("|", $timestamp);
    $start = strtotime($start) . "000";
    $end = strtotime($end) . "000";
    $now = strtotime("now") . "000";
    if ($start > $end || $start == $end || $start > $now) {
        $tests = 1;
        $msg = "Bad time logic!";
    }
    // Bail if ts logic isn't sound
    if ($tests == 1) {
        $result = array("dbg" => "{$msg}");
        $theJSON = json_encode($result);
        echo $theJSON;
        exit;
    }
    $client = new Elasticsearch\Client($clientparams);
    $params = array();
    $params['size'] = '500';
    $params['ignore'] = '400,404';
    $json = "{\n    \"query\": {\n      \"filtered\": {\n        \"query\": {\n          \"query_string\": {\n            \"query\": \"type:{$logtype} AND ({$filter})\"\n}\n},\n  \"filter\": {\n    \"range\": {\n      \"timestamp\": {\n        \"from\": {$start},\n          \"to\": {$end}\n}\n}\n}\n}\n},\n  \"size\": 500,\n  \"sort\": [{\n    \"timestamp\": {\n      \"order\": \"desc\"\n}\n}]\n\n}";
    $params['body'] = $json;
    $result = $client->search($params);
    /*
       if ($result[2] == "e") {
           $result = array("dbg"  => "Invalid query!");
       } 
    */
    $theJSON = json_encode($result);
    echo $theJSON;
}
Example #14
0
 private function elastic()
 {
     $client = new Elasticsearch\Client();
     $results = $client->search(['index' => 'reporter', 'type' => 'reporter', 'size' => 1, 'body' => ['query' => ['match_all' => []], 'sort' => ['time' => ['order' => 'asc']]]]);
     print_r($results);
 }
Example #15
0
ini_set('display_startup_errors', 1);
session_start();
include_once dirname(__FILE__) . '/lib/loaderPHPClass.php';
$client = new Elasticsearch\Client();
$uri = htmlspecialchars($_SERVER['REQUEST_URI']);
$topdx = '';
$debug = '';
//Ask a most spoted dx
$searchParams['index'] = 'dxspider';
$searchParams['type'] = 'spots';
$searchParams['size'] = 0;
$searchParams['body']['query']['filtered']['query']['match_all'] = array();
$searchParams['body']['query']['filtered']['filter']['range']['_timestamp']['gte'] = time() * 1000 - 60 * 60 * 1000;
$searchParams['body']['aggs']['topdx']['terms']['field'] = 'dx';
$searchParams['body']['aggs']['topdx']['terms']['size'] = 18;
$retDoc = $client->search($searchParams);
foreach ($retDoc["aggregations"]["topdx"]["buckets"] as $agg) {
    $topdx .= "<tr><td><small><a href=\"/?q={$agg["key"]}\">" . $agg["key"] . "</a></small></td><td><small>" . $agg["doc_count"] . "</small></td></tr>";
}
//Ask a band activity for last hour
$band_data = array();
$band = array("vlf", "160m", "80m", "60m", "40m", "30m", "20m", "17m", "15m", "12m", "10m", "6m", "4m", "2m", "70cm", "23cm", "6cm", "3cm");
foreach ($band as $key => $value) {
    $searchParams1['index'] = 'dxspider';
    $searchParams1['type'] = 'spots';
    $searchParams1['body']['filter']['term']['band'] = $value;
    $searchParams1['body']['query']['range']['_timestamp']['gt'] = 'now-1h';
    $retDoc = $client->search($searchParams1);
    $band_data["{$key}"] = $retDoc["hits"]["total"];
}
//var_dump(json_encode($data));
Example #16
0
        //$movie['has_recommended'] = true;
    }
    session(array('movies_viewed' => $movies_viewed));
    return $movies_viewed;
});
$app->get('/bbb', function () {
    return $b + $c;
});
$app->get('/es', function () {
    $es_client = new \Elasticsearch\Client();
    /*
    $response = $client->sendQuery(array('user'=> 1, 'num'=> 3));
    
    $array = array_map(function($item){
    	return $item['item'];
    }, $response['itemScores']);
    */
    $searchParams['index'] = 'movierecommendation_app';
    $searchParams['type'] = 'movie';
    $searchParams['body']['query']['bool']['must']['terms']['_id'] = array(1, 2, 3, 42, 50, 60, 88, 70, 100);
    $queryResponse = $es_client->search($searchParams);
    return $queryResponse;
});
$app->get('/ya', function () use($app) {
    $user_id = '55358a20dd477';
    $action = 'like';
    $movie_id = 317;
    $pio_eventclient = $app->make('PioEventClient');
    $response = $pio_eventclient->createEvent(array('event' => 'like', 'entityType' => 'user', 'entityId' => $user_id, 'targetEntityType' => 'item', 'targetEntityId' => $movie_id));
    print_r($response);
});
<?php

require_once 'includes.php';
$client = new Elasticsearch\Client();
$jsonString = file_get_contents('amazondata.json');
$documents = json_decode($jsonString, true);
$params['index'] = 'flipzon';
$params['type'] = 'docs';
$count = 0;
foreach ($documents as $document) {
    $params['body']['query']['filtered']['query']['bool']['must'] = [['match' => ['title' => $document['title']]], ['match' => ['color' => $document['color']]]];
    $params['body']['query']['filtered']['filter']['range']['internal']['gte'] = $document['internal'];
    $results = $client->search($params);
    if ($results['hits']['total'] != 0) {
        //update the document
        $count++;
        $id = $results['hits']['hits'][0]['_id'];
        $price_from_fk = $results['hits']['hits'][0]['_source']['price_from_fk'];
        unset($params['body']);
        $params['id'] = $id;
        $params['body']['doc'] = $document;
        $client->update($params);
        unset($params['body']);
        unset($params['id']);
    }
}
echo $count;
Example #18
0
 private function autocompleteProduct($product)
 {
     try {
         # check product is visible
         $productTypes = array('DRUG', 'GOME');
         $marketIds = array(1, 2, 7);
         if ($product->getInactive() || !in_array($product->getProductTypeCode(), $productTypes) || !in_array($product->getMarketStatusID()->getMarketStatusID(), $marketIds)) {
             return false;
         }
         # get names
         $RusName = $this->strip($product->getRusName());
         $RusName = mb_strtolower($RusName, 'UTF-8');
         $EngName = $this->strip($product->getEngName());
         $EngName = mb_strtolower($EngName, 'UTF-8');
         $elasticaClient = new \Elastica\Client();
         $elasticaIndex = $elasticaClient->getIndex('website');
         # check if names exists
         $client = new \Elasticsearch\Client();
         $s['index'] = 'website';
         $s['type'] = 'autocomplete';
         $s['body']['size'] = 1;
         $s['body']['query']['filtered']['query']['query_string']['query'] = $RusName;
         $s['body']['query']['filtered']['query']['query_string']['fields'] = array('name', 'type');
         $s['body']['highlight']['fields']['name'] = array("fragment_size" => 100);
         $s['body']['sort']['type']['order'] = 'desc';
         $s['body']['sort']['name']['order'] = 'asc';
         $s['body']['query']['filtered']['filter']['term']['type'] = 'product';
         $results = $client->search($s);
         $totalRus = $results['hits']['total'];
         $s['body']['query']['filtered']['query']['query_string']['query'] = $EngName;
         $results = $client->search($s);
         $totalEng = $results['hits']['total'];
         # autocomplete
         $type = $elasticaIndex->getType('autocomplete');
         if ($totalRus == 0) {
             $document = new \Elastica\Document(null, array('name' => $RusName, 'type' => 'product'));
             $type->addDocument($document);
         }
         if ($totalEng == 0) {
             $document = new \Elastica\Document(null, array('name' => $EngName, 'type' => 'product'));
             $type->addDocument($document);
         }
         $type->getIndex()->refresh();
         # autocomplete_ext
         $type = $elasticaIndex->getType('autocomplete_ext');
         if ($totalRus == 0) {
             $document = new \Elastica\Document(null, array('name' => $RusName, 'type' => 'product'));
             $type->addDocument($document);
         }
         if ($totalEng == 0) {
             $document = new \Elastica\Document(null, array('name' => $EngName, 'type' => 'product'));
             $type->addDocument($document);
         }
         $type->getIndex()->refresh();
         # product
         $type = $elasticaIndex->getType('autocomplete_product');
         if ($totalRus == 0) {
             $name = $RusName . ' ' . $product->getProductID();
             $document = new \Elastica\Document(null, array('name' => $name));
             $type->addDocument($document);
         }
         $type->getIndex()->refresh();
     } catch (\Exception $e) {
     }
     return true;
 }
    public function actionSearch()
    {
        // If no terms exist, just show the form:
        if (isset($_GET['terms'])) {
            $terms = $_GET['terms'];
        } else {
            $this->render('search', array('terms' => null));
            Yii::app()->end();
        }
        // Configure the search:
        $params = array();
        $params['index'] = $this->_index;
        $params['type'] = $this->_type;
        $params['body'] = '{
		"query": {
			"multi_match": {
				"query": "' . $terms . '",
				"fields": [
					"title^1",
					"author^1",
					"content"
					],
				"minimum_should_match": "75%"
			}
		},
		"highlight": {
			"fields": {
				"content": {
					"fragment_size": 300
				},
				"title": {
					"number_of_fragments": 0
				},
				"author": {
					"number_of_fragments": 0
				}
			}
		}
		}';
        // Create the client:
        $client = new Elasticsearch\Client();
        // Perform the search
        $results = $client->search($params);
        // Get the total:
        $total = $results['hits']['total'];
        // Get the hits:
        $hits = array();
        foreach ($results['hits']['hits'] as $hit) {
            $id = $hit['_id'];
            $hits[$id]['title'] = $hit['_source']['title'];
            // New version loops through "highlight":
            foreach ($hit['highlight'] as $field => $h) {
                $hits[$id]['highlight'][$field] = $h[0];
            }
        }
        // Render the view, passing along the stuff:
        $this->render('search', array('total' => $total, 'hits' => $hits, 'terms' => $terms));
    }
Example #20
0
 public function getAutoSearch($terms)
 {
     if ($terms != -11111) {
         $strQuery = $terms;
         $client = new \Elasticsearch\Client();
         $params = array('index' => 'portal', 'type' => 'links');
         $params['body']['query']['query_string']['fields'] = ["name", "descript", "link"];
         $params['body']['query']['query_string']['query'] = "*{$strQuery}* OR {$strQuery}";
         $params['body']['query']['query_string']['analyzer'] = 'thai';
         $params['analyzer'] = "thai";
         $params['size'] = 50;
         //$params['analyzer'] = 'thai';
         //$result =$client->mlt($params);
         $results = $client->search($params);
         $results = new ResultCollection($results, $instance = new Link());
         //dd($results);
         Session::flash('search', $terms);
         return View::make('home.ajax-search')->with('results', $results);
     } else {
         return View::make('home.ajax-search');
     }
     //return View::make('home.ajax-search');
 }
Example #21
0
 /** @Route("/elastic/autocomplete_veterinar/{term}", name="elastic_autocomplete_veterinar", options={"expose":true}) */
 public function autocompleteNozologyAction($term)
 {
     $words = explode(' ', $term);
     $query = implode('* ', $words) . '*';
     $client = new \Elasticsearch\Client();
     $s['index'] = 'website';
     $s['type'] = 'veterinar_autocomplete';
     $s['body']['size'] = 15;
     $s['body']['query']['filtered']['query']['query_string']['query'] = $query;
     $s['body']['query']['filtered']['query']['query_string']['fields'] = array('code', 'name');
     $s['body']['highlight']['fields']['name'] = array("fragment_size" => 100);
     $s['body']['sort']['name']['order'] = 'asc';
     $results = $client->search($s);
     return new JsonResponse($results);
 }