[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

10/20/2009 at 07:30AM PDT, ID: 24827008 | Points: 500
[x]
Attachment Details

Mysql Search Query Help

Asked by littlegreenman in MySQL Server, Perl Programming Language, SQL Query Syntax

Tags: MySQL, Select Statement, cross join, Perl, Linux, search engine, search routine, mysql search, search statement, SQL statement

Hi.
  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
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Table Structure is as follows:
 
CREATE TABLE IF NOT EXISTS `SearchWords` (
  `search_id` int(11) NOT NULL auto_increment,
  `product_id` varchar(10) character set utf8 default NULL,
  `search_word` varchar(255) character set utf8 default NULL,
  `category_id` varchar(10) NOT NULL default '',
  `product_publish` enum('Y','N') NOT NULL default 'N',
  `type` enum('2D','3D') NOT NULL default '3D',
  `title_word` enum('Y','N') NOT NULL default 'N',
  UNIQUE KEY `search_id` (`search_id`),
  KEY `search_word` (`search_word`),
  KEY `category_id` (`category_id`),
  KEY `product_id` (`product_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7936792 ;
Attachments:
 
SQL File with example records
 
 
Keywords: Mysql Search Query Help
 
Loading Advertisement...
 
[+][-]10/20/09 07:36 AM, ID: 25614593

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/20/09 07:37 AM, ID: 25614602

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/20/09 07:39 AM, ID: 25614625

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/20/09 08:25 AM, ID: 25615135

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/20/09 08:30 AM, ID: 25615184

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/20/09 08:35 AM, ID: 25615225

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/20/09 08:46 AM, ID: 25615347

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/20/09 10:11 AM, ID: 25616254

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625