Permalink
Browse files

New module finder version

Now the modules work in get (previous was post). It does query in contents (title field and text field) and in categories (title field and name field).
  • Loading branch information...
vivimpresa committed Jun 14, 2017
1 parent 52b2769 commit 44f6339f6324f6abe218a16050a5e1bd2f7220d8
Showing with 72 additions and 72 deletions.
  1. +72 −72 modules/finder/models/finder.php
@@ -1,73 +1,73 @@
<?php
defined( 'DACCESS' ) or die;
class MModel_Finder {
static function search($key) {
$searchstring = $key;
if (strlen($searchstring) >= 3) {
$searchstring = str_replace(array('\'', '`'), array('\\\'', '\\`'), $searchstring);
$language = new M_Language;
$contentlang = $language->getLanguage();
$PlaceSearch_category = array();
$SearchQueryArray = explode(' ', $searchstring);
$SearchQuery = '((`text` LIKE \'%' . implode('%\' AND `text` LIKE \'%', $SearchQueryArray) . '%\')';
$SearchQuery .= ' OR ';
$SearchQuery .= '(`title` LIKE \'%' . implode('%\' AND `title` LIKE \'%', $SearchQueryArray) . '%\'))';
$SearchQuery .= ' AND (`type` = \'place\' OR `type` = \'event\' OR `type` = \'route\')';
$CatSearchQuery = '((`name` LIKE \'%' . implode('%\' AND `name` LIKE \'%', $SearchQueryArray) . '%\')';
$CatSearchQuery .= ' OR ';
$CatSearchQuery .= '(`title` LIKE \'%' . implode('%\' AND `title` LIKE \'%', $SearchQueryArray) . '%\'))';
$PlaceSearch_content = ORM::for_table('contents')->select('title')->select('route', 'point')->select('id')->select('lat')->select('lng')->select('start')->select('end')->select('address')->select('text')->where_raw($SearchQuery)->where('enabled', 1)->where('language', $contentlang)->find_array();
$CatSearch = ORM::for_table('categories')->select_many('contents', 'title', 'id')->where_raw($CatSearchQuery)->where('enabled', 1)->find_array();
if (is_array($CatSearch)) {
if (count($CatSearch) > 0) {
$QueryString = NULL;
foreach ($CatSearch as $OneCategory) {
$PlacesString = $OneCategory['contents'];
if (strlen(trim($PlacesString)) > 0) {
$PlacesString = str_replace(array('{', '}'), '', $PlacesString);
$PlacesArray = explode(';', $PlacesString);
$PlacesArray = array_filter($PlacesArray);
if (count($PlacesArray) > 0) {
foreach ($PlacesArray as $ContentID) {
if (is_numeric($ContentID)) {
$QueryString .= '`id` = ' . $ContentID . ' OR ';
}
}
$QueryString = '(' . rtrim($QueryString, ' OR ') . ')';
$PlaceSearch_category = ORM::for_table('contents')->select('title')->select('route', 'point')->select('id')->select('lat')->select('lng')->select('start')->select('end')->select('address')->select('text')->where_raw($QueryString)->where('enabled', 1)->where('language', $contentlang)->find_array();
}
}
}
}
}
$SearchResult = array_merge($PlaceSearch_category, $PlaceSearch_content);
if (is_array($SearchResult)) {
if (count($SearchResult) > 0) {
return $SearchResult;
} else {
return FALSE;
}
} else {
return FALSE;
}
} else {
return FALSE;
}
}
<?php
defined( 'DACCESS' ) or die;
class MModel_Finder {
static function search($key) {
$searchstring = $key;
if (strlen($searchstring) >= 3) {
$searchstring = str_replace(array('\'', '`'), array('\\\'', '\\`'), $searchstring);
$language = new M_Language;
$contentlang = $language->getLanguage();
$PlaceSearch_category = array();
$SearchQueryArray = explode(' ', $searchstring);
$SearchQuery = '((`text` LIKE \'%' . implode('%\' AND `text` LIKE \'%', $SearchQueryArray) . '%\')';
$SearchQuery .= ' OR ';
$SearchQuery .= '(`title` LIKE \'%' . implode('%\' AND `title` LIKE \'%', $SearchQueryArray) . '%\'))';
$SearchQuery .= ' AND (`type` = \'place\' OR `type` = \'event\' OR `type` = \'route\' OR `type` = \'post\')';
$CatSearchQuery = '((`name` LIKE \'%' . implode('%\' AND `name` LIKE \'%', $SearchQueryArray) . '%\')';
$CatSearchQuery .= ' OR ';
$CatSearchQuery .= '(`title` LIKE \'%' . implode('%\' AND `title` LIKE \'%', $SearchQueryArray) . '%\'))';
$PlaceSearch_content = ORM::for_table('contents')->select('title')->select('route', 'point')->select('id')->select('lat')->select('lng')->select('start')->select('end')->select('address')->select('text')->where_raw($SearchQuery)->where('enabled', 1)->where('language', $contentlang)->find_array();
$CatSearch = ORM::for_table('categories')->select_many('contents', 'title', 'id')->where_raw($CatSearchQuery)->where('enabled', 1)->find_array();
if (is_array($CatSearch)) {
if (count($CatSearch) > 0) {
$QueryString = NULL;
foreach ($CatSearch as $OneCategory) {
$PlacesString = $OneCategory['contents'];
if (strlen(trim($PlacesString)) > 0) {
$PlacesString = str_replace(array('{', '}'), '', $PlacesString);
$PlacesArray = explode(';', $PlacesString);
$PlacesArray = array_filter($PlacesArray);
if (count($PlacesArray) > 0) {
foreach ($PlacesArray as $ContentID) {
if (is_numeric($ContentID)) {
$QueryString .= '`id` = ' . $ContentID . ' OR ';
}
}
$QueryString = '(' . rtrim($QueryString, ' OR ') . ')';
$PlaceSearch_category = ORM::for_table('contents')->select('title')->select('route', 'point')->select('id')->select('lat')->select('lng')->select('start')->select('end')->select('address')->select('text')->where_raw($QueryString)->where('enabled', 1)->where('language', $contentlang)->find_array();
}
}
}
}
}
$SearchResult = array_merge($PlaceSearch_category, $PlaceSearch_content);
if (is_array($SearchResult)) {
if (count($SearchResult) > 0) {
return $SearchResult;
} else {
return FALSE;
}
} else {
return FALSE;
}
} else {
return FALSE;
}
}
}

0 comments on commit 44f6339

Please sign in to comment.