473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

unordered word search

Hello,

I've built a search engine that queries a MySQL database. However,
if I enter "foo bar", the engine will search for that phrase exactly,
and will not find "bar foo" nor "foo something bar". How do you
separate words so that the engine finds them individually? I'm thinking
something like

$tokenized = strtok($query, " ")
mysql_query(" SELECT ... FROM ...
while(...){ WHERE ...}
")

but I just can't figure it out. Any help is much appreciated. Many
thanks in advance.

Diego

Dec 28 '05 #1
2 1611
co****@ironcito.com wrote:
Hello,

I've built a search engine that queries a MySQL database. However,
if I enter "foo bar", the engine will search for that phrase exactly,
and will not find "bar foo" nor "foo something bar". How do you
separate words so that the engine finds them individually? I'm thinking
something like

$tokenized = strtok($query, " ")
mysql_query(" SELECT ... FROM ...
while(...){ WHERE ...}
")

but I just can't figure it out. Any help is much appreciated. Many
thanks in advance.

Diego


Hi,

Suppose you have a table with firstname and lastname and etc. etc., and you
want to search firstname.
(I wrote an example in clear steps, so you see what happens. You can code it
a lot more dense if you prefer that.)
$searchwords = "foo bar whatever etc";
$ARRsearch = explode(" ",$searchwords);

$SQL = "SELECT firstname, lastname, ..... FROM tblYouKnow WHERE (";

$SQL_wordsearch = array();

foreach($ARRsearch as $oneWord){
$SQL_wordsearch[] = "(firstname LIKE '%".$oneWord."%')";
}

// add the pieces to SQL, use " OR " as 'glue':
$SQL .= implode(" OR ",$SQL_wordsearch);
$SQL .= ");";

echo $SQL;

// Now execute the SQL the way you are used to.

Good luck.

Regards,
Erwin Moller

PS, I am using the LIKE with %. I am unsure if that is supported like that
in mysql because I never use mysql. Maybe you need different syntax, but
that is just SQL syntax, you'll figure that out.
Dec 28 '05 #2
iuz
co****@ironcito.com wrote:
Hello,

I've built a search engine that queries a MySQL database. However,
if I enter "foo bar", the engine will search for that phrase exactly,
and will not find "bar foo" nor "foo something bar". How do you
separate words so that the engine finds them individually? I'm thinking
something like

$tokenized = strtok($query, " ")
mysql_query(" SELECT ... FROM ...
while(...){ WHERE ...}
")

but I just can't figure it out. Any help is much appreciated. Many
thanks in advance.

Diego


if you wnat to search these words in this order you can simply do something
like this..
$string = "word0 word1 word2 word3 word4 ";
$words = '%' . preg_replace('/ +/', '%', trim($string)) . '%';
$words = mysql_escape_string($words);
echo "SELECT * FROM table WHERE nn LIKE '$words'";

--
www.iuz-lab.info
Dec 28 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matthew Robinson | last post by:
i wrote a search page for my site (searching through a mysql database) but when i type in more than one word (eg "item three") in the search field it gets passed to the page as a single word...
2
by: Andrew Cranwell | last post by:
Hi, Please redirect me if I am in the wrong group for this question... this is my first post to this group, so I hope it is clear! I am working on an automation project in VB.NET and have to...
0
by: Zeljko | last post by:
VB.net 2005 express - Office Word 2003 Office 11 library =references I need to make from VB.net search in Word for these words: "tree", "bus", "car"...(complete list contains ca. 50 words) when...
3
by: tdemartino | last post by:
I've been searching for days, using MS help and I can't find the answer on my own. I have this code in my Access Form: If Not IsNull(Me.txtFilterDescriptionMatName) Then...
1
by: vmoreau | last post by:
I have a text and I need to find a Word that are not enclosed in paranthesis. Can it be done with a regex? Is someone could help me? I am not familar with regex... Example looking for WORD:...
3
by: User | last post by:
Hi, Is it possible to transform Ordered/Unordered list into navigation dropdown menus? Is this effect achieved by CSS? or via Javascript? PLease advise Thanks.
2
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
11
by: grantstech | last post by:
I have successfully created a program that searches for a word in multiple files but now I need to be able to search by more than one word. I have add code from a previous discussion to my original...
2
by: asc4john | last post by:
When including an unordered list in an unordered list: Should it be included as a "list" item as in: <ul><liitem</ li><ul.... </ul<liitem</li</ul> or included in the LI element as in:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.