Re: Slow searches in large database

From: Date: Wed, 15 Oct 2003 14:44:30 +0000
Subject: Re: Slow searches in large database
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-166207@lists.php.net to get a copy of this message
I used a variant of this scheme a time ago and it worked well though I had not reached 2 000 records. I separated the words using strtok(). Manu. PD: How large is the http://www.alenet.com DB; I searched the word 'the' (which is likely to be in every english doc) and it returned only 28 docs. Manu. "Cesar Cordovez" <phpguru@cesamo.com> wrote in message news:3F8C483A.2000300@cesamo.com... > Hi! > > I think that you will need a "keyword" table to speed up this procedure. > The basic idea is to create an index of words in your fields, > therefore you will not use "like" but "=" making things run much, much > faster. > > The steps for doing this are: > > 1. Every time you save a record in the table docs, take all the text > fields in it and separate it into words. You can use explode to do > this. Like for example: $words = explode(" ", $record["fieldone"] . " > " > .$record["fieldtwo"], {etc, etc}); > > 2. save in the keyword table the non repeating words in the array with a > reference to the original document, for example the document id. > > 3. Then, if you want to search for, let say, people you will do: > > select distinct(docid) from keywords where word='people' > > and you will have a list (cursor) with all the documents that have the > word "people". > > Very fast. > > For an example of this, go to http://www.alenet.com and search > for > something. With very little more effort you can add a spelling thingy > (type peeple on the search field) and "porcentajes" for each document. > > I use the exactly the same procedure in a 5000 record database, and the > time it uses to search is about the same that in alenet.com > > Cesar >

« previous php.general (#166207) next »