- Moon Nazis be trippin' in new theatrical trailer for IRON SKY
- Stake Land's Jim Mickle to remake Mexican cannibal flick WE ARE WHAT WE ARE
- Review of the Eric Bilodeau's cyberpunk zombie flick HUNTING GROUNDS
- Maria has a death wish in Marcel Grant’s MONSIEUR FRANCOIS trailer
- PUSHER pushes forward with new poster and first images
- Promo video for steampunk animation UN MONDE TRUQUE (A FAKE WORLD)
- THE END says stay positive in the apocalypse
- DVD Review: Style overshadows heart in spunky comedy SPORK
- J.J. Abrams sells new apocalypse show that sounds like the Emberverse series
- Review of quiescent arthouse gangster film The Road to Nod
- Prepare yourself for the apocalypse
- Female Prisoner No. 701: Sasori
- Re: Japanese zombie movies (2011-12 round-up)
- Re: Life Is Dead
- Balkans war revenge movie - Nicolas Cage?
- PA Film Archive
- i kill
- Re: Life Is Dead
- Monster Killer
- zombie films
- Retro Slave: LOGAN'S RUN series box coming in April
- APOCALYPSE PIZZA VIDEO delivers during the zombie apocalypse!
- Concept art for Enki Bilal's next is PA animation ANIMAL'Z
- Trailer for ZOMBIE MURDER EXPLOSION DIE! All 4 of these in every episode!
- Wandering madly in the remnants of civilization in Greece's HIGUITA (teaser)
- THE HOST director's English language debut SNOW PIERCER adds cast
- Argentina invaded by NEWMEDIA aliens
- THE DIVIDE movie review
- THE RIDER still rides! New teaser reveals stunning final animation style
- EXCLUSIVE: Trailer for RAMPAGE IN HEAVEN sees The Monkey King and mech in a nightmarish dying world
- Sony could back Seth Rogan's THE APOCALYPSE (Jay and Seth vs. The Apocalypse)
- SLAMDANCE 2012: Review of SUNDOWNING
- SLAMDANCE 2012: Review of killer tattoo thriller COMFORTING SKIN
- DVD Review: Style overshadows heart in spunky comedy SPORK
- DVD Review: Daniel Craig loses his mind in mediocre DREAM HOUSE
- SUNDANCE 2012: Review of EXCISION
- SUNDANCE 2012: Review of THE PACT
- SUNDANCE 2012: Review of GRABBERS
- SUNDANCE 2012: Review of SAFETY NOT GUARANTEED
- SUNDANCE 2012: Review of the visionary BEASTS OF THE SOUTHERN WILD
- SUNDANCE 2012: Review of (Radio Shack) ROBOT AND FRANK
- SXSW 2012: Full lineup includes world premiere of CABIN IN THE WOODS
- Stills for Korean android omnibus DOOMSDAY BOOK
- Trailer for muse EDDIE THE SLEEPWALKING CANNIBAL
- New on Blu-ray and DVD: Drive! The Thing! In Time!
- EXCLUSIVE: Trailer for 70s poltergeist flick WHEN THE LIGHTS WENT OUT
- SLAMDANCE 2012: Review of killer tattoo thriller COMFORTING SKIN
- Trailer for ZOMBIE MURDER EXPLOSION DIE! All 4 of these in every episode!
- Trailer for DEAD SHADOWS - Is there some Lovecraft influence?
- Jim Jarmusch making vampire flick ONLY LOVERS LEFT ALIVE
- Will you see this film? Teaser poster for RESIDENT EVIL: RETRIBUTION
- DVD Review: Style overshadows heart in spunky comedy SPORK
- DVD Review: Daniel Craig loses his mind in mediocre DREAM HOUSE
- Zombie bigots abound in DAVE OF THE DEAD
- Douche bags are target practice in GOD BLESS AMERICA trailer
- SUNDANCE 2012: Review of EXCISION
- SUNDANCE 2012: Review of THE PACT
- SUNDANCE 2012: Review of GRABBERS
- EXCLUSIVE: Researching life after death in random data patterns in APOPHENIA (APOFANIA) (trailer)
- Willem Dafoe is THE HUNTER
- SUNDANCE 2012: Review of SAFETY NOT GUARANTEED
Jack In
Latest Comments
Latest Forum Posts
PA News
Latest Reviews
Older News
Film Festivals
Berlin International Film Festival (Berlinale)
Feb 09 - Feb 19
Berlin, Germany
Boston Underground Film Festival
Mar 24 - Mar 31
Boston, Massacheusets
Yubari International Fantastic Film Festival
Feb 23 - Feb 27
Yūbari, Hokkaidō, Japan
Cinequest Film Festival
Feb 28 - Mar 11
San Jose, California
South by Southwest (SXSW)
Mar 09 - Mar 17
Austin, Texas
Staff
Don Neumann aka quietearth
Editor in Chief
Fort Collins/Denver, Colorado
agentorange
Managing Editor
Edmonton, Alberta
Marina Antunes
Assistant Managing Editor
Vancouver, British Columbia
projectcyclops
UK Correspondent
Edinburgh, Scotland
Rick McGrath
Toronto Correspondent
Toronto, Ontario
The Crystal Ferret
France Correspondent
Paris, France
rochefort
Austin Correspondent
Austin, Texas
kilowog
LA Correspondent
Los Angeles, California
Joao Fleck
South American Correspondent
Porto Alegre, Brazil
quietearth [General News 10.19.06]
For those framiliar with mysql, it offers the ability to search by regular expressions (posix style). I needed an advanced way of searching in php, and my backend was mysql, so this was the logical choice. Problem is, how do I build a whole mysql query based on the input? Here's the type of queries I wanted to be able to process:
1. exact word matches
2. sub-string matches (I was doing this with like "%WORD%")
3. exclude via sub-string match
4. exclude via exact word match
We could do more complex searches with the regexp functions, but this is pretty easy for now. Here is the mysql reference on regular expression queries for further reading.
A simple regexp query looks like:
select * from TABLE where ROW regexp '[[:<:]]bla[[:>:]]' and ROW regexp 'foo';This will look for an exact match of the string "bla", meaning not as a sub-string, and then match the sub-string "foo" somewhere.
So first off, items 1 and 4 are exact word matches and I want to be able to do this by surrounding the word with quotes. Let's set our necessary variables and then do a match on quotes:
$newq = $query; # $query is the raw query string
$qlevel = 0;
$curquery = "select * from TABLE where "; # the beginning of the query
$doneg = 0;
preg_match_all("/\"([^\"]*)\"/i", $query, $m);
$c = count($m[0]);
for ($i = 0; $i < $c; $i++) {
$temp = $m[1][$i]; # $temp is whats inside the quotesThen I want to be able to exclude words, and the user should be able to do this by starting the word with a dash (-), and for exact word matches this has to be inside the quotes. The second match is to get rid of the - in front of the query.
if (ereg("^-", $temp)) {
$pc = preg_match("/-([^-]*)/i", $m[1][$i], $dm);
if ($pc) {
$temp = $dm[1];
}
$doneg++;
}Now we will set $temp to the posix compliant exact match, then build this part of the mysql query.
$temp = "[[:<:]]".$temp."[[:>:]]";
if ($qlevel) $curquery .= "and "; # are we nested?
$curquery .= "ROW "; # the mysql row we are searching in
if ($doneg) $curquery .= "not "; # if dash in front, do not
$curquery .= "regexp ".quote_smart($temp)." ";
$qlevel++;
$doneg = 0;
$newq = ereg_replace($m[0][$i], "", $newq);
}The variable $newq has the rest of the search string, minus everything in quotes, so whatever remains are sub-string search items falling under 2 and 3. Now we can go through what is left and basically do the same thing as above.
$s = preg_split("/\s+/", $newq, -1, PREG_SPLIT_NO_EMPTY); #whitespaces
for ($i = 0; $i < count($s); $i++) {
if (ereg("^-", $s[$i])) { # exclude
sscanf($s[$i], "-%s", $temp); # this is poor
$s[$i] = $temp;
$doneg++;
}
if ($qlevel) $curquery .= "and ";
$curquery .= "ROW "; # the mysql row we are searching in
if ($doneg) $curquery .= "not ";
$curquery .= "regexp ".quote_smart($s[$i])." ";
$qlevel++;
$doneg = 0;
}
# use $curquery here in databaseThe variable $curquery now contains our built mysql query. You will notice the use of quote_smart in here, this is a mysql best practice from php.net. It's the only mention of security anywhere in this code. You will need to run your own checking against the input to make sure there are no bad characters, mine only allows alpha-numerics and a few others. DO NOT use this code as is without first fixing that.
Nanda Kumar (4 years ago) Reply
i want to find the exact word in a given string in MySql
quietearth (4 years ago) Reply
use the "posix compliant exact match" code I have listed above.
Anes (4 years ago) Reply
Friends I need an "Advanced Search Query" as we see in Advance search of Bharatmatrimony.com , jeevansathi.com etc...
if u have similar programs send me ,in my id i am really thankful to u.
Anonymous (3 years ago) Reply
A query of -"something" gives us:
select * from TABLE where ROW regexp '[[:<:]]something[[:>:]]' and ROW not regexp '[[:<:]]something[[:>:]]'
Clearly not a desirable result.
Nauman (3 years ago) Reply
http://devzone.zend.com/article/1304-Using-MySQL-Full-text-Searching
this link is for simple searching and fulltext searching
zahid (2 years ago) Reply
such a good topic I will use in my site
http://www.zahipedia.com
Unni Krishnan (2 years ago) Reply
"Friends I need an "Advanced Search Query" as we see in Advance search of Bharatmatrimony.com , jeevansathi.com etc..."
You can check this post, http://blog.webtechies.in/2009/11/29/advanced-search-with-multiple-entries-using-php-mysql/
Hope this may helped someone...
Search Engenie (1 year ago) Reply
Wouldn't it be more frugal to use Regex search in a FULLTEXT search capacity?
Description: http://en.wikipedia.org/wiki/Full_text_search
Query & Table example: http://jeremy.zawodny.com/blog/archives/000576.html



