ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Help creating a search model for my new website

December 17, 2008 4:00pm

Subscribe [6]
  • #1 / Dec 17, 2008 4:00pm

    unmillon

    7 posts

    Hello guys,

    This is my first post here at codeigniter’s forum, I’m new to codeigniter and so far I love how easy it is to make a website using it.  I started working on my first project using codeigniter for a website called BrowseForMusic.com.  I’m 90% done with the site except that the search part of it is not working as it should.

    I’m using fulltext search with MySQL database but the problem I’m having is that I can’t search for words with 3 characters or less. For example “DMX” which i have tons of records in my database, it returned 0 because it only has 3 characters. 

    Since I’m using share hosting, the hosting company doesn’t want to disable the 3 words feature in MySQL config file.

    Can someone help me create a model that will fix this problem?

    Right now this is what I’m currently using at the site as a work around. But i would like to have a better way to search and display more relevant results.

    if (strlen($search_words) < 4) {    
                $query = $this->db->query("SELECT * FROM songs WHERE deadlink='No' AND artistName LIKE '". $search_words ."' OR title LIKE '". $search_words ."' LIMIT $offset, $num ");
            } else {
                $query = $this->db->query("SELECT *, MATCH (s.artistName,s.title) AGAINST('" . $search_words ."') AS score  FROM songs AS s WHERE MATCH (s.artistName,s.title) AGAINST('" . $search_words ."') HAVING score > 0.2 AND deadlink='No' ORDER BY score DESC LIMIT $offset, $num ");
            }

    Any help will be greatly appreciated.

    Sincerely,

    Eddie

  • #2 / Dec 17, 2008 11:18pm

    John_Betong

    690 posts

    if (strlen($search_words) < 4)
      {    
        $query = $this->db->query(
           "
             SELECT * FROM songs 
             WHERE deadlink='No' 
             AND   artistName LIKE '%". $search_words ."%' 
             OR    title      LIKE '%". $search_words ."%' 
             LIMIT $offset, $num 
           ");
      }else{
       ...
       ...
      }

     
    I don’t know what your value of $search_words is but if it does not include any % then try modifying your SQL code to the above.
     
     
    “you and me can try all day to get zen to work”
     
    I tried the above search in my http://johns-jokes.com
    and this is the sql statement:

    SELECT * FROM jokes WHERE  
    (
     (title LIKE '%you%' OR memo LIKE '%you%')) 
      AND  ( (title LIKE '%and%' OR memo LIKE '%and%')) 
      AND  ( (title LIKE '%me%' OR memo LIKE '%me%')) 
      AND  ( (title LIKE '�n%' OR memo LIKE '�n%')) 
      AND  ( (title LIKE '%try%' OR memo LIKE '%try%')) 
      AND  ( (title LIKE '%all%' OR memo LIKE '%all%')) 
      AND  ( (title LIKE '�y%' OR memo LIKE '�y%')) 
      AND  ( (title LIKE '%to%' OR memo LIKE '%to%')) 
      AND  ( (title LIKE '%get%' OR memo LIKE '%get%')) 
      AND  ( (title LIKE '%zen%' OR memo LIKE '%zen%')) 
      AND  ( (title LIKE '%to%' OR memo LIKE '%to%')) 
      AND  ( (title LIKE '%work%' OR memo LIKE '%work%')
    )

     
     
    edit: formatted for easier reading
     

  • #3 / Dec 19, 2008 1:49pm

    Tom Schlick

    386 posts

    i really like your site. for shared hosting it is surprisingly fast. i saw the disclaimer at the bottom saying you dont host the music files… where are they hosted?

  • #4 / Dec 19, 2008 4:10pm

    unmillon

    7 posts

    Thanks, the music is hosted at different websites. I created a crawler that craws the internet and get me the music. So i only store the URL, title, artist’s name and duration of the song.

    But thanks for checking it out!

  • #5 / Dec 30, 2008 1:27am

    jonhurlock

    11 posts

    You may want to edit your config so that:

    $config['index_page'] = "index.php";

    looks like:

    $config['index_page'] = "";

    to get rid of the index.php/ part in the URLs 😉

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases