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 > Escaping an ampersand in match against

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-24-06, 07:55
PaulCookson PaulCookson is offline
Registered User
 
Join Date: Nov 2004
Posts: 2
Unhappy Escaping an ampersand in match against

After trawling the web for a few hours fruitlessly trying top find the answer.

Does anyone know how to do the following

match(product_description) against ('+M&S* ' in boolean mode)

where the data is stored in a database as 'M&S Sofa'.

I do not have the rights to change the source data. I cannot use like as the above is a simple query, and the need for full text indexing is a must.

TIA

Paul
Reply With Quote
  #2 (permalink)  
Old 02-24-06, 19:31
jfulton jfulton is offline
Registered User
 
Join Date: Apr 2005
Location: Baltimore, MD
Posts: 297
Quote:
Does anyone know how to do the following

match(product_description) against ('+M&S* ' in boolean mode)
Quote:
I do not have the rights to change the source data. I cannot use like as the above is a simple query, and the need for full text indexing is a must.
??? What does that mean??? I can only assume you are trying to get product descriptions with the string "M&S" in them?

Code:
SELECT
     *
FROM
     table
WHERE
     product_description LIKE "%M&S%"
If that doesn't help, post back and try to explain simply what you are trying to do.
Reply With Quote
  #3 (permalink)  
Old 02-25-06, 06:18
PaulCookson PaulCookson is offline
Registered User
 
Join Date: Nov 2004
Posts: 2
Quote:
Originally Posted by jfulton
??? What does that mean??? I can only assume you are trying to get product descriptions with the string "M&S" in them?
I am - however I cannot use 'like' - I have to use match against and the ampersand is being interpreted as either a logical AND or as a parameter so I need to escape the ampersand in the against clause. The example I used is extremely simplistic but should give the essence of what I am trying to do.

Escaping a character means replacing it with an escape character so the query processor does not get confused - for example wanting to find the occurence of a directory structure you have to escape the \ by using a \\. However I cannot find how to replace the ampersand in the against clause, as it works different to the like clause. An ampersand in like does not need escaping, however in against it does.

regards Paul
Reply With Quote
  #4 (permalink)  
Old 02-25-06, 13:10
jfulton jfulton is offline
Registered User
 
Join Date: Apr 2005
Location: Baltimore, MD
Posts: 297
Ah sorry about that. You just introduced me to the boolean mode option. I thought you were just trying to find things like 'M&S' and didn't read that you can't use the LIKE operator .

Aaaanyways...I thought you couldn't use match against with such short strings? If you're using longer strings, can't you encapsulate the terms in double quotes to deal with the special characters? As far as I've read it seems like this is the case?

Quote:
the ampersand is being interpreted as either a logical AND or as a parameter
Hmmm...what is your environment? I just tried running some queries with the '&' character and they seemed fine. Without using double quotes too...Maybe it is just the length factor???
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