search queries with less than 4 characters find videos via LIKE sql command
authorCalin Burloiu <calin.burloiu@gmail.com>
Thu, 8 Sep 2011 08:26:08 +0000 (11:26 +0300)
committerCalin Burloiu <calin.burloiu@gmail.com>
Thu, 8 Sep 2011 08:26:08 +0000 (11:26 +0300)
application/controllers/catalog.php
application/language/english/error_lang.php
application/models/videos_model.php
application/views/header.php

index 95a6908..1addf0d 100644 (file)
@@ -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;
                }
index ae3448f..c7983ef 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-$lang['error_search_query_too_short'] = 'The search query is too short! You must enter at least 4 characters.';
+$lang['error_search_query_empty'] = 'The search query is empty! Type something to search for or otherwise go to the home page to browse.';
 
 /* End of file error_lang.php */
 /* Location: ./application/language/english/error_lang.php */
\ No newline at end of file
index 73bdde7..fccb7a0 100644 (file)
@@ -238,13 +238,25 @@ class Videos_model extends CI_Model {
         */
        public function search_videos($search_query, $offset = 0, $count = 0, 
                                                                        $category_id = NULL)
-       {               
-               if (! $this->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";
index 987b6c4..0a8609e 100644 (file)
@@ -82,9 +82,9 @@
                var fakeSubmit = function() {
                        var searchQuery = $('#search').val();
 
-                       if (searchQuery.length < 4)
+                       if (searchQuery.length === 0)
                        {
-                               alert('<?php echo $this->lang->line('error_search_query_too_short') ?>');
+                               alert('<?php echo $this->lang->line('error_search_query_empty') ?>');
                                return;
                        }