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
remlabAsked:
Who is Participating?
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.