Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Old 01-01-2008, 06:26 PM   #1 (permalink)
Contributing Member
 
Join Date: 06-11-07
Posts: 238
iTrader: 0 / 0%
Latest Blog:
None

Capo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the rough
Purpose of indexing? MySQL Help

I'm making a search engine for my website, and I'm not very familiar with MySQL Optimization.

First question is what does indexing do? Is there anything that's bad about it? (aka Why don't i just index all of my columns).

Second question: Is there anything I can do in PHP code that will optimize my results, is there anything that is bad to do?

Right now my code:

* Splits up the query into words that are 2 characters are more and removes stopwords (me, you, what, etc..)
* for each word: mysql queries a SELECT * FROM table where description LIKE '%$word%'
* stores all results in an array with key='title' value++ (score for the word)
* for each word: mysql queries a SELECT * FROM table where title LIKE '%$word%'
* stores all results in an array with key='title' value += 5 (score for the word)
* mysql queries SELECT * FROM table WHERE title = 'searchQuery'
* stores all results in an array with key='title' value += 10
* foreach results as result it displays the title and the score
Capo64 is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-03-2008, 04:36 AM   #2 (permalink)
v7n Mentor
 
Join Date: 07-24-06
Posts: 691
iTrader: 1 / 100%
Latest Blog:
None

nasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nice
Quote:
Originally Posted by Capo64 View Post
First question is what does indexing do? Is there anything that's bad about it? (aka Why don't i just index all of my columns).
Index is your table sorted by key order (the fields you've chosen) ... kinda If you create too many indexes insert and edit operations will became slow (Your table will be resorted many times on every insert). Also it's a waste disk space.

Quote:
Originally Posted by Capo64 View Post

Second question: Is there anything I can do in PHP code that will optimize my results, is there anything that is bad to do?

Right now my code:

* Splits up the query into words that are 2 characters are more and removes stopwords (me, you, what, etc..)
* for each word: mysql queries a SELECT * FROM table where description LIKE '%$word%'
* stores all results in an array with key='title' value++ (score for the word)
* for each word: mysql queries a SELECT * FROM table where title LIKE '%$word%'
* stores all results in an array with key='title' value += 5 (score for the word)
* mysql queries SELECT * FROM table WHERE title = 'searchQuery'
* stores all results in an array with key='title' value += 10
* foreach results as result it displays the title and the score
You might find this helpful: http://dev.mysql.com/doc/refman/5.1/...xt-search.html

Last edited by nasty.web; 01-03-2008 at 05:01 AM..
nasty.web is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-04-2008, 09:11 PM   #3 (permalink)
Contributing Member
 
Join Date: 06-11-07
Posts: 238
iTrader: 0 / 0%
Latest Blog:
None

Capo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the rough
Thanks for the help, I'm trying to figure out this MATCH() AGAINST() I can't seem to get it to work the right way.

I have it working OK, but it's not doing well if the person searches for a keyword with a hyphen, and the relevancy is kinda messed up.
Capo64 is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-07-2008, 07:09 AM   #4 (permalink)
Contributing Member
 
Join Date: 06-11-07
Posts: 238
iTrader: 0 / 0%
Latest Blog:
None

Capo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the rough
Are there illegal characters that need to be replaced in search queries?
Capo64 is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-07-2008, 09:17 AM   #5 (permalink)
v7n Mentor
 
Join Date: 07-24-06
Posts: 691
iTrader: 1 / 100%
Latest Blog:
None

nasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nice
This might be helpful:
http://dev.mysql.com/doc/refman/5.0/...ne-tuning.html
http://dev.mysql.com/doc/refman/5.0/...stopwords.html
nasty.web is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-09-2008, 06:38 PM   #6 (permalink)
Contributing Member
 
Join Date: 06-11-07
Posts: 238
iTrader: 0 / 0%
Latest Blog:
None

Capo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the rough
Thanks a lot so far nasty,

Can anyone tell me why this isn't a valid query? This stuff is killing me..
Code:
$query = "SELECT title, description, id, MATCH(title,description) AGAINST ( REPLACE('$clean', '-', ' ') ) AS Relevance FROM items WHERE MATCH ( REPLACE(title, '-', ' ') , REPLACE(description, '-', ' ') ) AGAINST ( REPLACE('$clean', '-', ' ') IN BOOLEAN MODE ) ORDER BY Relevance DESC";
I know for a fact it's something with the REPLACE(title.... and the REPLACE(description...
because it works without the replace. I don't see what's wrong with it though..
It's not that I don't have an index because it doesn't give me that error. It gives me the error that it's invalid syntax.
Capo64 is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-10-2008, 12:46 AM   #7 (permalink)
v7n Mentor
 
Join Date: 07-24-06
Posts: 691
iTrader: 1 / 100%
Latest Blog:
None

nasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nice
MATCH(column, ... ) requires a column name as its parameter not an expression.
My quick suggestion would be to use two columns in your table for the same field: one for indexing, second for actual data.
nasty.web is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-10-2008, 03:56 PM   #8 (permalink)
Contributing Member
 
Join Date: 06-11-07
Posts: 238
iTrader: 0 / 0%
Latest Blog:
None

Capo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the rough
Wouldn't that be a little strenuous? My descriptions are pretty long..

Is there a different solution that I con do on the site?

It would be extremely slow to get the titles and descriptions of all my items in an array, then go through the array to replace them and redo the search, right?
Capo64 is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-10-2008, 04:05 PM   #9 (permalink)
v7n Mentor
 
Join Date: 07-24-06
Posts: 691
iTrader: 1 / 100%
Latest Blog:
None

nasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nice
Quote:
Originally Posted by Capo64 View Post
Wouldn't that be a little strenuous? My descriptions are pretty long..

Is there a different solution that I con do on the site?

It would be extremely slow to get the titles and descriptions of all my items in an array, then go through the array to replace them and redo the search, right?
why do you think you need an array? I suggest you keeping two columns for the same field in a table. Eg.: title (this one for actual data) and title_idx (this one for indexing).
nasty.web is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-10-2008, 05:52 PM   #10 (permalink)
Contributing Member
 
Join Date: 06-11-07
Posts: 238
iTrader: 0 / 0%
Latest Blog:
None

Capo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the rough
yeah, but what about the descriptions, I'm searching through the description too
Capo64 is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-11-2008, 12:32 AM   #11 (permalink)
v7n Mentor
 
Join Date: 07-24-06
Posts: 691
iTrader: 1 / 100%
Latest Blog:
None

nasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nice
Quote:
Originally Posted by Capo64 View Post
yeah, but what about the descriptions, I'm searching through the description too
Add second column for descriptions as well (I still can't see where you need an array). I believe that disk space is much cheaper than your work, so having additional columns wont hurt much (and it's the easiest and the fastest solution).
nasty.web is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-11-2008, 06:08 PM   #12 (permalink)
Contributing Member
 
Join Date: 06-11-07
Posts: 238
iTrader: 0 / 0%
Latest Blog:
None

Capo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the rough
Alright thanks,

So I would just add a column like title_idx and description_idx, then make a php page that removes hyphens and stop words from each description & title and adds them to the new columns?
Capo64 is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-11-2008, 06:20 PM   #13 (permalink)
v7n Mentor
 
Join Date: 07-24-06
Posts: 691
iTrader: 1 / 100%
Latest Blog:
None

nasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nice
Yes,
you can update your whole table with something like
Code:
UPDATE table SET title_idx = REPLACE(title,'-',''), description_idx = REPLACE(description,'-','')
And then on each insert or update you should do exactly the same (just add WHERE clause).
nasty.web is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-11-2008, 06:22 PM   #14 (permalink)
Contributing Member
 
Join Date: 06-11-07
Posts: 238
iTrader: 0 / 0%
Latest Blog:
None

Capo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the roughCapo64 is a jewel in the rough
Ok, Thank you so much for all your help nasty.
Capo64 is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Purpose of web directories JessicaWDC Tech Support Forum 23 11-03-2008 10:08 PM
Creating purpose and intensity in life coberst Forum Lobby 7 11-05-2007 12:33 PM
Purpose of Article Writing IslaScotts Marketing Forum 17 12-07-2006 09:10 AM
What is the purpose of this? GeXus SEO Forum 8 07-02-2004 03:30 AM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 09:59 PM.
© Copyright 2008 V7 Inc
Powered by vBulletin
Copyright © 2000-2009 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.