Skip to main content
Known Participant
March 16, 2011
Question

how do I narrow down mysql search results?

  • March 16, 2011
  • 1 reply
  • 746 views

I want to create a mysql search (MATCH x AGAINST y) where it will only show the results where the complete term of 'x' is found in 'y'.

for example, in database 'x' I have two entries: 1)  'good forum' and 2) 'bad forum'.

When the input of 'y' is "dreamweaver has a good forum", I only want the first entry of x to show ('good forum').

However, using WHERE MATCH x AGAINST y always displays both 1 and 2 of database 'x' because they both have the word 'forum'. How do I arrange the search result code to only get the the entry of 'x' that fully matches that of 'y'?

Thank you,
YWSW

This topic has been closed for replies.

1 reply

Günter_Schenk
Inspiring
March 17, 2011

The MySQL documentation provides very helpful information about Boolean Full-Text Searches :: the IN BOOLEAN MODE modifier lets you specify a "required" word by adding (quote) "a leading plus sign which indicates that this word must be present in each row that is returned"

In your case this example, which specifies both words as required, should work:

SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('+good +forum' IN BOOLEAN MODE);

YWSWAuthor
Known Participant
March 17, 2011

Gunter Shenk, thank you so much for replying.

My problem is that entry 'y' can be many words (as in my example above) or even many paragraphs. It is the full term of 'x' that I want to be matched (in my example above, I only want the first term of 'good forum' to show).

WHERE MATCH (x) AGAINST (y)

is there any boolean code that works to make the full 'x' mandatory?

Thanks,
YWSW

Günter_Schenk
Inspiring
March 17, 2011

is there any boolean code that works to make the full 'x' mandatory?

The documentation also says that "a phrase that is enclosed within double quote (“"”) characters matches only rows that contain the phrase literally, as it was typed" -- what in your case should result in:

SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('"good forum"' IN BOOLEAN MODE);