Forum Moderators: open

Message Too Old, No Replies

Force search less than 4 chars?

Shared server need to force less than 4 character search in mysql

         

salewit

11:58 pm on Nov 17, 2007 (gmt 0)

10+ Year Member



Does anyone know of any tricks or any way to force a MySQL search for LESS THAN 4 characters? It's critical to what I'm trying to do. I'm on a shared hosting situation and the host has already said they can't change the .ini file just for me.

Our site is railroad related, and I started a log of what people are searching for and I'm getting lots of requests like "big boy" (a steam locomotive), EMD, CAB, GG1, etc. They are all returning 0 results when there should be hundreds. My log is showing about 75% failures because of this problem. Any way around this using MySQL?

Habtom

7:05 am on Nov 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



MySQL search for LESS THAN 4 characters

Is this really a MySQL issue, or something you need to do from PHP?

salewit

2:53 pm on Nov 18, 2007 (gmt 0)

10+ Year Member



It's 100% a MySQL issue. What does PHP have to do with it? When I use the MySQL fulltext search function, MySQL throws out any search word less than 4 characters (by default). It doesn't matter what scripting language you use. Unless I'm misunderstanding the entire situation.

inbound

4:01 pm on Nov 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The ideal answer is not to use MySQL Full Text Search, it's poor in comparison to the many alternatives out there. The problem with being on shared space is that you may not be able to install some of the software that would do the job well. I would search for full text search alternatives. One that I would highly recommend is SphinxSearch, it's lightning fast and easy to use.

If you can't go down an alternative route then the answer to your problem may be to improvise, this could be affected by the size of your database. A 'quick and dirty' solution would be to replicate the searchable part of your database with a 3 character string added to every word (e.g big becomes bigxyz) and then do a search for 'bigxyz boyxyz' instead of 'big boy', there are all sorts of reasons why that's not a great solution but it would get around your 4 character issue.

I would suggest that if your hosting set up is causing you problems then moving may be the answer. having to write 'solutions around artificially imposed restrictions is not the way forward. If you are having an issue with full text search then I'd guess that many other issues will crop up and cause you to spend more time than need be (hence making it more efficieant to just pay more for your hosting than spending hours more on every bit of coding). Moving to a host that gives you more control means you can use the wealth of advice that's out there without having to engineer your way around restrictions, an example is that a really good full text search solution to your problem could be up and running in less time than some people take for lunch.

salewit

5:53 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



Thanks for the response. I really do appreciate it. A little off topic, but when I was just getting out of high school, I had a beat up old Fiat that was literally falling apart. Well being that age and broke I could barely afford a gallon of gas let alone repairs on the car. So when my exhaust pipe started to develop a rust hole, I would buy that crappy muffler tape that fixed it for a good year or so. When my tires started showing the steel belts, I'd buy a used set for $10 each. I was always told "Just buy some good $500 Michelin's and you'll be done with it", or "just replace that exhaust system and do it right". These are totally correct comments to make. But not everyone has the capabilities to do what they'd like.

Anyway, the point I'm making is I have a website that "at this time" is just about breaking even. Would I like a dedicated server? Sure! But sometime you just have to make do with what you can afford and if jerry-rigging will get you through it until things do start clicking, than that is what I have no choice but to do.

Really, I do appreciate the "do it right the first time" response, but it's not always possible. We've got a ton of data in our MySQL databases, they're working extremely well, I know how to work with it, and the access is lightning fast including search terms that are > 3 characters and I was just hoping there would be some kind of tweak or method of creating a secondary .ini file I can get MySQL to recognize that will lower the word count setting.

quizme2000

9:45 pm on Feb 11, 2008 (gmt 0)

10+ Year Member



to set up min_len and stopword_file in windows (win2k or xp):

1. run services.msc to check what .ini your mysql is reading (in my case, "C:\MySQL\bin\mysqld-nt" --defaults-file="C:\MySQL\my.ini" MySQL)

2. change your my.ini like this:
[mysqld]
ft_min_word_len=3
ft_stopword_file="C:\\MySQL\\stop.txt"

3. restart your mysqld at services.msc

4. reindex your table using REPAIR TABLE tbl_name QUICK;