Forum Moderators: coopster

Message Too Old, No Replies

wildcards in mysql WHERE clauses

on left side, possible?

         

amznVibe

7:31 am on Nov 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a mysql table of all strings... is it possible to do queries using wildcards on left side? Can't find any documentation on it, and I don't seem to be able to do it, but I am fairly novice with mysql

SELECT * FROM $sql_tbl WHERE * LIKE $search
or
SELECT * FROM $sql_tbl WHERE *=$search

any "legal" way to accomplish this without specifying all the fields?

lorax

3:00 pm on Nov 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That ain't gonna happen because MySQL needs to know what table.field's contents you're trying to compare your var against. If you don't know the what field to use then I think you'd better look further up the stream to determine a better way to get what you need. What is it you're trying to do?

coopster

4:04 pm on Nov 27, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You may want to have a look at MySQL Full-text Search [mysql.com].

amznVibe

5:27 pm on Nov 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



lorax I am trying to make an interface into a library database that has very poor and inconsistant data entry... I have to span many fields to make sure a person searching gets what they want...

In the end, I have just stacked about 25 OR statements... doesn't seem to hurt speed too much...

coopster thanks for your idea, it seems to be a start for my quest for some starting code for a php google-like parser for a search form (meaning quotes and boolean logic) My mind is short-circuiting with the number of possibilities I have to go through to code something really functional.

killroy

6:15 pm on Nov 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Personally I didnT' find the MySQL fulltext search all that usefull. I ended up codign my own logic, and I'm VERY happy. It seems really scalable (could easily search millions of full text documents), Uses stemming and even is even flexible as to regards misspellings.

Tricks it think in a different way... you donT' search documents, you search words in a word table, then you have a link table tellign you which documents match with the words you found... The wrod table grows much slower then the document table (for large systems). Especially if stemmed. I use the double metaphone algorithm to increase reach, but use a ranking system to maintain relevancy and accuracy.

There is a lot of really interesting research available on CiteSeer on large scale document retrieval.

In the end it depends if you're geeky to blow a week on developign a powerfull search system for a potentially small application, jsut cos it's really interesting ;)

I know I am.

SN

brotherhood of LAN

6:18 pm on Nov 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It is interesting, and those docs can sometimes take more than a week of your interest i bet ;o)

I use the same method as killroy, a "word hits" table, if you want ot get fancy you can store the word position, or have more granularity and split by sentence etc.

I ran a script to loop through an INSERT statement until there were around 5,000,000 word hits, searching it was no prob at all.

lorax

4:03 am on Nov 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



ah, understood. I suppose cleaning up the database would be too time consuming?