Mysql query for full text search with an OR condition
I have a dropdown list where it contains only two options And and Or.
These two options when selected will run a query however depending on the
selection. When And is selected, a change in the query will be made. My
query looks like this,
$sql =
"SELECT distinct n.node_id, n.path,
n.title_tag as node_name,
n2.title_tag as tree_name,
MATCH (n.title_tag) AGAINST ('%s') as score
FROM nodes n
join trees t on (n.tree_id=t.tree_id and t.status='A' and
t.workspace_id=%d)
join nodes n2 on (n2.node_id = t.tree_id)
left join node_links nl1 on (n.node_id=nl1.from_node_id and
nl1.to_node_id='%s')
left join node_links nl2 on (n.node_id=nl2.to_node_id and
nl2.from_node_id='%s')
WHERE n.node_id!='%s' and nl1.node_link_id is null and
nl2.node_link_id is null
HAVING score > 0
ORDER BY score DESC";
Notice the MATCH AGAINST part, that is where I would like to add my And
and Or conditions. How would I do it if when selecting the And condition
the query will match the node_name using the AND logic and when selecting
the Or condition the query will match the node_name using the OR logic.
Any help will do. Thanks.
No comments:
Post a Comment