Fantastic, I've been looking for something like this for some time.
My girlfriend had a play with your code and enhanced it slightly because I noted that it didn't appear to search picture tags, just the name, description and the alt.
Laura isn't a SQL / PHP person so the code can probably be made even more efficient.
I don't think we added anything extra to what you defined for search.php;
<p></p>
<?php if(is_search()) {
$search = $wp_query->get('s');
$keywords = preg_replace('/\+/',' ',$search);
if (function_exists ('ngg_get_search_pictures')) { // function from functions.php
$nggpictures = ngg_get_search_pictures($keywords, '6'); // put the number of pictures by row you want, if you don't want "4"
if ($nggpictures) {
echo "<h2></h2>";
echo $nggpictures;
}
}
}
?>
Several changes in functions.php;
## Function to do searchs on gallery pics from NextGen Gallery plugin
##
## 2 vars : (1) $keywords (usually coming from the standard search query from wordpress)
## (2) $numberPicCol (number of pic by row, if null it takes 4 )
function ngg_get_search_pictures ($keywords, $numberPicRow = NULL) {
global $wpdb;
$count=1;
if (!$numberPicRow) { $numberPicRow = "4"; }
$nngquery = "
SELECT pid,description,alttext
FROM wp_ngg_pictures
WHERE MATCH (description, filename, alttext) AGAINST ('*$keywords*' IN BOOLEAN MODE)
AND exclude = '0'
UNION
SELECT pid,description,alttext
FROM wp_ngg_pictures, wp_ngg_tags, wp_ngg_pic2tags
WHERE pid = picid and tagid = id and
MATCH (name) AGAINST ('*$keywords*' IN BOOLEAN MODE)
AND exclude = '0'
";
$pictures = $wpdb->get_results($nngquery, ARRAY_A);
if ($pictures) foreach($pictures as $pic) {
$out .= '';
$out .= '<img class="ngg-gallery" style="border: .1em solid #FFFFFF" src="'.nggallery::get_thumbnail_url($pic[pid]).'" alt="'.stripslashes($pic[alttext]).'" title="'.stripslashes($pic[alttext]).'" />';
$out .= "\n";
if ($count == 0) {
$out .= "";
}
++$count;
$count%=$numberPicRow;
}
return $out;
};
Hope the code posts OK?
I'm redeveloping my website but you can see the code in practise here, http://blog.aengusm.com/?page_id=24 not many pics there at the moment so just enter a single letter like a in the search box.
Hope that adds something for someone.
Cheers,
Aengus