I have a bit of a problem here...
The following code returns matches that the users searched for - nicely sorted by relevance, & super fast: -
SELECT
-
*
-
FROM
-
search_table
-
WHERE
-
MATCH (Title_Column) AGAINST (
-
'Whatever the user searched for'
-
)
-
LIMIT 25;
The problem shows up when i do the following to narrow the results by category: -
SELECT
-
*
-
FROM
-
search_table
-
WHERE
-
MATCH (Title_Column) AGAINST (
-
'Whatever the user searched for'
-
)
-
AND (
-
MATCH (Category_Column) AGAINST ('Music' IN BOOLEAN MODE)
-
)
-
LIMIT 25;
The results are by no means sorted, & they are not related to what the user searched for even though they put quite a few different words in the query. I also added In Boolen MODE to the second part that filters by the category because I'm not sure if it will try to order by category instead.
I am by no means a database guru, or even a noob... I'm 10 feet below that.
I have tried the following, but it completely defeats the benefits of having an index. Although it does the job, it's performance is poor compared to the above examples: - SELECT
-
*, MATCH (Title_Column) AGAINST (
-
'Michael Jackson' IN Boolean MODE
-
) AS Relevance
-
FROM
-
search_table
-
WHERE
-
(
-
MATCH (Title_Column) AGAINST (
-
'Michael Jackson' IN Boolean MODE
-
)
-
AND MATCH (Category_Column) AGAINST ('Music' IN Boolean MODE)
-
)
-
ORDER BY
-
Relevance DESC
-
LIMIT 25;
I was 3 seconds away from deciding to re-learn some other SQL language because this is as far as i can get - speed being the requirement, & it's not usable.
Here are the requirements: - SPEED
- User selects 1 of 23 categories. Category 1 is "ALL CATEGORIES". A few others are a mix of categories - for example: "Music" on the search page category list is actually a combination of "Music-MP3", "Music-FLACK", "Music-WMA", & "Music-Video"... all separate categories in the Category_Column's column that's assigned to each relevant record in the table.
- Search Title_Column for user's search term, & filer it by the categories selected.
- Results MUST be sorted by relevance, AND return results according the the user's search term.
- Did I mention Speed?
Ok... here's the CREATE statement: - delimiter $$
-
-
CREATE TABLE `search_table` (
-
`Category_Column` tinytext NOT NULL,
-
`s_Size` varchar(12) NOT NULL,
-
`Title_Column` tinytext NOT NULL,
-
`User_TITLE_Column` tinytext NOT NULL,
-
`s_PostDate` varchar(40) NOT NULL,
-
`s_Poster` tinytext NOT NULL,
-
`s_ItemHASH` varchar(40) NOT NULL,
-
`s_ItemName` tinytext NOT NULL,
-
`s_ItemNumber` bigint(9) NOT NULL,
-
`s_DownloadsCount` bigint(9) NOT NULL,
-
`s_URL` tinytext NOT NULL,
-
`tid` bigint(9) NOT NULL auto_increment,
-
`s_CatImage` varchar(30) NOT NULL,
-
`s_UnixTimeStamp` bigint(10) NOT NULL,
-
`s_ID` varchar(40) NOT NULL,
-
PRIMARY KEY (`tid`),
-
FULLTEXT KEY `iCategory_Column` (`Category_Column`),
-
FULLTEXT KEY `iTitle_Column` (`Title_Column`),
-
FULLTEXT KEY `iUserTITLE_Column` (`User_TITLE_Column`),
-
FULLTEXT KEY `i_Poster` (`s_Poster`)
-
) ENGINE=MyISAM AUTO_INCREMENT=737319 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC$$
FULLTEXT indexes are of B-Tree type
I would like to see examples of the proper syntax that allows the user to search, & return relevant results just as the fisrt (FAST) example I gave above does, but with the category filter.
I would like it to be as fast as the first search example, or even the second (that returns non-relevant results), but it MUST continue to sort the relevant results just as it does without the filter.
Any examples would be awesomely appreciated. MySQL 5.0.XX
The table has just under 1,000,000 records... 879,366 records to be exact.
Columns are all less than 255 characters.
Thanks
2 2537 Luuk 1,047
Recognized Expert Top Contributor
First of all, when you do a 'SELECT * FROM table' there is NO way of knowing in which order your data is returned. If you want it to be returned in a specific order you have to use the 'ORDER BY'-clause.
Your 'Category_Column' is wrongly defined. If you say 'Category 1 is "ALL CATEGORIES". ', i will ask you, why you did not define that field as INT(2) ??
How will you show 'ALL CATEGORIES', if there are records with the category 'Music', which clearly is a diffent category than 'ALL CATEGORIES' ?
Selecting an index on a INT(2) field is quicker than selecting on a FULL TEXT index.
If you want to combine categories in your final result you can always do someting like:
SELECT * from table where Category IN (1,3,5)
to select the category one, three and five.
The 'ORDER BY' function drastically slows the response time, but I agree.
The 'Category_Column' is different from the site's category dropdown box. If the user chooses 'All Categories' from the site's dropdown box, then I don't filter... The resulting query is plain (and fast) like the following: -
SELECT
-
*
-
FROM
-
search_table
-
WHERE
-
MATCH (Title_Column) AGAINST (
-
'Whatever the user searched for'
-
)
-
LIMIT 25;
-
I also agree on Int(2), but for now, we're still building, & am trying to avoid confusion, & possibilities for mistakes, so I leave them visually understandable. When it's all done, & acceptable for the production server, I'll change it. I need every possible second shaved from the response times.
This will be accessed from public/private software, & sites (many), & if the response times of each query is slow, then that will lead to a site lockup, crash, or lag/freeze.
Thanks for your response :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Josh |
last post by:
I've got a search running from PHP with the following SQL:
$results = mysql_query("SELECT DISTINCT ForumThread.id as threadId,
ForumThread.Subject as threadTopic,
ForumThread.ID as threadId,
ForumPost.Message as postMessage,
ForumCategory.ID as categoryId,
ForumCategory.Name as categoryName,
MATCH (ForumThread.Subject) AGAINST ('" ....
|
by: vze29xhy |
last post by:
I have searched the existing responses in this forum and others and
could not find a solution.
I have a database on MySQL server Version "4.0.13". My table structure
is as follows
TABLE1:MusicCD
This table has three columns - UPC, Title, ExtendedTitle
TABLE2: Artist
This table has three columns - ArtistID, ArtistName, ArtistOtherName
|
by: Aaron Whiffin |
last post by:
Hi, I've set up the following table in MySQL 3.23.58 and all seemed to be
working fine:
CREATE TABLE advert (
id INT NOT NULL AUTO_INCREMENT,
userid INT NOT NULL,
make VARCHAR(25) NOT NULL,
model VARCHAR(15) NOT NULL,
year VARCHAR(4) NOT NULL,
price FLOAT(7,2) NOT NULL,
|
by: leegold |
last post by:
Show full header Is there any way to make relevance when using boolean
mode more useful? If not, are there plans in the Fulltext development
"todo" for making it useful?
I'm thinking of just counting the keyword occurences in records with a
PHP script somehow and using that to order the records somehow. Or doing
a non boolean fulltext...
|
by: phillip.s.powell |
last post by:
SELECT id, student_first_name, student_last_name, major, minor ,
MATCH(major, minor) AGAINST ('"mechanical engineering"')
AS score
FROM students
WHERE MATCH(major, minor) AGAINST ('"mechanical engineering"' IN
BOOLEAN MODE)
GROUP BY id, student_first_name, student_last_name, major, minor, score
ORDER BY score DESC
This query in MySQL...
| |
by: Malte |
last post by:
Hello there,
We got a problem atm with our 20k database. Everytime we search for sth. with double quotes it takes much more longer than without.
Here is what we did:
mysql> SELECT COUNT(*) FROM `Pages` WHERE MATCH (`Text`) AGAINST ('"term"' IN BOOLEAN MODE);
+----------+
| COUNT(*) |
+----------+
|
by: jmdaviault |
last post by:
I want to do the equivalent of
SELECT id from TABLE WHERE text='text'
only fast solution I found is:
SELECT id,text from TABLE WHERE MATCH(text) AGAINST('value' IN BOOLEAN
MODE) HAVING text='value'
|
by: Mad Scientist Jr |
last post by:
When searching through code in Vis. Interdev 6, when in the Find
dialog, it listed the results in the results pane below. The cursor
didn't change position to the next found item until you clicked on a
line in the results.
This is actually a nice feature that I haven't seen before -
all the matches show up at once in a list,
with a column...
|
by: lawrence k |
last post by:
Wierd. Go to this page:
http://www.ihanuman.com/search.php
and search for "yoga"
This query gets run:
SELECT * FROM albums WHERE MATCH(name,description) AGAINST ('yoga')
ORDER BY id DESC
|
by: SamudraSri |
last post by:
hi everybody
i am working wamp since 4+ years. i have a requirement where in i need to search for the record that matches some keywords using fulltext
search.
tables:
temp1(id,keywords,searchin,matchwords);
temp2(id,keywords,title)
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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: 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
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| | |