Fw: Google Style Search Results

Fw: Google Style Search Results

am 10.12.2005 04:51:41 von Julien Bonastre

------=_NextPart_000_0012_01C5FD90.D97B46A0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

----- Original Message -----=20
From: Ming Xiao=20
To: Julien Bonastre=20
Sent: Friday, December 09, 2005 7:04 PM
Subject: Re: [PHP-DB] Google Style Search Results


hello everybody
who knows ajax , I want to make a website use ajax technolgy.
thanks,everybody!


=20
2005/12/9, Julien Bonastre :=20
Sure,

Firstly, thank you for the credit, that was only my second mid-scale =
project, coded ground up in Textpad 4 ;-)=20

enough patting my own back, onto business..

=
http://aries.the-spectrum.org/webdev/wawd/forums/search.php? q=3Dsufficien=
t%2Blarge&st=3Dpost&sb%5B%5D=3D*&maxres=3D25&ob=3Ddatetime&o t=3DDESC=20



Notice some changes??


You've just sparked a interest in me to revise and rewrite some of the =
code for that page this lovely 33 degree celcius summer Friday afternoon =
here in Australia.. :-)


Previously, it was only really just pumping out the first sentence or =
so of text from the matched query..


Now though it is actually going through each query word and matching a =
set number of words surrounding it [in this case I've made it five] and =
throwing that out in the extraction field... with each of these said =
matches being seperated by a ellipsis [...]=20


All I did was conjure up a regular expression that basically just =
matches words :-) haha ironically..


Here it is:

$extract_result=3D"";
preg_match_all("/((?:[\w]+ ?){0,5})[\w =
\.\,\-\;]((?:".join("|",$q_arr)."))([\w]*)[\w \.\,\-\;]((?:[\w]+ =
?){0,5})/i",$row["content"],$ext_matches,PREG_SET_ORDER);=20
foreach($ext_matches as $ext_arr) {
$extract_result .=3D $ext_arr[1]." =
".$ext_arr[2]."".$ext_arr[3]." ".$ext_arr[4]." ... ";
}


Are you familiar with regex?=20

It really shouldn't be hard to implement a similiar concept with =
whatever your current search system does.. My system as can be seen from =
this above code actually breaks up the query string sent via the form on =
search page into each word.. therefore you have an array [$q_arr] that =
looks like Array( "sufficient", "large") ..=20

Hence in that regex above i just did a "join" using the "|" pipe =
symbol.. I use this so when it joins all the words together they come =
out as: word1|word2|word3

meaning regex will match 5 or less words before and after any of the =
given words. the | symbol means bitwise "OR", for example:=20

run(ning|ner)

will match running or runner but not runs

Sorry if you already know some of this I am just trying to make sure I =
explain myself fully as I am unawares as to your experience level.

Anyway, so yes I simply use the handy preg_match_all function which =
will run this regex statement upon the entire $row["content"] which in =
my case is just the entire content of the post which it found to match =
words in.. and from that it simply matches these certain given keywords =
and their surrounding word/s..=20

I then use a foreach structure to simply iterate over each of the =
matches and create the lovely string you see before you, it does this =
simply by reprinting the original matched string, creating a =
bold effect on the given search word and adding an ellipsis at the end =
for simple athestic reasons..=20



If you want any more examples or clarification please feel free to =
ask..



Enjoy ;-)



---oOo--- Allowing users to execute CGI scripts in any directory =
should only be considered if: ... a.. You have no users, and nobody ever =
visits your server. ... Extracted Quote: Security Tips - Apache HTTP =
Server ---oOo--- ------oOo---------------oOo------ Julien Bonastre =
[The_RadiX] The-Spectrum Network CEO ABN: 64 235 749 494 =
julien@the-spectrum.org www.the-spectrum.org =
------oOo---------------oOo------
----- Original Message -----
From: < dpgirago@mdanderson.org>
To: "Julien Bonastre"
Sent: Friday, December 09, 2005 12:42 AM
Subject: Re: [PHP-DB] Google Style Search Results=20


>
> Great site, Julien! Probably more involved than we need for our =
project,
> but very, very impressive. I really like the CSS styling in =
particular. If
> you could tell me how you are displaying the content within the =
"extract"=20
> field, that would be very helpful.
>
> Regards,
>
> David
>
>
> David P. Giragosian, Psy.D.
> Database and Software Developer
> 713-798-7898
>
>
> |---------+------------------------------------------>
> | | |
> | | |
> | | "Julien Bonastre"|=20
> | | |
> | | |
> | | |=20
> | | |
> | | 12/08/2005 05:23 AM|
> | | Please respond to "Julien|
> | | Bonastre"|=20
> | | |
> | | |
> |---------+------------------------------------------>
> =
>----------------------------------------------------------- -------------=
-----------------------------------------|=20
> | =
|
> | =
|=20
> | =
|
> |To: =
|=20
> | =
|
> |cc: =
|=20
> | =
|
> | =
|=20
> | =
|
> | =
|=20
> | =
|
> |Subject: =
|=20
> | Re: [PHP-DB] Google Style Search Results =
|
> | =
|=20
> =
>----------------------------------------------------------- -------------=
-----------------------------------------|
>
>
>
>
> Try a quick visit to:
> =
http://aries.the-spectrum.org/webdev/wawd/forums/search.php? q=3Ddone&st=3D=
post&sb%5B%5D
> =3D*&maxres=3D25&ob=3Ddatetime&ot=3DDESC
>
>
> If you are interested in that, I can tell you more..=20
>
> ----- Original Message -----
> From:
> To:
> Sent: Thursday, December 08, 2005 7:15 AM
> Subject: Re: [PHP-DB] Google Style Search Results
>
>
>>
>> Thanks Joseph and Philip. I think that will work very well.
>>
>>>> why not use substr?=20
>>>> $preview =3D substr($string, 0, 50) .'...';
>>>>
>>>> it will probably cut off in the middle of a word, but you can use
> strpos
>>>> and
>>>> check to see if the char is a space to get to the point you want. =

>>>>
>>>> It's possible that the keywords wouldn't be in the first X =
numbers of
>>>> characters.
>>
>>> Then use strstr() to find the first occurence of the first keyword =
and=20
>>> then use substr with an initial offset...
>>
>>
>> David
>>
>> --
>> PHP Database Mailing List (http://www.php.net/)=20
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
>
>
>
>


------=_NextPart_000_0012_01C5FD90.D97B46A0--