Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Comments for: clay19990421

Message # 1014499:
Date: 12/03/02 13:27
By: /zureash
Subject: RE: database searching

Just a quick hint- you should be using preg_replace as it is faster than ereg_replace. Also, you don't need to repeat the replace code over and over, you can set up an array of patterns and replacements, for example:

$pattern=array( '\n', '(', ')' );
$replace=array( '' );
$filtered=preg_replace( $pattern, $replace, $blobtext );

Also, if you have a clear pattern that you are looking for (such as alpha characters) an easier way would just be to use a regular expression to catch any non-alpha characters, for example:

$filtered=preg_replace( '/W/', '', $blobtext );

As a side note, TEXT columns in MySQL are NOT case-sensative, while BLOB columns are case-sensative. This difference explains why the code snippet in the article is NOT case-sensitive.

Finally, this is a pretty heavy app (resource-wise) to be running on your server. I am not convinced that this is the best approach to indexing and searching a db-powered site. However, if you are going to use this, make sure you create an index of your key word table in your database. An index will greatly speed up the matching in the database. (See the MySQL documentation if you don't know how to do this.)

Also, you should NOT run the indexing portion of this script (the part that creates the keyword table) too frequently. This is exactly the kind of utility that cron jobs are made for. Your best bet is to set a cron job to run this utility once a day (preferably during the night, or during periods of lowest traffic on your site.)

I used to work for a major search engine company, so I can tell you that this is NOT how indexes like Google are created. Major search engines use compiled indexes (and no, the correct word IS NOT indices!) Search terms are ranked according to a complex formula, and frequent queries are cached (which is not a bad idea for any site.) I know Adam said this in the article, but I just wanted to restate it for those of you who appear to be confused in the postings.

Previous Message | Next Message


Comments:
search using multiple search fieldsMatthew Daniels11/27/05 19:58
RE: display records 1-10 then next/prev.saleem05/12/05 09:01
Searching with mysql+php.siti 12/06/04 22:54
RE: Searching mysql...Barend11/01/04 06:37
Another Good, Free ScriptDaniel Hendricks01/28/03 02:07
RE: database searching/zureash12/03/02 13:27
DB Search across different headdingsRichmond Chua09/27/02 19:13
Identifier?Jason Nelms09/11/02 12:00
RE: Building a search engine(spider)Beldwin Cabrera08/26/02 01:55
RE: display records 1-10 then next/prev.Eviljello08/23/02 11:53
READERS: Ignore this articleVan07/15/02 00:39
RE: search engineMoses Bony06/27/02 18:26
RE: Building a search engine(spider)Vince06/22/02 09:02
implementing search engineMarge06/13/02 01:58
RE: Searching mysql...Alessandro05/29/02 17:56
Searching mysql...Vic Jolin05/27/02 03:46
RE: Fixed Scriptdmitry05/07/02 04:10
RE: Weird SQLBill Barron05/03/02 13:24
starting a search engineShunte Carter05/03/02 12:14
Weird SQLDemon 32105/01/02 11:59
using links indexingYuriC04/29/02 16:22
problem in search ... help meDeV^AwaY04/24/02 19:42
why blobs?bob_whale04/18/02 22:22
search engineayman04/05/02 16:59
RE: Boolean searchesAqil02/28/02 02:51
Build a search engine in MySQL muthu02/18/02 00:24
RE: Fixed ScriptPaddy02/13/02 10:17
Fixed ScriptJose01/21/02 18:17
The search query in this article is bogus.Jose01/21/02 17:51
Simple Question I am sureKacey A. Murphy01/17/02 12:19
RE: Close Match Search on DBPavan01/14/02 09:29
mySQL 3.23.23 Has All This Built InFigment01/08/02 12:15
RE: Can someone look at this?Mark Hall12/10/01 19:57
Can someone look at this?TVance12/05/01 15:38
PLEASE SOMEONE HELP!!!...TVance12/05/01 15:15
RE: And when the created table is dropped?Danny Biggs12/02/01 23:59
Code and other requirements for search enginerubina12/01/01 01:52
where is the solution?rubina12/01/01 01:41
Building a search engine(spider)Aditya11/26/01 13:47
Building a search engine(spider)Aditya11/25/01 13:39
RE: creating a search engine which can do elantra11/20/01 02:29
Pretty Cool Search engine, but..Luis Erique11/19/01 11:05
knowpostPamela Weston10/20/01 20:28
Simple but Powerful ImprovementBefara10/04/01 00:19
RE: search engineCameron Cox09/03/01 06:27
Problem with resultOwen08/31/01 00:02
Using multiple keywordsTantalus08/16/01 19:35
boolean (and/or) search on php/mysql datatbasdread08/16/01 02:03
query on page 2 of this articleJesse07/27/01 00:47
And when the created table is dropped?Alkis Doulgeris07/12/01 06:06
Another TweakDan07/10/01 09:58
search engineAnitaamal07/04/01 22:13
RE: full text search engineDanny Tuppeny06/28/01 04:26
RE: search engineDmitry06/13/01 05:42
creating a search engine which can do shzshi06/12/01 04:09
Normalization (and / or why?)Rutger Lubbers06/06/01 11:26
RE: Close Match Search on DBJimmy Brake05/25/01 14:56
RE: Close Match Search on DBThomas Hurst05/20/01 13:44
Close Match Search on DBShekhar05/13/01 23:24
full text search engineRobin Ren05/05/01 18:09
RE: search engineShanx05/03/01 14:38
search enginerobert04/24/01 18:04
Extra points for words close togetherDarian Stibbe04/05/01 09:54
RE: That's great -- but here's a better versionAndy Jeffries03/26/01 11:14
deja vunadia03/20/01 11:23
RE: Efficiency...Simone Capra03/08/01 15:02
more php/mysql search scriptsJohn Scrivener02/24/01 06:32
this query has a subselectScott Mebberson02/11/01 16:34
RE: Anyone care to put this article in English?Mangala02/08/01 18:43
RE: Need help getting started with this srch-engSummerblind02/08/01 06:27
str_replace instead of ereg_replace??Allen02/04/01 02:04
RE: Efficiency...Szii02/03/01 16:04
Search engines for those without SQLOliver White02/01/01 10:43
RE: That's great -- but here's a better versionJohn G.01/25/01 07:20
RE: That's great -- but here's a better versionMarc01/21/01 19:48
RE: Boolean searchesJaco Schieke01/14/01 19:48
Efficiency...Phil01/13/01 15:25
RE: display records 1-10 then next/prev.aris01/10/01 20:32
erm, PHP?James01/08/01 13:11
Anyone care to put this article in English?Mr. Needs Help01/05/01 17:40
RE: display records 1-10 then next/prev.Cesar Hernandez01/05/01 15:07
RE: Error on line 4 of codeJamie01/04/01 10:29
display records 1-10 then next/prev.Chris B01/04/01 08:47
RE: Boolean searchescolin01/02/01 11:10
RE: database searchingAdam Gossage12/28/00 21:13
That's great -- but here's a better versionJohn G12/25/00 22:12
Error on line 4 of codeChris Thompson12/22/00 20:55
database searchingCiaran12/18/00 11:31
FANTASTICbharat11/30/00 07:37
Need help getting started with this srch-engTejas11/28/00 22:34
RE: case sensitive or case insensitive?Jeff Harris11/27/00 22:45
RE: How do I reindex?Mike10/07/00 07:43
How do I reindex?Aaron Nikula09/03/00 15:59
Speed of this search engineOlli Kay08/21/00 13:54
Boolean searchesBen Phillips08/08/00 06:00
case sensitive or case insensitive?Wincent Colaiuta08/06/00 05:29
RE: Stupid question about data tablesTim Patterson08/02/00 15:26
Stupid question about data tablesCymen Vig07/18/00 15:25
search engineAmita Jalla07/01/00 05:26
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.