From 69c30ca56fdc6a4eff236902040cc04ec6eaccf2 Mon Sep 17 00:00:00 2001 From: Calin Burloiu Date: Thu, 8 Sep 2011 11:26:08 +0300 Subject: [PATCH] search queries with less than 4 characters find videos via LIKE sql command --- application/controllers/catalog.php | 4 ++-- application/language/english/error_lang.php | 2 +- application/models/videos_model.php | 23 ++++++++++++++++----- application/views/header.php | 4 ++-- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/application/controllers/catalog.php b/application/controllers/catalog.php index 95a6908..1addf0d 100644 --- a/application/controllers/catalog.php +++ b/application/controllers/catalog.php @@ -176,10 +176,10 @@ class Catalog extends CI_Controller { } // Check if search string is valid. - if (strlen($search_query) < 4) + if (strlen($search_query) === 0) { //$results_data['videos'] = NULL; - $this->error($this->lang->line('error_search_query_too_short'), + $this->error($this->lang->line('error_search_query_empty'), $header_data); return; } diff --git a/application/language/english/error_lang.php b/application/language/english/error_lang.php index ae3448f..c7983ef 100644 --- a/application/language/english/error_lang.php +++ b/application/language/english/error_lang.php @@ -1,6 +1,6 @@ is_advanced_search_query($search_query)) // if natural language mode + { + // very short queries + if (strlen($search_query) < 4) + { + $search_cond = "(title LIKE '%$search_query%' + OR description LIKE '%$search_query%' + OR tags LIKE '%$search_query%')"; + $relevance = "( 0.5 * (title LIKE '%git%') + + 0.2 * (description LIKE '%git%') + + 0.3 * (tags LIKE '%git%') ) AS relevance"; + } + // natural language mode + else if (! $this->is_advanced_search_query($search_query)) { $search_cond = "MATCH (title, description, tags) AGAINST ('$search_query')"; $relevance = "$search_cond AS relevance"; - } // if boolean mode + } + // boolean mode else { $against = "AGAINST ('$search_query' IN BOOLEAN MODE)"; @@ -262,9 +274,10 @@ class Videos_model extends CI_Model { $limit = ""; } else - { + { + // TODO select data, description if details are needed $selected_columns = "id, name, title, duration, user_id, views, - thumbs_count, default_thumb, date, description, + thumbs_count, default_thumb, (views + likes - dislikes) AS score, $relevance"; $order = "ORDER BY relevance DESC, score DESC"; diff --git a/application/views/header.php b/application/views/header.php index 987b6c4..0a8609e 100644 --- a/application/views/header.php +++ b/application/views/header.php @@ -82,9 +82,9 @@ var fakeSubmit = function() { var searchQuery = $('#search').val(); - if (searchQuery.length < 4) + if (searchQuery.length === 0) { - alert('lang->line('error_search_query_too_short') ?>'); + alert('lang->line('error_search_query_empty') ?>'); return; } -- 2.20.1