Nope - I gave up on the filters and hooks and whatnot... just wasn’t doing what I needed... I wound up writing my own.
It’s kinda messy, no pagination, but it works:
The search snippett:
<?php
if (empty($_POST)) return '';
if (!empty($submitVar) && empty($_POST[$submitVar])) return '';
$modx->setPlaceholder('name',$_POST["name"]);if($_POST["name"] == ''){$name = '';}else{$name = $_POST["name"];}
$modx->setPlaceholder('institution',$_POST["institution"]);if($_POST["institution"] == ''){$institution = '';}else{$institution = $_POST["institution"];}
$modx->setPlaceholder('academicinterest',$_POST["academicinterest"]);if($_POST["academicinterest"] == ''){$academicinterest = '';}else{$academicinterest = $_POST["academicinterest"];}
$modx->setPlaceholder('clinicalinterest',$_POST["clinicalinterest"]);if($_POST["clinicalinterest"] == ''){$clinicalinterest = '';}else{$clinicalinterest = $_POST["clinicalinterest"];}
$modx->setPlaceholder('province',$_POST["province"]);if($_POST["province"] == ''){$province = '';}else{$province = $_POST["province"];}
$modx->setPlaceholder('city',$_POST["city"]);if($_POST["city"] == ''){$city = '';}else{$city = $_POST["city"];}
$tpl = $modx->getOption('tpl',$scriptProperties,'OncologistSearchResult');
include_once $modx->config['base_path'].'core/components/oncologistSearch/include.oncologistSearch.php';
//echo '<h6>' . $name . $institution . $academicinterest . '</h6>';
$searchResults = getOncologists($name,$institution,$academicinterest,$clinicalinterest,$province,$city);
$output = '';
foreach($searchResults as $result){
$output .= $modx->getChunk($tpl,$result);
$count = $result["count"];
}
if(!$output){$count = "Sorry, no results were found.";}
$modx->setPlaceholder('resultSet',$output);
$modx->setPlaceholder('resultCount',$count);
//return $output;
return '';
The actual search functions:
<?php
$hostname = "******";
$username = "*****";
$password = "******";
$dbName = "********";
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
@mysql_select_db( "$dbName") or die( "Unable to select database");
function getOncologists($name,$institution,$academicinterest,$clinicalinterest,$province,$city){
$sql = "select * from custom_oncologist_database where id >= '1' AND ";
if (!empty($name)){$sql .= "(firstname like '%" . $name . "%' OR lastname like '%" . $name . "%') AND ";}
if (!empty($institution)){$sql .= "(institution LIKE '%" . $institution . "%') AND ";}
if (!empty($province)){$sql .= "(province LIKE '%" . $province . "%') AND ";}
if (!empty($city)){$sql .= "(excity LIKE '%" . $city . "%') AND ";}
if (!empty($academicinterest)){$sql .= "(" . $academicinterest . " = '1') AND ";}
if (!empty($clinicalinterest)){$sql .= "(" . $clinicalinterest . " = '1') AND ";}
$sql .= " oncologist_database = '1' order by lastname;";
$mysqlresults = mysql_query($sql) or die (mysql_error());
$records = mysql_num_rows($mysqlresults);
if ($records == 0) {
$count = "Sorry, no results were found.";
}else{
$count = $records . " Results";
}
$i = 0;
$resultArray = '';
while ($row = mysql_fetch_assoc($mysqlresults)) {
$resultArray[$i]["id"] = $row["id"];
$resultArray[$i]["salutation"] = $row["salutation"];
$resultArray[$i]["firstname"] = $row["firstname"];
$resultArray[$i]["lastname"] = $row["lastname"];
$resultArray[$i]["resultCity"] = $row["excity"];
$resultArray[$i]["resultInstitution"] = $row["institution"];
$resultArray[$i]["resultProvince"] = $row["province"];
$resultArray[$i]["clinicalinterestspecifics"] = $row["clinical_interest_specifics"];;
$resultArray[$i]["clinicalinterestother"] = $row["other_clinical_interest"];
$resultArray[$i]["academicinterestspecifics"] = $row["academic_interest_specifics"];
$resultArray[$i]["academicinterestother"] = $row["other_academic_interest"];
$resultArray[$i]["count"] = $count;
$i++;
}
//print_r($resultArray);
return $resultArray;
}
function getResultsDetail($id){
$sql = "select * from custom_oncologist_database where id = '" . $id . "' LIMIT 1;";
$mysqlresults = mysql_query($sql) or die (mysql_error());
$records = mysql_num_rows($mysqlresults);
if (mysql_num_rows($mysqlresults) == 0) {
$count = "Sorry, no results were found.";
}else{
$count = $records . " Results";
}
$i = 0;
$resultArray = '';
while ($row = mysql_fetch_assoc($mysqlresults)) {
$resultArray[$i]["id"] = $row["id"];
$resultArray[$i]["salutation"] = $row["salutation"];
$resultArray[$i]["firstname"] = $row["firstname"];
$resultArray[$i]["lastname"] = $row["lastname"];
$resultArray[$i]["resultCity"] = $row["excity"];
$resultArray[$i]["resultInstitution"] = $row["institution"];
$resultArray[$i]["resultProvince"] = $row["province"];
$resultArray[$i]["clinicalinterestspecifics"] = $row["clinical_interest_specifics"];;
$resultArray[$i]["clinicalinterestother"] = $row["other_clinical_interest"];
$resultArray[$i]["academicinterestspecifics"] = $row["academic_interest_specifics"];
$resultArray[$i]["academicinterestother"] = $row["other_academic_interest"];
$resultArray[$i]["specialty"] = $row["specialty"];
$resultArray[$i]["specialty_other"] = $row["specialty_other"];
$resultArray[$i]["staff_or_resident"] = $row["staff_or_resident"];
$resultArray[$i]["excountry"] = $row["excountry"];
$resultArray[$i]["telephone"] = $row["telephone"];
$resultArray[$i]["extension"] = $row["extension"];
$resultArray[$i]["count"] = $count;
$i++;
}
//print_r($resultArray);
return $resultArray;
}
the search result chunk:
<li>
<label><a href="[[~351]]?oncologist=[[+id]]">[[+lastname]], [[+salutation]] [[+firstname]]</a></label>
<p>[[+resultInstitution]] - [[+resultCity]], [[+resultProvince]]<br />
Clinical Interests: [[+clinicalinterests]]<br />
Academic Interests: [[+academicinterests]]<br />
</li>
that searches a custom table of users for specific criteria, while sloppy - it does work. I’m sure there are better ways to write most of the php - I’m just not a php guy....
this one is far less errr. ’tidy’ but it searches the content tables for a bunch of different things. again - no pagination or ’relevance’
<?php
$hostname = "xxxxxx";
$username = "xxxxxxx";
$password = "xxxxxxx";
$dbName = "xxxxxxxx";
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
@mysql_select_db( "$dbName") or die( "Unable to select database");
//some default stuff
$limit = $limit;
$offset = $offset;
$tpl = $modx->getOption('tpl',$scriptProperties,'AdvancedSearchResult');
date_default_timezone_set('UTC');
if(!isset($_POST["searchterms"])){ $searchterms = "";}else{$searchterms = $_POST["searchterms"];}
if(!isset($_POST["searchdefault"])){ $searchdefault = "";}
$searchterms = trim(strip_tags($searchterms));
$searchdefault = $searchterms;
if(isset($_POST["searchtitle"])){$searchtitle = 'checked';}else{$searchtitle = '';}
if(isset($_POST["searchbody"])){$searchbody = 'checked';}else{$searchbody = '';}
if(isset($_POST["phrase"])){$phrase ='checked';}else{$phrase = '';}
if(isset($_POST["andor"])){$andor ='and';}else{$andor = 'or';}
if(!isset($_POST["fromdate"])){ $fromdate = "";}else{$fromdate = trim($_POST["fromdate"]);}
if(!isset($_POST["todate"])){ $todate = "";}else{$todate = trim($_POST["todate"]);}
//funtions
function toEpoch($humandate,$offset){
$arrdates = explode('-',$humandate);
$epochdate = mktime(0,0,0,$arrdates[1],$arrdates[2],$arrdates[0]);
$epochdate = ($epochdate + $offset);
return $epochdate;
}
if (empty($_POST)) return '';
if (!empty($submitVar) && empty($_POST[$submitVar])) return '';
if($phrase != 'checked'){
if(stristr($searchterms, ",")){$searchterms = str_replace(","," ",$searchterms);}
$searchterms = explode(" ", $searchterms);
}else{
$searchterms = array($searchterms);
}
$sql = "";
$sql .= "select pagetitle, longtitle, id, description, introtext, content, publishedon from modx_site_content where (";
if(($searchbody == 'checked') && ($searchtitle == '')){
foreach($searchterms as $i => $aterm){
if($i != 0){ $or = $andor;}else{$or = '';}
$sql .= $or . " content like '%" . $aterm . "%' ";
}
}elseif(($searchbody == '') && ($searchtitle == 'checked')){
foreach($searchterms as $i => $aterm){
if($i != 0){ $or = $andor;}else{$or = '';}
$sql .= $or . " longtitle like '%" . $aterm . "%' ";
}
}else{
foreach($searchterms as $i => $aterm){
if($i != 0){ $or = $andor;}else{$or = '';}
$sql .= $or . " longtitle like '%" . $aterm . "%' or content like '%" . $aterm . "%' ";
}
}
$sql .= ") ";
if($fromdate != ""){ $sql .= " and publishedon >= '" . toEpoch($fromdate,0) . "'" ; }
if($todate != ""){ $sql .= " and publishedon <= '" . toEpoch($todate,86399) . "'" ; }
$sql .= " and searchable = 1 and template = 1 order by publishedon;";
$mysqlresults = mysql_query($sql) or die (mysql_error());
$records = mysql_num_rows($mysqlresults);
$resultArray = '';
if (mysql_num_rows($mysqlresults) == 0) {
$count = "Sorry, no results were found.";
}else{
$count = $records . " Results";
}
$i = 0;
while ($row = mysql_fetch_assoc($mysqlresults)) {
$pubdate = date("M/d/Y", $row["publishedon"]);
$strcontent = $row["description"];
$pubdate = $pubdate;
if($row["introtext"] == ''){$description = 'Sorry, no description is currently available.';}else{$description = $row["introtext"];}
if($row["longtitle"] == ''){$longtitle = $row["pagetitle"];}else{$longtitle = $row["longtitle"];}
$resultArray[$i]["id"] = $row["id"];
$resultArray[$i]["longtitle"] = $longtitle;
$resultArray[$i]["pubdate"] = $pubdate;
$resultArray[$i]["description"] = $description;
$resultArray[$i]["records"] = $records;
$i++;
}
$output = '';
foreach($resultArray as $result){
$output .= $modx->getChunk($tpl,$result);
}
if($andor == "and"){$phandor = 'checked';}else{$phandor = '';}
$modx->setPlaceholder('searchdefault',$searchdefault);
$modx->setPlaceholder('searchtitle',$searchtitle);
$modx->setPlaceholder('searchbody',$searchbody);
$modx->setPlaceholder('phrase',$phrase);
$modx->setPlaceholder('fromdate',$fromdate);
$modx->setPlaceholder('todate',$todate);
$modx->setPlaceholder('andor',$phandor);
$modx->setPlaceholder('count',$count);
$modx->setPlaceholder('searchresults',$output);
return '';
and the snippet that posts to it....
<p>[[AdvancedSearch? &submitVar=`execute-search` &limit=`10` &offset=`0`]]</p>
<form class="form advanced-search" action="[[~[[*id]]]]" method="post" name="advanced-search">
<ul>
<li><label>Search term[s]:</label><input class="searchbox" style="width: 600px;" type="text" name="searchterms" value="[[+searchdefault]]" /></li>
<li><label>Search in title</label><input class="checkbox" type="checkbox" name="searchtitle" /></li>
<li><label>Search in body</label><input class="checkbox" type="checkbox" name="searchbody" /></li>
<li><label>Search as a phrase</label><input class="checkbox" type="checkbox" name="phrase" /></li>
<li><label>Must contain all terms</label><input class="checkbox" type="checkbox" name="andor" /></li>
<li><label class="datefield">From (published) date:</label><input class="datefield" type="text" name="fromdate" value="[[+fromdate]]" /> <input class="submit date" onclick="displayDatePicker('fromdate', this);" type="button" value="Set Date" /></li>
<li><label class="datefield">To (published) date:</label><input class="datefield" type="text" name="todate" value="[[+todate]]" /> <input class="submit date" onclick="displayDatePicker('todate', this);" type="button" value="Set Date" /></li>
<li><label> </label><input class="submit advanced" type="submit" name="execute-search" value="submit" /></li>
</ul>
</form><!--
[ [!getPage? &element=`AdvancedSearch`] ]
[ [!getPage? &element=`searchresults`] ]
-->
<ul class="advanced-results">
<li>
<h4>[[+count]]</h4>
</li>
[[+searchresults]]</ul>
So - [Again!] no pagination, php sexiness is weak, I should at least clean up the db connection stuff, oh yea - & no real validation. but if you can use any of this & bend it to your will...... have at it - and if you figure out the pagination... hit me back!
-good luck
-sean