Welcome Guest, Not a member yet? Register   Sign In
Help creating a search model for my new website
#1

[eluser]unmillon[/eluser]
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.

Code:
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

[eluser]thinkigniter[/eluser]
Try
Code:
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 ");
        }

Add '%' for containing keyword
#3

[eluser]unmillon[/eluser]
Thanks for replying, I added the % now, but that would not solved my problems. I still need to make a better way of searching than this.
#4

[eluser]jaswinder_rana[/eluser]
Not sure what you mean but you may be looking for boolean search.

If you DB is MySQL then you can try joedolson[dot]com/Search-Engine-in-PHP-MySQL.php

Not sure if this is what you want
#5

[eluser]John_Betong[/eluser]
&nbsp;
http://ellislab.com/forums/viewthread/100106/
&nbsp;
Check out my solution with an actual example in your above duplicated message.
&nbsp;
&nbsp;
#6

[eluser]unmillon[/eluser]
Thank you guys for posting your reply and try to help me.

jaswinder_rana: I think that's exactly what I'm looking for, is it possible for me to implement that in codeigniter?

Can you help me modify it to use it on my site?

Thanks in advance for your help.
#7

[eluser]jaswinder_rana[/eluser]
I haven't used it before. I was planning to use it myself and was researching hence the reason I had that link.

And your should be able to do it in CI because it's just a matter of creating that query. I don't think there's a library in CI that may do that for you (or maybe I missed reading it). So, you'll have to take users' input from your search box and generate that query.

You can download that script from the link I gave you (I think its script) and then copy their logic into your controller, generate where statement and pass it on to your Model.
#8

[eluser]Phil Sturgeon[/eluser]
No active record methods for match (yet) I'm afraid so full-text searches will need to be done with a straight SQL string as mentioned above.
#9

[eluser]unmillon[/eluser]
I still need help with this search function. I can offer $100 who ever can help me get this done using codeigniter. I need a smart search function, that can bring back results that are relevant to the search string.

For example: If I search for Beyonce Single Ladies, it will bring me any songs related to this search and not all the songs from Beyonce with nothing to do with single ladies.

Please let me know if one of you can make this for me. I will pay via Paypal.

Thanks again.
#10

[eluser]John_Betong[/eluser]
[quote author="browseformusic" date="1231798996"]I still need help with this search function. I can offer $100 who ever can help me get this done using codeigniter. I need a smart search function, that can bring back results that are relevant to the search string.

For example: If I search for Beyonce Single Ladies, it will bring me any songs related to this search and not all the songs from Beyonce with nothing to do with single ladies.

Please let me know if one of you can make this for me. I will pay via Paypal.

Thanks again.[/quote]

Hi,

Take a look at Johns-Jokes.com. it uses a search which could no doubt be adapted to suit your needs.

Let me know how you get on.

Cheers,

John_Betong




Theme © iAndrew 2016 - Forum software by © MyBB