• [Mod] Add a keyword list to the search form v.2 5 0 5 1
Currently:  

Author Topic: [Mod] Add a keyword list to the search form v.2  (Read 105041 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
[Mod] Add a keyword list to the search form v.2
« on: January 30, 2003, 05:11:55 AM »
Adds a list of all available image keywords to the search_form.html template where the user can select 1 or more and include those words in their search criteria.
See the screen shot at the bottom.

NOTE: There is some confusion circulating around what keywords really are in 4images. Let's see if I can help clear it up.

The default template search_form.html, with the english language pack, uses search_keywords and lang_search_keywords in the form field that actually accepts "words to search for". Search words can be anything from the image description, name, and even keywords. Keywords are words you explicitly assign to an image.

From a dictionary:
Quote
key·word also key word -
A word used as a reference point for finding other information.

It's very common for digital asset management software to not only let you categorize files, but to also let you assign keywords. Keywords are descriptive words, not phrases, that you can assign to your cataloged files in order to categorize and classify them. If you had an image of a tropical beach at sunset, you might assign it keywords such as Sand, Beach, Ocean, Sunset, Tropical, Vacation, Recreation, Outdoor, and so on. You might have chosen to place this image in a "Beaches" category. Suppose you also had an image of a city building taken at sunset when the color had changed and you placed it in a "Buildings" category. The keyword "sunset" could be used to group these images as having something in common. ("Tropical Sunset" is actually two keywords.)

Summary Description
The database table 4images_images is read and a sorted, unique list of keywords is generated. This array is then used to add list of all image keywords found to the search_form.html template. This is a standard HTML <select> form control that allows multiple items to be selected. Example is shown below:


Summary of files affected
[change] search.php
[change] includes/functions.php
[change] lang/english/main.php
[change] templates/default/search_form.html


Open search.php, locate this code near the top:
Code: [Select]
$org_search_keywords = $search_keywords;

if (isset($HTTP_POST_VARS['search_user']) || isset($HTTP_GET_VARS['search_user'])) {

Change it to the new lines as shown:
Code: [Select]
$org_search_keywords = $search_keywords;

// [Mod] Add a list of image keywords to the search form BEGIN
if (isset($HTTP_POST_VARS['search_keyword_list'])) {
  $search_keyword_list = implode(" ", $HTTP_POST_VARS['search_keyword_list']);
  $show_result = 1;
}
else {
  $search_keyword_list = "";
}

$org_search_keywords .= trim(" ".$search_keyword_list);
$search_keywords = $org_search_keywords;
// [Mod] Add a list of image keywords to the search form END

if (isset($HTTP_POST_VARS['search_user']) || isset($HTTP_GET_VARS['search_user'])) {


Locate this code near the bottom:
Code: [Select]
    "category_dropdown" => get_category_dropdown($cat_id)
  ));

Change it to the new lines as shown:
Code: [Select]
    "category_dropdown" => get_category_dropdown($cat_id),
    "lang_image_keyword_list" => $lang['image_keyword_list'], // [Mod] Add a list of image keywords to the search form
    "image_keyword_list" => get_keyword_list() // [Mod] Add a list of image keywords to the search form
  ));



Open includes/functions.php, locate this code at the very bottom:
Code: [Select]
?>
Change it to the following:
Code: [Select]

