- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsHi.
I'm currently building a search routine for a clip art website in PERL using MySQL. I have extracted all title words, and all clip tags associated with all clips into a table. I've extracted a selection and the table format and attached.
I'd like to build an SQL query which will interrogate this one table but the number of querries involved is making it extremely difficult and complex. Too complex for me to do efficently and correctly.
In Perl I'm stripping all the useless words and extracting the core search words like so.
$search_value =~ s/'/\\'/g;
use Lingua::StopWords qw( getStopWords );
my $stopwords = getStopWords('en');
@words = split(/ /, $search_value);
What I need to achieve is to search the table based on the following criteria and in the following order.
As an example let us use the Search Phrase (Green Globe)>
I need the SQL to
1. Search the table for the phrase "Green Globe" (case insensitive) from field search_word where title_word = 'Y' and Product_publish = 'Y'
2. Search the table for the phrase "Green Globe" (case insensitive) from field_search_word where title_word = 'N' and Product_publish = 'Y'
3. Search the table for the word "Green" (case insensitive) from field_search and Product_publish = 'Y'
4. Search the table for the word "Globe" (case insensitive) from field_search and Product_publish = 'Y'
5. As product_id is a many to one ... this field needs to be grouped.
I will also need to use some form of a join to link to the actual product table to get the full details, but I think I can do this.
As the results need to be split over various pages, I need to get a count of the number of returned records and work out the number of page results. Again I believe I can do this based on the final SQL.
If somebody can get me started on the SQL it would be appreciated. What would be nice would be if the SQL statement could also display a result if the one of the keywords/phrases (search_word) was for example greenish globe.
Mysql Version is : 5.0.81-community
Architecture is : i686
Apache version 2.0.63
Perl: 5.8.8
Many thanks for reading this.
Cormac
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: virmaiorPosted on 2009-10-25 at 18:37:49ID: 25659322
5. As product_id is a many to one ... this field needs to be grouped.
[6. would green globe be the entire field? I am going to assume no.]
1. Search the table for the phrase "Green Globe" (case insensitive) from field search_word where title_word = 'Y' and Product_publish = 'Y'
SELECT product_id FROM WHERE title_word = 'Y' AND search_word LIKE '%Green Globe%' AND product_publish = 'Y'
GROUP BY product_id
2. Search the table for the phrase "Green Globe" (case insensitive) from field_search_word where title_word = 'N' and Product_publish = 'Y'
SELECT product_id FROM WHERE title_word = 'N' AND search_word LIKE '%Green Globe%' AND product_publish = 'Y'
GROUP BY product_id
3. Search the table for the word "Green" (case insensitive) from field_search and Product_publish = 'Y'
SELECT product_id FROM WHERE search_word LIKE '%Green%' AND product_publish = 'Y'
GROUP BY product_id
4. Search the table for the word "Globe" (case insensitive) from field_search and Product_publish = 'Y'
SELECT product_id FROM WHERE search_word LIKE '%Globe%' AND product_publish = 'Y'
GROUP BY product_id
...
for your other question, you can use RLIKE to scan the table for something like "greenish"
the results will be faster if each row is just one word and use you = 'Green Globe' vs the LIKE syntax i am using above.