If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > all combinations in multi-word searches what to do

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-28-10, 05:08
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
all combinations in multi-word searches what to do

to use search whole site feature using database, to search keywords yyy zzz and keywords zzz yyy NOT differently but use all combinations in multi-word searches what to do?
// but zzz yyy may get result, but the inverse in order words yyy zzz gives nothing.
currently use:
SELECT Products.*, Categories.* FROM Products INNER JOIN Categories ON Categories.Category_ID = Products.Category_ID WHERE Category LIKE '%#searchKeyword#%' OR Product_ID LIKE '%#searchKeyword#%' OR Product_Name LIKE '%#searchKeyword#%' OR Product_Description LIKE '%#searchKeyword#%'
Reply With Quote
  #2 (permalink)  
Old 10-28-10, 05:44
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by lse123 View Post
currently use:
looks okay to me

what's wrong with it?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-28-10, 07:50
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
If I search for "akamas flower" is ok return results, this order of words exist in database table.

well, if search "flower akamas" returns NOTHING, ...Well?

what to do to return the same as first keyword?
Reply With Quote
  #4 (permalink)  
Old 10-28-10, 07:56
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
aha, okay, now i understand

what you have to do is break up your submitted search string into whole words
Code:
WHERE Category            LIKE '%flower%' 
   OR Product_ID          LIKE '%flower%'
   OR Product_Name        LIKE '%flower%' 
   OR Product_Description LIKE '%flower%' 
   OR Category            LIKE '%akamas%' 
   OR Product_ID          LIKE '%akamas%'
   OR Product_Name        LIKE '%akamas%' 
   OR Product_Description LIKE '%akamas%'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 10-28-10, 09:37
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
how understand the number of words submitted?
Reply With Quote
  #6 (permalink)  
Old 10-28-10, 09:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by lse123 View Post
how understand the number of words submitted?
count the spaces

number of words = number of spaces + 1

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 10-28-10, 09:53
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
how implement the ORs in query. then to correct number, and after run?
Reply With Quote
  #8 (permalink)  
Old 10-28-10, 09:56
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by lse123 View Post
how implement the ORs in query. then to correct number, and after run?
what application language are you using to produce a query that contains #searchKeyword#?

looks like it could be coldfusion

in any case, all of what you are asking is done with the application language
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 10-28-10, 10:15
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
yes is CFML... I can not thing a way make it can you tell any hint?
Reply With Quote
  #10 (permalink)  
Old 10-28-10, 10:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
here's a hint -- split the submitted search string apart using the space as list delimiter, and process the words using CFLOOP
Code:
<!--- build the SELECT statement --->
<CFOUTPUT>
SELECT Products.*
     , Categories.* 
  FROM Products 
INNER 
  JOIN Categories 
    ON Categories.Category_ID = Products.Category_ID 
 WHERE 0=1
</CFOUTPUT>

<!--- add the search conditions ---> 
<CFLOOP INDEX="word" LIST="#searchstring#" DELIMITER=" "> 
<CFOUTPUT>
   OR Category            LIKE '%#word#%' 
   OR Product_ID          LIKE '%#word#%'
   OR Product_Name        LIKE '%#word#%' 
   OR Product_Description LIKE '%#word#%' 
</CFOUTPUT>
</CFLOOP>
please note: as a rule, we do not provide application language solutions in the mysql forum
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On