// [Mod] Add a list of image keywords to the search form BEGIN
function get_keyword_list()
{
  global $lang, $site_sess, $site_db;
  $keyword_dropdown = "";
  $keyword_dropdown .= "<select name=\"search_keyword_list[]\" multiple=\"multiple\" size=\"10\" class=\"setperpageselect\">\n";
  $sql = "SELECT `image_keywords` FROM ".IMAGES_TABLE." WHERE 1 order by `image_keywords` DESC";
  $result = $site_db->query($sql);
  $array = array();
  while(list($Name) = mysql_fetch_row($result)) {
// Commented out until enforcement of user/category/image permissions is developed
//    if (!check_permission("auth_viewimage", $image_row['cat_id']) || !check_permission("auth_viewcat", $image_row['cat_id'])) {
    if(!empty($Name)) {
      $explode_array = explode(" ",$Name);
      for($ctr=0; $ctr < count($explode_array); $ctr++){
        $temp = $explode_array[$ctr];
        $array[] = $temp;
      }
    }
  }
  $site_db->free_result();
  $array1 = array_unique($array); // Remove duplicate values from the array
  if (!empty($array1)) {
    sort($array1,SORT_REGULAR); // Sort the array
    foreach($array1 as $val) {
       $keyword_dropdown .= "<option value=\"".$val."\">".$val."</option>\n";
    }
  }
  $keyword_dropdown .= "</select>\n";
  return $keyword_dropdown;
}
// [Mod] Add a list of image keywords to the search form END

?>



Now let's correct some misleading text in the english language pack and add our new language phrases for this mod.

Open lang/english/main.php and locate:
Code: [Select]
$lang['search_by_keyword'] = "Search by Keyword:<br /><span class=\"smalltext\">Use terms such as AND, OR and NOT to control your search in more detail. Use asterisks (*) as a wildcard for partial matches.</span>";
$lang['search_terms'] = "Search term:";

Change those lines to:
Code: [Select]
$lang['search_by_keyword'] = "Search Words:<br /><span class=\"smalltext\">Use terms such as AND, OR and NOT to control your search in more detail.<br />Use asterisks (*) as a wildcard for partial matches.</span>";
$lang['search_terms'] = "Any or All search words?";


After this line
Code: [Select]
$lang['or'] = "OR";
Add this new line
Code: [Select]
$lang['image_keyword_list'] = "Select Image Keywords:<br /><span class=\"smalltext\">Use CTRL-click or SHIFT-click to select multiple keywords.<br><br>You can use the '".$lang['keywords_only']."' field above to limit your search.</span>"; // [Mod] Add a list of image keywords to the search form


Open templates/default/search_form.html and locate:
Code: [Select]
          <tr>
            <td class="row1">&nbsp;</td>
            <td class="row1"><input type="submit" value="{lang_search}" class="button" /></td>
          </tr>

Replace with this:
Code: [Select]
          <tr class="row2">
            <td valign="top"><b>{lang_image_keyword_list}</b></td>
            <td>{image_keyword_list}</td>
          </tr>
          <tr>
            <td class="row2">&nbsp;</td>
            <td class="row2"><input type="submit" value="{lang_search}" class="button" /></td>
          </tr>


Revisions:
  • Jan 28, 2005 - Version 2.0 - Major rewrite
          Eliminated the need for a new template
          Eliminated the single keyword jump menu and keyword links
          Introduced a multi-item selectable list of image keywords providing more functionality than version 1.0
          Consolidated and reduced code
          TODO:  Find a way to return only keywords for images the user has permission to view. Currently this mod returns ALL image keywords.
  • Removed extraneous show_error_page() from new code block for functions.php - Thanks to v@no for spotting it
  • Fixed location of {keyword_dropdown_form} in search_form.html
       Previous location had it embedded in the search form and caused a javascript error.
  • Added an example of {keyword_links} in search_form.html to the picture.
« Last Edit: May 08, 2005, 03:26:06 AM by Chris »

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Add a keyword jump menu to search form
« Reply #1 on: January 31, 2003, 11:02:25 AM »
I cant get this mod to work... :oops:
first off all, I think u post little extra code that gives error message.
Quote
Insert the following two new functions immediately above it (and under the get_category_dropdown function)
the bottom part of that insert already exist in 4images code:
Code: [Select]
function show_error_page($error_msg, $clickstream = "") {
  global $site_template, $site_sess, $lang, $config;
  if (empty($clickstream)) {
    $clickstream = "<a href=\"".$site_sess->url(ROOT_PATH."index.php")."\">".$lang['home']."</a>".$config['category_separator'].$lang['error'];
  }
  $site_template->register_vars(array(
    "error_msg" => $error_msg,
    "lang_error" => $lang['error'],
    "clickstream" => $clickstream,
    "random_image" => ""
  ));
  $site_template->print_template($site_template->parse_template("error"));
  exit;
}
so, php give error that function show_error_page() already registered.

but when I delete dublicate of this function, neither my search button, nor keyword sellect dont work at all, when I press either of them nothing happend... 8O
maybe I missed something?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Sincerest appologies
« Reply #2 on: February 01, 2003, 02:02:28 AM »
I'm rather embarassed my original post didn't work.  I've got to stop making complex posts so late at night when I'm tired!

The original post has been updated.  You will notice a revision list at the bottom.  I prefer to edit the original post rather than post again since it keeps the instructions all in one place.  This time I tested my own instructions and code against a clean installation of 4images using the default template set.    Yes, it now works but be careful to follow ALL of the instructions.  I tweaked a couple of things.

Keep the feedback coming.  If there are any more problems, I will fix them straight away!

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Add a keyword jump menu to search form
« Reply #3 on: February 01, 2003, 02:36:50 AM »
yay! now works in 3 min!
just now I realized that I dont even use keywords in the gallery...I have just 3 keywords for the whole collection  :?

Thx, vivdviews, nice MOD!
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline airphoto

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • http://www.airphoto.co.uk
[Mod] Add a keyword jump menu to search form
« Reply #4 on: February 01, 2003, 12:47:12 PM »
Nice mod and I got it working in just a few minutes.

One small problem I would like to share. - The keyword jump menu and Keyword search links now show all keywords for all images in all catagories on the site.

When you click on a search link in the jump menu and it belongs to a private catagory the search engine returns "Your search resulted in no matching records." which can be a litle confusing.

Q. Can this be further modified to show only keywords from the catagories that members are allowed to view?

Hope this is good feedback.

Offline jobro

  • Pre-Newbie
  • Posts: 3
    • View Profile
how about an "Add keyword" function?
« Reply #5 on: February 02, 2003, 05:43:41 PM »
Hi Jan, everybody,

I am impressed with the 4images script (if you can still call it a script?  :D ), and I have been searching for a way to integrate the function of adding keywords in a logical manner. I reply now and here, because i see the start if implementing such a function has just been started. My wishes are:

- At upload time, select keywords from the currently available ones in the database (from a drop down list or list box like shown in this thread) and add them to the picture being uploaded. This to prevent ambiguity between keywords that users might add at their own insight.

- Maybe it should be best if the admin adds his *fixed* list of keywords being the one to choose from when doing a search.

- In addition to that, the admin should be able to add keywords at any time.

- Important is, that when uploading masses of pictures, a fixed number of chosen keywords can be added to the pictures being uploaded automatically.

Could this all be possible to implement?

Good day to all and greetz from the Netherlands (snow outside!!  :lol:)

- Jobro

Offline jengwen

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • http://www.jenrichardsphotography.com
Adding keyword dropdown to home page
« Reply #6 on: February 10, 2003, 04:00:53 AM »
This is a great mod and worked fine on my search page.  I was hoping I could add a call to {keyword_dropdown_form} by the {category_dropdown_form} on my home and other similarily formatted pages.  However, when I add it, nothing happens.  There is no sign of the dropdown box, but I don't get any errors either.  Any thoughts on this?

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
[Mod] Add a keyword jump menu to search form
« Reply #7 on: February 10, 2003, 04:13:35 AM »
It only works from the search form by design.  I deliberately avoided making it work like the category drop down where it would get called on every page hit.

Generating the keyword dropdown list is a costly operation since it has to read every image record from the database and parse through the array of keywords attached with each record.  If you have thousands of images this has the potential to really slow down a server as the number of concurrent visitors increases.  Remember that most people have their web sites on shared hosting solutions which means their box is probably already handling 150-400 other web sites too.

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
[Mod] Add a keyword jump menu to search form
« Reply #8 on: February 10, 2003, 04:22:13 AM »
Quote from: airphoto
Nice mod and I got it working in just a few minutes.

When you click on a search link in the jump menu and it belongs to a private catagory the search engine returns "Your search resulted in no matching records." which can be a litle confusing.

Thanks.

I hear you on the private categories issue.  In my configuration of 4images it's not an issue since I don't use private categories.  And since I am very pressed for time over the next 4-6 week, I don't know when I will be able to re-examine this mod for an enhancement (fix)  :roll:

You are correct and I agree that the keyword list should be limited to keywords for which the user has access.

I'll try to see what I can come up with.  In the meantime if anyone else would care to lend their ideas on how it can be done, I'm all ears.

Offline jengwen

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • http://www.jenrichardsphotography.com
[Mod] Add a keyword jump menu to search form
« Reply #9 on: February 10, 2003, 05:39:07 AM »
I understand what you are saying about it being processor intensive to have on every page.  I am not sure this is a concern for me, since I won't have many users accessing my site and won't have that many photos.  If this is still a concern, I would be willing to cut-and-paste my list of keywords and hard-code them into the dropdown box.  They won't change often, so it wouldn't be hard for me to maintain.  Do you have an example of what I would need to change to get that to work?

Offline intuitiv

  • Pre-Newbie
  • Posts: 9
    • View Profile
    • http://www.intuitivmedia.net/
Keyword limit ?
« Reply #10 on: February 10, 2003, 04:10:23 PM »
Hello,

is it possible to limit the number of keywords listed in the dropdown?

thank you !

Offline jobro

  • Pre-Newbie
  • Posts: 3
    • View Profile
Logical keyword add/search
« Reply #11 on: February 10, 2003, 07:55:13 PM »
Ever thought about categorising the keywords as well? I also thought of other methods of storing the keywords in a logical manner. I am running a modded test setup of 4images with 10 people that batch upload folders with their images at will.

They asked me for a different approach on the keywords which should rule out double entry or misspelled words so everyone searches with the right keywords. I thought of using only drop down menus for the keywords and an enhanced upload page which offers the opportunity to choose your keywords from the list that exists, thus preventing spelling mistakes etc. The admin can add or remove the keywords.

I think the given mod is a good start, but when the list of words gets too large, it doesn't work efficiently anymore. I am working on a modded batch import that does auto-thumbnailing as well as keyword addition, all in one go.

Who will help this poor PHP coder??  :oops:

Offline tradertt

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
[Mod] Add a keyword jump menu to search form
« Reply #12 on: March 01, 2003, 08:41:37 PM »
Is there anyway to limit the keywords? maybe to the more popular photos? or more  popular keywords? or a admin function to set it?

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
[Mod] Add a keyword jump menu to search form
« Reply #13 on: March 01, 2003, 09:36:16 PM »
Sorry, there is no way to limit the number of keywords.

Sorry, there is no way to limit the keywords to only "popular" photos.

The purpose of my mod was to allow for easy keyword searches as part of the advanced search function.  Therefore, I did not design any limit mechanisms, nor do I have plans to do so since this is meant to be used as part of the advanced search feature.

The only change I am considering is to limit the keyword list to only those images which the user has permission to view.  This is a logical extension of the 4images user and group permissions security model and so it seems natural that it should be accomodated.  The problem with adding this is that I do not have time right now to take on the added work.

I'll post again if I have made any changes.

Offline Ernesto Taseffa

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: [Mod] Add a keyword jump menu to search form
« Reply #14 on: March 02, 2003, 12:33:33 AM »
.
« Last Edit: August 09, 2009, 01:11:02 AM by Ernesto Taseffa »