Re: question regarding content search in array with PHP

"Chen Shapira" <[email protected]> Tue, 18 Dec 2007 20:20:04 -0800
Newsgroups gmane.culture.hackers.israel
Message-ID <[email protected]>
If you don't need persistence for the array, don't use a DB such as
MySQL. DBs write everything to the disk. They are highly optimized to
never ever lose data, so they write to disk a lot. Then they read from
disk. IO operations are slow. So slow that you are probably better off
with the old algorithm.
If you want to go the DB way (and I certainly hope you'll find a
better way), try an in-memory database. As an Oracle DBA, I'll
recommend TimesTen - Oracle's in-memory database, but I'm sure you can
find an open-source solution as well.

Chen


On Dec 18, 2007 9:45 AM, Omer Zak <w1-W6cp89mEpD1mR6Xm/[email protected]> wrote:
>
>
>
>
>
>
> Since you want to use PHP, I assume that you want to do this when
>  processing Web requests.
>  Therefore, I would store the array as a DB (such as MySQL) table.
>
>  The table will have two columns:
>  - Word (indexed, non-unique key)
>  - FullString
>
>  For 'linux', you'll have
>  'linux','linux'
>
>  For 'mac os', you'll have
>  'mac','mac os'
>  'os','mac os'
>
>  Then, when you get the string from the user, split it into words and
>  query for full strings corresponding to each word (using, for example:
>  SELECT FullString FROM StringsTable WHERE Word='os';
>  Of course, you should use the appropriate prepared queries to guard
>  against SQL injection vulnerabilities).
>
>  Now you'll have small number of full strings to be considered, and can
>  apply your complicated and inefficient heuristic algorithm to determine
>  which full string corresponds best to the user's string.
>
>  --- Omer
>
>
>  On Tue, 2007-12-18 at 19:06 +0200, ik wrote:
>  > Hello list,
>  >
>  > I have an array that for the example will look as follows:
>  >
>  > linux, windows, mac os, beos, os/2, freebsd, netbsd, irix ....
>  >
>  > And a string:
>  >
>  > "linux kernel 2.6.24"
>  >
>  > Now I wish to find the closest value of the string in the array ->
> "linux".
>  > But the problem as you can see, is that the string contain more
>  > content then the array value.
>  > I can think on many unefficient ways to find the part of string as an
>  > array value, but I'm looking for an efficient way to do it. specially
>  > if I need to serve a lot of strings on after the other...
>  > The problem is, that I must use PHP (because I can think on an answer
>  > using Perl, that I haven't tested).
>  >
>  > Any ideas how I can do it in an efficient way ?
>
>  --
>  MS-Windows is the Pal-Kal of the PC world.
>  My own blog is at http://www.zak.co.il/tddpirate/
>
>  My opinions, as expressed in this E-mail message, are mine alone.
>  They do not represent the official policy of any organization with which
>  I may be affiliated in any way.
>  WARNING TO SPAMMERS: at http://www.zak.co.il/spamwarning.html
>
>