Link to home
Start Free TrialLog in
Avatar of Dusty
DustyFlag for United States of America

asked on

MySql FULLTEXT / Coldfusion search question.

MySql 5.7 / Coldfusion 11

I have a real estate property search form with multiple fields for instance  City, Price, Acres, etc... and a Keyword input that needs to be able to further filter these results.   Example: I need to be able to find only properties listed in a certain city by a certain agent the agents name goes in the "keyword" input.

I have 3 tables in my database that I need to query and do a fulltext search on; "listings",  "fagents", "fcoagents"  
so I added fulltext index for each.

ALTER TABLE listings ADD FULLTEXT(Class,Type,SubType,City,PropertyName,Highlights,Remarks,Agent,CoAgent,AddressNumber,AddressStreet,Zipcode);

ALTER TABLE fagents ADD FULLTEXT(AgentFName,AgentLName,AgentEmail);

ALTER TABLE fcoagents ADD FULLTEXT(AgentFName,AgentLName,AgentEmail);


SELECT * FROM listings
LEFT JOIN fagents ON listings.Agent = fagents.Agent
LEFT JOIN fcoagents ON listings.CoAgent = fcoagents.CoAgent

WHERE (Status = "Active" OR Status = "Pending")

AND

<!---Search by City--->
<cfif StructKeyExists(form,"City") and listLen(trim(form.City), ",")>
 AND City IN
        (
             <cfqueryparam value="#form.City#"
                   cfsqltype="cf_sql_varchar"
                   list="true"
                   separator=",">
     )
</cfif>

<!---Search by keywords--->
<cfif StructKeyExists(form,"Keyword") and len(trim(form.Keyword))>
AND
MATCH(listings.Class,listings.Type,listings.SubType,listings.City,listings.PropertyName,listings.Highlights,listings.Remarks,listings.Agent,listings.AddressNumber,listings.AddressStreet,listings.Zipcode) AGAINST('#form.Keyword#' IN BOOLEAN MODE)
OR
MATCH(AgentFName,AgentLName,AgentEmail) AGAINST('#form.Keyword#' IN BOOLEAN MODE)
OR
MATCH(CoAgentFName,CoAgentLName,CoAgentEmail) AGAINST('#form.Keyword#' IN BOOLEAN MODE)
</cfif>

Group BY listings.ListID

--------------------------------------------------

My question is how can I match against all 3 indexes without matching against them individually as that gives incorrect results if I search an Agent name in the keyword input because then the query just finds all listings in the selected city OR agent.
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dusty

ASKER

Thanks, _agx_ !
Adding parenthesis did indeed solve the problem!