473,394 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

MySQL Fulltext query question

JT
I have a MySQL fulltext search form in place and I now want to filter the
results further. I've added a few multiple select boxes on my form
(ResourceType and Topic), and I'm able to build and execute the SQL
queries properly.

The problem is that when I add the criteria for "ResourceTyoe" and
"Topic", it seems to take precedence over the fulltext matching. In The
two query examples below I'm searching on a single keyword "safety".
Query1 will return 1 result (correct), while Query2 will return 5
(incorrect).

I'm new to fulltext searching and I don't think I have the SQL syntax
correct. Where should I be placing the additional criteria in this query?

-JT

Query1:

SELECT ResourceID, ResourceName, ResourceType, ResourceSubType, Topic,
MATCH (ResourceDescription) AGAINST ('safety')
AS Score
FROM tblmainresourcestable
WHERE MATCH (ResourceDescription) AGAINST ('safety')
ORDER BY Score DESC

Query2:
SELECT ResourceID, ResourceName, ResourceType, ResourceSubType, Topic,
MATCH (ResourceDescription) AGAINST ('safety')
AS Score
FROM tblmainresourcestable
WHERE MATCH (ResourceDescription) AGAINST ('safety')
AND ResourceType = 1 OR ResourceType = 2
AND Topic = 3 OR Topic = 4
ORDER BY Score DESC
Jul 17 '05 #1
3 2434
JT wrote:
WHERE MATCH (ResourceDescription) AGAINST ('safety')
AND ResourceType = 1 OR ResourceType = 2
AND Topic = 3 OR Topic = 4


If I'm not mistaken, AND and OR have the same priority, so the condition
is evaluated left to right. Try grouping the ORs together with
parentheses like this:

WHERE MATCH (ResourceDescription) AGAINST ('safety')
AND (ResourceType = 1 OR ResourceType = 2)
AND (Topic = 3 OR Topic = 4)

Jochen

Jul 17 '05 #2
JT
Jochen Buennagel <za*********@buennagel.com> wrote in news:bri1lp$7lg$01
$1@news.t-online.com:
JT wrote:
WHERE MATCH (ResourceDescription) AGAINST ('safety')
AND ResourceType = 1 OR ResourceType = 2
AND Topic = 3 OR Topic = 4
If I'm not mistaken, AND and OR have the same priority, so the

condition is evaluated left to right. Try grouping the ORs together with
parentheses like this:

WHERE MATCH (ResourceDescription) AGAINST ('safety')
AND (ResourceType = 1 OR ResourceType = 2)
AND (Topic = 3 OR Topic = 4)

Jochen


Hey that worked perfectly. I haven't found many examples of fulltext
queries besides the basic ones in the MySQL manual. I've been afraid to
start going off on the wrong tangent, I've already made some huge
mistakes in getting it to work this far ;)

Thanks a million!
Jul 17 '05 #3
JT <jo***@adroitdesigners.com> wrote in message
news:<Xn*************************@68.1.17.6>...

I have a MySQL fulltext search form in place and I now want to filter the
results further. I've added a few multiple select boxes on my form
(ResourceType and Topic), and I'm able to build and execute the SQL
queries properly.

The problem is that when I add the criteria for "ResourceTyoe" and
"Topic", it seems to take precedence over the fulltext matching. In The
two query examples below I'm searching on a single keyword "safety".
Query1 will return 1 result (correct), while Query2 will return 5
(incorrect).


Use parentheses to set precendence of logical operators:

SELECT
ResourceID, ResourceName, ResourceType, ResourceSubType, Topic,
MATCH (ResourceDescription) AGAINST ('safety') AS Score
FROM tblmainresourcestable
WHERE
MATCH (ResourceDescription) AGAINST ('safety')
AND (ResourceType = 1 OR ResourceType = 2)
AND (Topic = 3 OR Topic = 4)
ORDER BY Score DESC;

Cheers,
NC
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jasper Bryant-Greene | last post by:
I have a database of movie titles, with about 78,000 records, and a database of related people (directors, writers, actors/actresses etc.) with about 141,000 records. I display a random movie out...
2
by: Phil Powell | last post by:
Relevancy scores are normally defined by a MySQL query on a table that has a fulltext index. The rules for relevancy scoring will exclude certain words due to their being too short (minimum...
0
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default...
1
by: Hal Halloway | last post by:
How do I change a MYSQL Fulltext relevance value to: 0 to 100%. I'm just thinking about usability for the "average" user - maybe they would like to know...and would not understand the raw value. ...
2
by: Maziar Aflatoun | last post by:
Hi, I have the following table CREATE TABLE `fulltext_sample` ( `copy` text, FULLTEXT KEY `copy` (`copy`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO `fulltext_sample` VALUES...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Henry Hank | last post by:
Environment: I'm setting up a database server on a Dell Poweredge 2650, dual 1.8GHZ pentium with 1GB of memory and RAID5 drives. I've installed RedHat 9, and updated the kernel to 2.4.20-19.9smp....
0
by: Phil Powell | last post by:
Retracing my problem leads me to believe I never successfully created fulltext indexes for MySQL 3.23.58 MyISAM tables. I went to the MySQL manual and was able - or so I thought - to create them,...
8
by: Fred | last post by:
Hello, Our website is currently developed in ASP/Mysql 4. The dedicated servers on which it is currently hosted arrive at saturation. Here is their configuration: - 1 server PIV 2,8Ghz 1GB...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.