473,513 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mix of Match() Against(), & Match() Against(in boolean mode) = Non-Sorted results

DTeCH
23 New Member
I have a bit of a problem here...


The following code returns matches that the users searched for - nicely sorted by relevance, & super fast:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.     *
  3. FROM
  4.     search_table
  5. WHERE
  6.     MATCH (Title_Column) AGAINST (
  7.         'Whatever the user searched for'
  8.     )
  9. LIMIT 25;


The problem shows up when i do the following to narrow the results by category:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.     *
  3. FROM
  4.     search_table
  5. WHERE
  6.     MATCH (Title_Column) AGAINST (
  7.         'Whatever the user searched for'
  8.     )
  9. AND (
  10.     MATCH (Category_Column) AGAINST ('Music' IN BOOLEAN MODE)
  11. )
  12. 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:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.     *, MATCH (Title_Column) AGAINST (
  3.         'Michael Jackson' IN Boolean MODE
  4.     ) AS Relevance
  5. FROM
  6.     search_table
  7. WHERE
  8.     (
  9.         MATCH (Title_Column) AGAINST (
  10.             'Michael Jackson' IN Boolean MODE
  11.         )
  12.         AND MATCH (Category_Column) AGAINST ('Music' IN Boolean MODE)
  13.     )
  14. ORDER BY
  15.     Relevance DESC
  16. 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:
  1. SPEED
  2. 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.
  3. Search Title_Column for user's search term, & filer it by the categories selected.
  4. Results MUST be sorted by relevance, AND return results according the the user's search term.
  5. Did I mention Speed?



Ok... here's the CREATE statement:
Expand|Select|Wrap|Line Numbers
  1. delimiter $$
  2.  
  3. CREATE TABLE `search_table` (
  4.   `Category_Column` tinytext NOT NULL,
  5.   `s_Size` varchar(12) NOT NULL,
  6.   `Title_Column` tinytext NOT NULL,
  7.   `User_TITLE_Column` tinytext NOT NULL,
  8.   `s_PostDate` varchar(40) NOT NULL,
  9.   `s_Poster` tinytext NOT NULL,
  10.   `s_ItemHASH` varchar(40) NOT NULL,
  11.   `s_ItemName` tinytext NOT NULL,
  12.   `s_ItemNumber` bigint(9) NOT NULL,
  13.   `s_DownloadsCount` bigint(9) NOT NULL,
  14.   `s_URL` tinytext NOT NULL,
  15.   `tid` bigint(9) NOT NULL auto_increment,
  16.   `s_CatImage` varchar(30) NOT NULL,
  17.   `s_UnixTimeStamp` bigint(10) NOT NULL,
  18.   `s_ID` varchar(40) NOT NULL,
  19.   PRIMARY KEY  (`tid`),
  20.   FULLTEXT KEY `iCategory_Column` (`Category_Column`),  
  21.   FULLTEXT KEY `iTitle_Column` (`Title_Column`),   
  22.   FULLTEXT KEY `iUserTITLE_Column` (`User_TITLE_Column`),   
  23.   FULLTEXT KEY `i_Poster` (`s_Poster`)   
  24. ) 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
Jun 27 '12 #1
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.
Jul 1 '12 #2
DTeCH
23 New Member
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:

Expand|Select|Wrap|Line Numbers
  1.     SELECT
  2.         *
  3.     FROM
  4.         search_table
  5.     WHERE
  6.         MATCH (Title_Column) AGAINST (
  7.             'Whatever the user searched for'
  8.         )
  9.     LIMIT 25;
  10.  


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 :)
Jul 15 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1786
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 ('" ....
8
2996
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
9
2588
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,
1
2437
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...
0
1247
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...
0
1520
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(*) | +----------+
4
11212
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'
0
1328
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...
6
3517
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
1
1912
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)
0
7177
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...
0
7394
Oralloy
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. ...
0
7559
jinu1996
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...
0
7542
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 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...
0
5701
agi2029
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...
1
5100
isladogs
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...
0
4756
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...
0
1611
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
0
470
bsmnconsultancy
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...

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.