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 "ResourceTy oe" 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 (ResourceDescri ption) AGAINST ('safety')
AS Score
FROM tblmainresource stable
WHERE MATCH (ResourceDescri ption) AGAINST ('safety')
ORDER BY Score DESC
Query2:
SELECT ResourceID, ResourceName, ResourceType, ResourceSubType , Topic,
MATCH (ResourceDescri ption) AGAINST ('safety')
AS Score
FROM tblmainresource stable
WHERE MATCH (ResourceDescri ption) AGAINST ('safety')
AND ResourceType = 1 OR ResourceType = 2
AND Topic = 3 OR Topic = 4
ORDER BY Score DESC 3 2437
JT wrote: WHERE MATCH (ResourceDescri ption) 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 (ResourceDescri ption) AGAINST ('safety')
AND (ResourceType = 1 OR ResourceType = 2)
AND (Topic = 3 OR Topic = 4)
Jochen
Jochen Buennagel <za*********@bu ennagel.com> wrote in news:bri1lp$7lg $01
$1@news.t-online.com: JT wrote: WHERE MATCH (ResourceDescri ption) 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 (ResourceDescri ption) 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!
JT <jo***@adroitde signers.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 "ResourceTy oe" 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 (ResourceDescri ption) AGAINST ('safety') AS Score
FROM tblmainresource stable
WHERE
MATCH (ResourceDescri ption) AGAINST ('safety')
AND (ResourceType = 1 OR ResourceType = 2)
AND (Topic = 3 OR Topic = 4)
ORDER BY Score DESC;
Cheers,
NC This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 of this
database on each hit to my website's homepage.
This worked fine when I had only a couple thousand movies, but now that
the DB has grown,...
|
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 default is 4
letters).
This is the Fed. Everything is a TLA (three-letter acronym).
Therefore, since I'm building a PORTABLE web application,...
|
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 setting whereby the
minimum amount of characters is 4 for a search. Being that we're
government and full of TLA (three-letter acronyms), that is not...
|
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.
Any snips, ideas or links appreciated.
Thanks
|
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 ('This is a test to see how mysql
| |
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 form
for a number of platforms from our download pages at
http://www.mysql.com/downloads/ and mirror sites.
|
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. I've installed the RPM binary distribution of MySQL
4.0.14 right from the MySQL website. The only thing I have done is disable
InnoDb in my my.cnf...
|
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, however, my
fulltext search queries fail in 3.23.58 but the exact queries (with
same data) work perfectly in 4.0.10.
--...
|
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 RAM with IIS 5 on Windows 2000
- 1 server Bi-xeon 3Ghz, 512 MB with MySQL 4 on Windows 2003
The website makes approximately 10.000.000 of pages seen...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |