[SPT/CWIS] Advanced Search Results
Kucera, Rich
Kucerar at hhmi.org
Mon Jun 12 09:49:25 CDT 2006
Code example to sort-by-classification:
The change is to Scout--SearchEngine.php. There are two globals controlling
how the customized CleanScores() function is used:
$sort_by_classification_pid = "182";
$sort_by_classification_release_flag = "1";
These can be set at the top of SPT--AdvancedSearch.php, and in other places
where custom additional searches of the search engine(for unreleased records
for example, have to set the release flag to 0 and do the search, then set
it back to 1).
182 happens to be the parent category ID of a category to be sorted by.
There is an assumption in the code that each and every resource is tagged by
the sort category. Every record has to have some tag, or it won't show up
in the search. The SQL could be adjusted to change this, perhaps an outer
join.
function CleanScores($Scores, $StartingResult, $NumberOfResults)
{
# perform any requested filtering
if ($this->DebugLevel > 0) { print("SE: Have ".count($Scores)."
results before filter callbacks<br>\n"); }
$Scores = $this->FilterOnSuppliedFunctions($Scores);
# save total number of results available
$this->NumberOfResultsAvailable = count($Scores);
if ( ! empty ($GLOBALS['sort_by_classification_pid']) ) {
//ORDER BY CLASSIFICATION QUERY -- NEEDS TO OCCUR WITHIN
CleanScores()
$sorting_cls_parent_id =
$GLOBALS['sort_by_classification_pid'];
$query_string = "SELECT distinct a.ResourceId
FROM Resources a, ResourceClassInts b,
Classifications c
WHERE a.ResourceId = b.ResourceId
AND b.ClassificationId = c.ClassificationId
AND c.ParentId = $sorting_cls_parent_id
AND a.ReleaseFlag =
{$GLOBALS['sort_by_classification_release_flag']}
AND a.ResourceId >= 0
ORDER BY c.ClassificationName
";
$ResourceDB = new SPTDatabase();
$ResourceDB->Query($query_string);
$ResourceIds = $ResourceDB->FetchColumn("ResourceId");
// echo "<pre>";
// echo "BEFORE\n";
// var_dump( $Scores );
// ITERATE OVER ORDER-BY-CLASSIFICATION INDEX
$Sorted_G_SearchResults = array();
foreach ($ResourceIds as $ResourceId)
{
if ( ! empty( $Scores[$ResourceId] ) ) {
$Sorted_G_SearchResults[$ResourceId]=$Scores[$ResourceId];
}
}
$Scores = $Sorted_G_SearchResults;
// echo "AFTER\n";
// var_dump( $Scores );
// echo "</pre>";
} else {
# sort result list by score
arsort($Scores, SORT_NUMERIC);
}
# trim result list to match range requested by caller
$ScoresKeys = array_slice(
array_keys($Scores), $StartingResult, $NumberOfResults);
$TrimmedScores = array();
foreach ($ScoresKeys as $Key) { $TrimmedScores[$Key] =
$Scores[$Key]; }
# returned cleaned search result scores list to caller
return $TrimmedScores;
}
-----Original Message-----
From: spt-cwis-users-bounces at scout.wisc.edu
[mailto:spt-cwis-users-bounces at scout.wisc.edu] On Behalf Of Kucera, Rich
Sent: Monday, June 05, 2006 11:55 AM
To: SPT / CWIS Users Discussion List
Subject: RE: [SPT/CWIS] Advanced Search Results
I just finished some code to sort by classification.
You have to build a custom index (through SQL query) in the function
CleanScores() in the file Scout--SearchEngine.php.
Hope that helps,
-----------------------------------------
Rich Kucera
Senior Web Applications Developer
Howard Hughes Medical Institute
4000 Jones Bridge Road
Chevy Chase, MD 20815
(301) 215-8714
-----Original Message-----
From: spt-cwis-users-bounces at scout.wisc.edu
[mailto:spt-cwis-users-bounces at scout.wisc.edu] On Behalf Of Michael Drutar
Sent: Monday, June 05, 2006 10:37 AM
To: spt-cwis-users at scout.wisc.edu
Subject: [SPT/CWIS] Advanced Search Results
Edward,
I know that you have probably been over this on the listserv, however I've
searched and searched and cannot seem to find it.
I'm looking to have my Advanced Search Results page print the records
alphabetically. Hence, when someone clicks on "subject: statistics" from a
Full Record page, they are displayed all the statistics resources
alphabetically.
Any ideas?
Thanks,
Mike
_______________________________________________
SPT-CWIS-Users mailing list
SPT-CWIS-Users at scout.wisc.edu
http://scout.wisc.edu/mailman/listinfo/spt-cwis-users
_______________________________________________
SPT-CWIS-Users mailing list
SPT-CWIS-Users at scout.wisc.edu
http://scout.wisc.edu/mailman/listinfo/spt-cwis-users
More information about the SPT-CWIS-Users
mailing list