Revize 1000
Přidáno uživatelem Michal Kliment před více než 13 roky(ů)
freenetis/branches/search_filters/application/i18n/cs_CZ/texts.php | ||
---|---|---|
'save' => 'Uložit',
|
||
'save wireless setting' => 'Uložit bezdrátové nastavení',
|
||
'search' => 'Hledat',
|
||
'searching' => 'Vyhledávání',
|
||
'searching of term' => 'Vyhledávání výrazu',
|
||
'second-degree certified engineers' => 'Certifikovaní technici druhého stupně',
|
||
'secondary dns' => 'Sekundární DNS.',
|
freenetis/branches/search_filters/application/helpers/arr.php | ||
---|---|---|
return $array;
|
||
}
|
||
|
||
/**
|
||
* Creates array from string
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $string
|
||
* @param integer $length
|
||
* @param integer $offset
|
||
* @return array
|
||
*/
|
||
public static function from_string ($string, $length, $offset = 0)
|
||
{
|
||
$array = array();
|
||
... | ... | |
return $array;
|
||
}
|
||
|
||
/**
|
||
* Returns variation of array
|
||
*
|
||
* @author Michal Kliment
|
||
* @param array $array
|
||
* @param integer $class
|
||
* @return array
|
||
*/
|
||
public static function variation ($array, $class)
|
||
{
|
||
$arr = array();
|
freenetis/branches/search_filters/application/models/search.php | ||
---|---|---|
<?php
|
||
/**
|
||
*
|
||
* @author Michal Kliment
|
||
* @copyright (c) 2011 Kliment Michal
|
||
* @license GNU GPLv3
|
||
* @license http://www.gnu.org/licenses/gpl.txt
|
||
*/
|
||
|
||
class Search_Model extends Model
|
||
{
|
||
// definitions of serach rules
|
||
public static $rules = array(
|
||
array(
|
||
'method' => 'member_name',
|
||
... | ... | |
),
|
||
);
|
||
|
||
/**
|
||
* Searchs in members by name
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function member_name ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in members by ID
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function member_id ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in members by variable symbol
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function member_variable_symbol ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in members by comment
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function member_comment ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in members by town
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function member_town ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in members by street and street number
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function member_street ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in users by name
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function user_name ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in users by login
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function user_login ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in users by contact
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function user_contact($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in towns by name
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function town_name ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in devices by name
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function device_name ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in devices by MAC address
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function device_mac ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
WHERE ic.mac LIKE '%$keyword%' COLLATE utf8_general_ci
|
||
");
|
||
}
|
||
|
||
|
||
/**
|
||
* Searchs in devices by IP address
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function device_ip_address ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in subnets by name
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function subnet_name ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in subnets by address
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function subnet_address ($keyword)
|
||
{
|
||
return $this->db->query("
|
||
... | ... | |
");
|
||
}
|
||
|
||
/**
|
||
* Searchs in segments by name
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
* @return MySQL Result object
|
||
*/
|
||
public function segment_name ($keyword)
|
||
{
|
||
return $this->db->query("
|
freenetis/branches/search_filters/application/controllers/search.php | ||
---|---|---|
<?php
|
||
/**
|
||
*
|
||
* @author Michal Kliment
|
||
* @copyright (c) 2011 Kliment Michal
|
||
* @license GNU GPLv3
|
||
* @license http://www.gnu.org/licenses/gpl.txt
|
||
*/
|
||
|
||
class Search_Controller extends Controller
|
||
{
|
||
private $results = array();
|
||
|
||
/**
|
||
* Only redirects to method simple
|
||
*
|
||
* @author Michal Kliment
|
||
*/
|
||
public function index()
|
||
{
|
||
url::redirect (url_lang::base().'search/simple/'.$this->input->get('keyword'));
|
||
}
|
||
|
||
/**
|
||
* Base method, makes search
|
||
*
|
||
* @author Michal Kliment
|
||
* @param string $keyword
|
||
*/
|
||
private function search ($keyword = NULL)
|
||
{
|
||
$keywords = explode(" ", trim($keyword));
|
||
|
||
$keys = array();
|
||
|
||
// finds all possible variations
|
||
for ($i = count($keywords); $i > 0;$i--)
|
||
$keys = arr::merge($keys, arr::variation ($keywords, $i));
|
||
|
||
$search_model = new Search_Model();
|
||
|
||
$sum_counts = array();
|
||
$ids = array();
|
||
$models = array();
|
||
$sums = array();
|
||
$counts = array();
|
||
$total_counts = array();
|
||
$values = array();
|
||
|
||
// foreach all search rules
|
||
foreach (Search_Model::$rules as $rule)
|
||
{
|
||
// foreach variations
|
||
foreach ($keys as $key)
|
||
{
|
||
$weight = count(explode(" ",$key));
|
||
if (isset($total_counts[$rule['model']]))
|
||
$total_counts[$rule['model']]++;
|
||
else
|
||
... | ... | |
|
||
foreach ($result as $row)
|
||
{
|
||
// test how much are texts similar
|
||
similar_text(url::title($row->value," "), url::title($key, " "), $percent);
|
||
//echo $row->return_value." ".url::title($row->value)." ".url::title($key)." $percent $weight<br />";
|
||
if (!isset($sums[$rule['model']][$row->id]))
|
||
{
|
||
$sums[$rule['model']][$row->id] = 0;
|
||
... | ... | |
}
|
||
}
|
||
|
||
//echo "<pre>";
|
||
|
||
$result_sums = array();
|
||
$result_counts = array();
|
||
|
||
// transforms to 1-dimensional array
|
||
foreach ($sums as $model => $model_sums)
|
||
{
|
||
foreach ($model_sums as $id => $sum)
|
||
{
|
||
//echo "$model $id ".$sum." ".$total_counts[$model]."<br />";
|
||
//$result_sums[] = $sum / $total_counts[$model];
|
||
$result_sums[] = $sum;
|
||
$result_counts[] = $counts[$model][$id] / $total_counts[$model];
|
||
$this->results[] = $values[$model][$id];
|
||
}
|
||
}
|
||
|
||
// sorts results
|
||
array_multisort ($result_sums, SORT_DESC, $this->results, SORT_DESC);
|
||
}
|
||
|
||
/**
|
||
* Simple searching, uses method search
|
||
*
|
||
* @author Michal Kliment
|
||
* @param <type> $keyword
|
||
* @param <type> $limit_results
|
||
* @param <type> $page_word
|
||
* @param <type> $page
|
||
*/
|
||
public function simple ($keyword = NULL, $limit_results = 20, $page_word = 'page', $page = 1)
|
||
{
|
||
//$profiler = new Profiler();
|
||
... | ... | |
$to = count($this->results)-1;
|
||
|
||
$view = new View('main');
|
||
$view->title = $keyword;
|
||
$view->keyword = $keyword;
|
||
$view->title = $keyword . ' - '.url_lang::lang('texts.Searching');
|
||
$view->content = new View('search');
|
||
$view->content->keyword = $keyword;
|
||
$view->content->total_items = count($this->results);
|
||
... | ... | |
//echo $profiler->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Ajax searching (for whisper)
|
||
*
|
||
* @author Michal Kliment
|
||
* @param integer $count
|
||
*/
|
||
public function ajax ($count = 100)
|
||
{
|
||
$this->search($this->input->get('q'));
|
||
|
||
$counter = 0;
|
||
|
||
// prints all results
|
||
foreach ($this->results as $result)
|
||
{
|
||
$counter++;
|
||
... | ... | |
break;
|
||
}
|
||
|
||
// no results
|
||
if (!$counter)
|
||
{
|
||
?>
|
freenetis/branches/search_filters/application/views/main.php | ||
---|---|---|
if ($this->session->get('user_id'))
|
||
{
|
||
echo form::open(url_lang::base().'search', array('method' => 'get', 'autocomplete' => 'off', 'class' => 'search'));
|
||
echo form::input('keyword');
|
||
echo form::input('keyword',(isset($keyword) ? $keyword : ''));
|
||
echo form::imagebutton('search_submit', url::base().'media/images/icons/search.gif');
|
||
echo form::close();
|
||
?>
|
Také k dispozici: Unified diff
Takrka dokonceno vyhledavani. Jeste zbyva implementovat vylepseni filtru.