NOTE: I was wanting to post this on the mods section, but I don't know why I don't have permission to post there. If some admin wants to move the post, I will be grateful
Hello people:
There is a problem if you want to add a boolean field and make it searchable using this guide:
http://www.4homepages.de/forum/index.php?topic=1313.0That works very well with varchar fields. But for boolean fields, it's actually a waste of time and space, because to index it you have to set MIN_SEARCH_KEYWORD_LENGTH to 1, what causes to almost ALL words to be indexed. That can be a problem if you have various searchable fields, as I have. And in case that you want to find a positive value you have to enter a 1 in the search terms...
This mod allows you to make a boolean field searcheable WITHOUT indexing it. It works almost in the same way wich search_new_images works.
I will show the example with the field "image_nocturnal", but thats your choice.
First, add a "boolean" (tinyint 1) field to the images table, with this tutorial:
If you are goin to use an "internal" field (as this example, there is no need to show "Nocturnal: Yes" in the details page) you can avoid the steps involving details.html .
http://www.4homepages.de/forum/index.php?topic=747.msg3277#msg3277In file
search.php :
Look for:
if (isset($HTTP_POST_VARS['search_new_images']) || isset($HTTP_GET_VARS['search_new_images'])) {
$search_new_images = 1;
$show_result = 1;
}
else {
$search_new_images = 0;
}
Insert
below :
// NOCTURNAS
if (isset($HTTP_POST_VARS['search_nocturnal_images']) || isset($HTTP_GET_VARS['search_nocturnal_images'])) {
$search_nocturnal_images = 1;
$show_result = 1;
}
else {
$search_nocturnal_images = 0;
}
//FIN NOCTURNAS
find:
if ($search_new_images && $show_result == 1) {
$search_id['search_new_images'] = 1;
}
insert
below:
//NOCTURNAS
if ($search_nocturnal_images && $show_result == 1) {
$search_id['search_nocturnal_images'] = 1;
}
//FIN NOCTURNAS
find:
if (!empty($search_id['search_new_images']) && $search_id['search_new_images'] == 1) {
$new_cutoff = time() - 60 * 60 * 24 * $config['new_cutoff'];
$sql_where_query .= "AND i.image_date >= $new_cutoff ";
}
add
below:
// NOCTURNAS
if (!empty($search_id['search_nocturnal_images']) && $search_id['search_nocturnal_images'] == 1) {
$sql_where_query .= "AND i.image_nocturnal = 1 ";
}
// FIN NOCTURNAS
find:
$site_template->register_vars(array(
"search_keywords" => htmlspecialchars(stripslashes($org_search_keywords)),
"search_user" => htmlspecialchars(stripslashes($org_search_user)),
"lang_search_by_keyword" => $lang['search_by_keyword'],
"lang_search_by_username" => $lang['search_by_username'],
"lang_new_images_only" => $lang['new_images_only'],
"lang_search_terms" => $lang['search_terms'],
"lang_or" => $lang['or'],
"lang_and" => $lang['and'],
"lang_category" => $lang['category'],
"lang_search_fields" => $lang['search_fields'],
"lang_all_fields" => $lang['all_fields'],
"lang_name_only" => $lang['name_only'],
"lang_description_only" => $lang['description_only'],
"lang_keywords_only" => $lang['keywords_only'],
"category_dropdown" => get_category_dropdown($cat_id),
add
below(note the comma on the previous line)
"category_dropdown" => get_category_dropdown($cat_id),
// NOCTURNAS
"lang_nocturnal_images_only" => $lang['nocturnal_images_only']
// FIN NOCTURNAS
Now in page_header.php :
Find:
"url_new_images" => $site_sess->url(ROOT_PATH."search.php?search_new_images=1"),
Add
below :
// NOCTURNAS
"url_nocturnal_images" => $site_sess->url(ROOT_PATH."search.php?search_nocturnal_images=1"),
// FIN NOCTURNAS
Now go to main.php of your language directory, and define (before ?> or in any place that you want):
$lang['nocturnal_images_only'] = "Sólo imágenes nocturnas";
("Sólo imágenes nocturnas" = "Only nocturnal images" in english).
Now you can add in your template pages the following code:
In
search_form.html, the checkbox to limit the search to the images that have a positive value on the field "image_nocturnal":
<input type="checkbox" name="search_nocturnal_images" value="1" /> {lang_nocturnal_images_only}
And the link to show directly all the images with a positive value (on any page of your template):
<a href="{url_nocturnal_images}">
In case that someone ask:
If you want to look for non-positive (zero) values in the field too, you can put a second instance of the mod (just below the new code added), and change the variable, function and tag names, and replace:
$sql_where_query .= "AND i.image_nocturnal = 1 ";
with:
$sql_where_query .= "AND i.image_nocturnal = 0 ";
Well, that's it...
Best regards.
WR.