Dusty
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,SubTyp e,City,Pro pertyName, Highlights ,Remarks,A gent,CoAge nt,Address Number,Add ressStreet ,Zipcode);
ALTER TABLE fagents ADD FULLTEXT(AgentFName,AgentL Name,Agent Email);
ALTER TABLE fcoagents ADD FULLTEXT(AgentFName,AgentL Name,Agent Email);
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,"Keyw ord") and len(trim(form.Keyword))>
AND
MATCH(listings.Class,listi ngs.Type,l istings.Su bType,list ings.City, listings.P ropertyNam e,listings .Highlight s,listings .Remarks,l istings.Ag ent,listin gs.Address Number,lis tings.Addr essStreet, listings.Z ipcode) AGAINST('#form.Keyword#' IN BOOLEAN MODE)
OR
MATCH(AgentFName,AgentLNam e,AgentEma il) AGAINST('#form.Keyword#' IN BOOLEAN MODE)
OR
MATCH(CoAgentFName,CoAgent LName,CoAg entEmail) 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.
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,SubTyp
ALTER TABLE fagents ADD FULLTEXT(AgentFName,AgentL
ALTER TABLE fcoagents ADD FULLTEXT(AgentFName,AgentL
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 City IN
(
<cfqueryparam value="#form.City#"
cfsqltype="cf_sql_varchar"
list="true"
separator=",">
)
</cfif>
<!---Search by keywords--->
<cfif StructKeyExists(form,"Keyw
AND
MATCH(listings.Class,listi
OR
MATCH(AgentFName,AgentLNam
OR
MATCH(CoAgentFName,CoAgent
</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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Adding parenthesis did indeed solve the problem!