Exemplo n.º 1
0
 /**
  * Search tweets
  *
  * @todo   Allow searching for empty location
  * @todo   Search operator for text and location is OR - change to AND
  * @param  array $q     Query fields and values
  * @param  array $limit Limit results
  * @return array
  */
 public function search(array $q, $limit = 1000)
 {
     $params = ['index' => $this->_esindex, 'type' => $this->_estype, 'size' => $limit];
     $continue = false;
     if (isset($q['text']) && $q['text'] !== "") {
         $params['q']['text'] = $q['text'];
         $continue = true;
     }
     if (isset($q['location']) && $q['location'] !== "") {
         $params['body']['query']['match']['user.location'] = $q['location'];
         $continue = true;
     }
     if ($continue === false) {
         return [];
     }
     $query = $this->_es->search($params);
     if ($query['hits']['total'] >= 1) {
         $result = $query['hits']['hits'];
     } else {
         $result = [];
     }
     return $result;
 }
Exemplo n.º 2
0
<?php

require "elastic.php";
require "indexer.php";
require "searcher.php";
$indexer = new Indexer();
$indexer->setIndex("test")->setType("type");
echo "Add\n";
print_r($indexer->add(array("name" => 'asd', "phone" => "79111234567")));
print_r($indexer->add(array("name" => 'test asd', "phone" => "79133234567")));
print_r($indexer->add(array("name" => 'test', "phone" => "79155234567")));
$client = new Elastic();
echo "Get\n";
print_r($client->get(array('index' => 'test', 'type' => 'type', 'id' => 1)));
$searcher = new Searcher();
$searcher->setIndex("test")->setType("type");
echo "Search\n";
print_r($searcher->partial_query(array("name" => "te", 'phone' => '7913')));
// print_r($searcher->query_string('test +79155234*'));
echo "Clear index\n";
//print_r($indexer->clear());
Exemplo n.º 3
0
Elastic::set_option('base_domain', $_SERVER['HTTP_HOST']);
Elastic::set_option('base_path', '/');

Container::instance()->set_implementation('Session_StorageInterface', 'Session_Storage_Cookie');
Container::instance()->set_implementation('Session_IdentifierInterface', 'Session_Identifier_Cookie');

Container::instance()->set_scope('StorageInterface', 'singleton');
Container::instance('page_cache')->set_scope('StorageInterface', 'singleton');
Container::instance()->set_implementation('StorageInterface', 'Storage_Array');

Container::instance()->set_implementation('Config_ReaderInterface', 'Config_Reader_PHP');
Container::instance()->set_implementation('Config_WriterInterface', 'Config_Writer_PHP');

Elastic::module('doctrine', MOD_ROOT.'/doctrine');
Elastic::module('twig',     MOD_ROOT.'/twig');

Route::set('front/page')
  ->uri('(<controller>(/<action>(/<id>)))')
  ->options(array('class' => 'Controller_Front_Page_<controller>', 'method' => 'action_<action>', 'directory' => 'front/page'))
  ->segments(array('id' => '\d+'))
  ->defaults(array('controller' => 'home', 'action' => 'index'));

Route::set('front/pagelet')
  ->uri('pagelet(/<controller>(/<action>(/<id>)))')
  ->options(array('class' => 'Controller_Front_Pagelet_<controller>', 'method' => 'action_<action>', 'directory' => 'front/pagelet'))
  ->segments(array('id' => '\d+'))
  ->defaults(array('controller' => 'home', 'action' => 'index'));

Route::set('back/page')
  ->uri('admin(/<controller>(/<action>(/<id>)))')