Forums / General / Search, advancedsearch and custom SQL scripts

Search, advancedsearch and custom SQL scripts

Author Message

Aleksander Lech

Friday 09 September 2005 6:18:42 am

Hi,
I'm trying to achieve something like this:
Searching works as ususal but <form action> on the search page points to my extension where (based on searched term) another search is made on custom DB tables. Both search results are presented on results page.
And its work to this moment.

Advanced search form on results page doesn't have input fields filled, dropdown lists are empty, and if I try to search by "phrase search" I don't have any results from ezPublish, just from custom search. If I search using 'typical search' field I got both results, but dropdown list are stil empty.

I think that maybe my way is not exactly good.
Here's some code"

extension's php script (overview.php)

<?php
include_once( 'kernel/common/template.php' );
include_once( 'kernel/content/search.php' );

function arr_clean(&$val) {
   $val=chop(trim($val));
}

if(isset($_REQUEST["SearchText"]) && $_REQUEST["SearchText"]!=""){
	
	$searchArr=$_REQUEST["SearchText"];
	$searchArr=explode(" ",$searchArr);
	array_walk($searchArr,'arr_clean');

};

if(isset($_REQUEST["PhraseSearchText"]) && $_REQUEST["PhraseSearchText"]!=""){
	$searchArr=$_REQUEST["PhraseSearchText"];
}


$tpl =& templateInit();

    include_once( 'lib/ezdb/classes/ezpostgresqldb.php' );  
	$db =& eZDB::instance();
    $wynik =& $db->arrayQuery( 'SELECT prac.*, inst.*, dz.* FROM pracownik prac, instytut inst, dzial dz WHERE	prac.id_dzial=dz.id_dzial AND dz.id_inst=inst.id_inst ',
                            array( 'offset' => 0, 'limit' => 10 ) );

	$tpl->setVariable('wynik', $wynik);
	
	$Result = array();
	$Result['content'] =& $tpl->fetch( 'design:bw_search.tpl');
	//$Result['content'] =& $tpl->fetch( 'design:nikiss/overview.tpl' );
	$Result['path'] = array( array( 'url' => false,
                                'text' => 'Wynik wyszukiwania' ) );
                                
?>

bw_search.tpl is standard advancedsearch.tpl file and is called using link: mysite__web_address/ez/index.php/plain/przeszukaj_baze_wiedzy

I'm not sure if it can be done this way.

Aleksander

Aleksander Lech

Thursday 22 September 2005 3:26:09 am

Well....
of course it was my mistake.
A was including search.php and using advancedsearch.tpl. Changing include from search.php to advancedsearch.php made things work great.

Aleksander