The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.
I'm using some PHP code from CJ Webdesign for a simple website Search Engine.
I've got everything working but when I try searching for word + another the '+' symbol creates loads of errors (so does *).
The errors are reported in line 38 (preg_match)
You can see the script errors at [URL]http://www.hmmm.ip3.co.uk/search/[/URL]
Search for: freeola test then freeola + test
Thanks in advance - code here: (freeola forum police stop the long fields being posted [URL]http://www.hmmm.ip3.co.uk/cgi-bin/axs/ax.pl?http://www.hmmm.ip3.co.uk/search/code.shtml[/URL]
> What exactly are you searching? Is it a MySQL database, and if so,
> what version of MySQL are you running?
>
> I only ask this since more recent versions of MySQL support boolean
> searching and may be what you are looking for...
No there's no DB, just flat files.
I'm playing with a website for a town planning company who want a simple (and cheap) search option. A visitor needs to be able to stick in a reference number, area or postcode and be presented with a list of results.
This script can provide that, but it may be too simplistic. I would like a site search that resturns the results with thumbnail images attached and with a few more frilly bits. My problem is costs, I'm trying to find free CGI/Perl/PHP/Javascript scritps that are any good.
EDIT:
Managed to add this to the code(not my coding)so the script now searches for partial words (free finds freeola) and automatically applies AND to the keywords:
$weight = 0;
foreach ($keywords as $word){
if(preg_match ("/$word/i", $temp[3]) || preg_match ("/$word/i", $temp[0])) {
$weight++;
}
}
$wordCount = count($keywords);
if($weight == $wordCount) {
$lis++;
$collect[$lis] = $line[$x];
}
> I laughed when I read your last message - I've re-read everything and
> I don't think you actually told me that solution - just said you had
> it ready... If you did I missed it and apologise.
>
Oh, I was referring to what I originally posted about escaping the special characters with \, just in the end didn't see any point in keeping them so just deleted them instead. Going for the cheap fix just wasted time, should have not been so idle and given you the proper solution in the first place.
I only ask this since more recent versions of MySQL support boolean searching and may be what you are looking for...
> Perhaps a better approach was to do what I suggested in the first
> place and try this.
> After
> $keyword = $_POST['keyword'];
> Put
> $keyword = preg_replace('/[^a-zA-Z0-9\s]/', '', $keyword);
Garin - THANKS! All working now...
I laughed when I read your last message - I've re-read everything and I don't think you actually told me that solution - just said you had it ready... If you did I missed it and apologise.
You're right it is a simple search engine script but hopefully it's going to help me out with a site I'm doing. Basically you have to tell the engine what to index (i.e. all the key words) then a user can only find what you want them to - perhaps a reference number or a post code.
Anyway thanks again - good work!
> Of course there's always another problem.
> This works: freeola test
> Now this works: freeola + test
>
> But for some boolean logic visitors they might still try: freeola
> +test which causes the error again.
Ultimately you're hitting the limits of the scipt you're using. Perhaps a better approach was to do what I suggested in the first place and try this.
After
$keyword = $_POST['keyword'];
Put
$keyword = preg_replace('/[^a-zA-Z0-9\s]/', '', $keyword);
It basically filters out anything thats not a letter of the alphabet, a number or a space. The script isnt really set up to support complex searches anyway, so better just filter out anything causes trouble.
> Seems it not my day...really sorry :( I put the ) in the wrong place.
> The line is this:
>
> if (strlen($word)<= 1) { continue; }
>
> I just wrote out another solution for you too until it just struck me
> what I'd done. :P Hopefully not needed now.
I'm all bracketed out!
You're last post works !!! Thanks for that - you certainly know your PHP.
Of course there's always another problem.
This works: freeola test
Now this works: freeola + test
But for some boolean logic visitors they might still try: freeola +test which causes the error again.
EDIT: I've updated the code below with your latest fix.
:( or is that :{
if (strlen($word)<= 1) { continue; }
I just wrote out another solution for you too until it just struck me what I'd done. :P Hopefully not needed now.
> Oops sorry, careless error, the line is missing a closing ) it should
> be
> if (strlen($word<= 1)) { continue; }
Better ! No errors but now the search script doesn't actually find anything - i.e. It's not working... (NB. I'm testing this in a different domain, the links still point to the original problem)
Could your idea for word be used at the top of the code, line 11 which check for the keyword?
if(strlen($_POST['keyword']) <= 3){
Thanks again.
if (strlen($word<= 1)) { continue; }
Tried amended things - but failed so far...