Page 1 of 1

site search

Posted: Fri May 12, 2006 4:13 pm
by alexislalas
hey,

anyone knows where to find or you mind telling me how to build searches for my website.

Posted: Fri May 12, 2006 4:20 pm
by pickle
If you're looking for pre-made scripts, Hotscripts is always the first place to look. If you're looking at making your own - we'll need some more information.

Is your site content in files or in the database?

Posted: Fri May 12, 2006 4:45 pm
by alexislalas
both, but most of it reads from a database.


whats better to find a script or try to do it by myself?

Posted: Fri May 12, 2006 5:41 pm
by pickle
If the content is in the database, check out using LIKE syntax, or setting up a FULLTEXT index - both in MySQL.

Posted: Fri May 12, 2006 5:44 pm
by RobertGonzalez
alexislalas wrote:both, but most of it reads from a database.


whats better to find a script or try to do it by myself?
If you can find one that does what you want it to, why reinvent the wheel. However, if you love to take on projects just because you 'want to see if I can do this with PHP', then by all means, build one on your own. It really depends on you: your preferences, your abilities, your speed, your knowledge, your patience, your eye color. Well, not really your eye color, but all of the other stuff I said.

Posted: Sun May 14, 2006 4:58 am
by aerodromoi
alexislalas wrote:both, but most of it reads from a database.

whats better to find a script or try to do it by myself?
It always depends on what the user input will be like.

Code: Select all

<?php
$query = "SELECT * FROM database WHERE text like '%$needle%' ORDER BY id DESC";
?>
This will give you all entries containing the keyword $needle. However, if the user is going to search for a specific date, you'll probably have to implement a regex function to ensure that the date is properly formatted.

If you want to display the entries according to relevance, you'll have to sort this selection afterwards - perhaps by checking how many times a single entry contains your keyword (substr_count).

Additionally, if the user is likely to search for a misspelled word, you'll probably have to resort to SOUNDEX.

aerodromoi