I try to implement a search where 3 fields in the database (artist, title, publisher) need to be targed. I.o.w when I type 1, 2 or 3 phrases in the search field it should return results that where found in 1 of the 3 or in 2 or all 3 fields. For example when in the search Muse and Warner it should return all albums from Muse made on the Warner Bros label, but for some reason doesn’t the database return those results. It is working with the first 2 fields (artist and title) but not with the third. This is my products table:
Fix your query, get it working correctly and THEN and only THEN put it into your front end application.
Again, unless you are searching a text type field with large amounts of data you aren’t gaining anything by using a full text index search for the type of search you are doing.
Full text would be used when you are searching for a bunch of words contained in a paragraph, or a chapter of a book for instance.
Not saying that is the only time you would use it, just I think it is overkill for what you would be searching for in your application.
I don’t see why you’d need to implement a full text search here. why aren’t you merely searching those fields? you only have one value in each column for each row right?
WHERE artist=‘Muse’ and publisher=‘Warner’ would do what you are looking for wouldn’t it?
WHERE artist=‘Muse’ and publisher=‘Warner’ would do what you are looking for wouldn’t it?
But how do I get that coming from a form field?
<cfquery name="getProducts" datasource="#application.dsn#">
SELECT p.product_id, p.artist, p.title, p.publisher, p.category_id, c.category
FROM products p
LEFT JOIN categories c ON p.category_id = c.category_id
WHERE 0 = 0
<cfif structKeyExists( Url, 'category' ) And Url.category Neq 0>>
AND p.category_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#Val( Url.category )#" />
</cfif>
<cfif isDefined( "Url.txtSearch" ) AND Url.txtSearch NEQ "">
AND ( artist LIKE '%#Url.txtSearch#%'
OR title LIKE '%#Url.txtSearch#%'
OR MATCH (artist, title, publisher) AGAINST ('Url.txtSearch'in boolean mode))
</cfif>
</cfquery>
Here it is. It’s about the bottom part. category field is another field in the form and works great.