Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

how do I narrow down mysql search results?

Community Beginner ,
Mar 16, 2011 Mar 16, 2011

Copy link to clipboard

Copied

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

TOPICS
Server side applications

Views

632
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 16, 2011 Mar 16, 2011

Copy link to clipboard

Copied

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);

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 16, 2011 Mar 16, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 16, 2011 Mar 16, 2011

Copy link to clipboard

Copied

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);

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 16, 2011 Mar 16, 2011

Copy link to clipboard

Copied

Gunter Schenk, it is not the AGAINST (y) that I need to be exact, it is the first part of the phrase, the MATCH (x).

I need something like:

               WHERE MATCH ("x" IN BOOLEAN MODE) AGAINST (y)

[which, by the way, does not work]

I cannnot put "..." in AGAINST (y) as 'y' is a very long string of words (as in my example in my question above)- only some of which match up to 'x'.

It is the 'MATCH (x)' that I need to be specified.

Does this make sense?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 16, 2011 Mar 16, 2011

Copy link to clipboard

Copied

LATEST

Does this make sense?

Honestly said, not at all -- maybe I´m just temporarily a little dense

I need something like:

               WHERE MATCH ("x" IN BOOLEAN MODE) AGAINST (y)

[which, by the way, does not work]

Apart from the fact that a literal "x" will certainly not work because you´ll have to specify the table name(s) here, "does not work" can have many reasons, like the fact that fulltext searches can only work with MySQL tables of the type MyISAM, and those +/- operators seem to be supported with MySQL 5 and higher

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines