[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

Match Against Mysql statement.

Doing a search of a "forum" type setup..
Two tables
forum_posts, forum_replies  will be searching feilds ( title , content ) in both tables.

i need to search both tables get a score back combine the scores then select from the forum_posts the in the order of the scores with the matching.

forum_posts.post_id = forum_replies.parent_id

i do not need anything from the forum_replies as far as data

this HAS to be 1 mysql query.


the below does not work correctly but its something ive been trying to work on.
 SELECT posts. * ,
MATCH (
posts.subject, posts.content
)
AGAINST (
'test* search*'
IN BOOLEAN
MODE
) AS score_posts
FROM `forum_posts` AS posts, replies. * ,
MATCH (
replies.subject, replies.content
)
AGAINST (
'test* search*'
IN BOOLEAN
MODE
) AS score_replies
FROM `forum_replies` AS replies
WHERE MATCH (
replies.subject, replies.content
)
AGAINST (
'test* search*'
IN BOOLEAN
MODE
)
ORDER BY total_score DESC
LIMIT 0 , 30
0
remlab
Asked:
remlab
  • 2
1 Solution
 
Brian BushSolutions ArchitectCommented:
Try something like this:

SELECT
  posts.id,
  replies.parent_id,
  MATCH(
    posts.subject,
    posts.content
  ) AGAINST(
    'test* search*'
    IN BOOLEAN MODE
  ) +
  MATCH(
    replies.subject,
    replies.content
  ) AGAINST(
    'test* search*'
    IN BOOLEAN MODE
  ) AS score
FROM
  `forum_posts`   AS posts,
  `forum_replies` AS replies
WHERE
  posts.id = replies.parent_id
ORDER BY
  score DESC
LIMIT 0, 30

I think that's going to give you what you want.
--brian
0
 
remlabAuthor Commented:
Has not been answered yet. was waiting for more user comments.
0
 
Brian BushSolutions ArchitectCommented:
Do you think you could respond to my post?
Did you try the query? Did it not work? What results did it give
versus what results were you expecting?

You have to give us something to work with here.
--brian
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now