Re: Incorporating a PHP/MySQL based search

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, December 8, 2007 4:36 pm, Steve Finkelstein wrote:
> One area I lack experience in is writting a solution to index/search
> on a
> site. Would anyone be kind enough and point me in the right direction
> as far
> as any books which discuss some simple solutions or articles/blogs on
> the
> web? Clearly I'm not looking for anything as complex as Google's
> engine, ;-)
> but would love just to be able to understand/incorporate a decent
> level of
> search capabilities.

If it's a publicly-available site, you would probably be best served
by integrating with Google's search engine and their custom search
forms for your site.

Another pre-packaged option is ht://dig (a.k.a. htdig)

If you want to roll your own for "fun" it kind of depends on your
schema and what is on your site in terms of DB versus static versus...

As suggested, MySQL's fulltext index and match operator can be very
useful for large text field[s].

You can also provide search in very specific fields with an "advanced"
search form.

A crude/simple way to do this is to just assign "point values" to
everything and to add up points for various fields.

An example for a "library" site might go like this:

$query = "select 0 ";
if (isset($_REQUEST['author'])){
  $query .= " + 10 * author like '%$_REQUEST[author]%' ";
}
if (isset($_REQUEST['title'])){
  $query .= " + 10 * author like '%$_REQUEST[title]%' ";
}
if (isset($_REQUEST['synopsis'])){
  $query .= " + 5 * synopsis like '%$_REQUEST[synopsi]%' ";
}
$query .= " as score ";
$query .= " from books ";
$query .= "having score > 0 ";
$query .= " order by score desc ";
$query .= " limit 10 ";
$query .= " offset $_REQUEST[offset] ";

Of course, you'd have to validate/cleanse the $_REQUEST data instead
of just slamming it directly into a query!

But the idea is to give "points" to various things that match whatever
the user inputs, and add them up as a sort of "score" for each book.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux