Author Topic: Search Category Names, Not File Names  (Read 39231 times)

0 Members and 1 Guest are viewing this topic.

Offline tgiokdi

  • Newbie
  • *
  • Posts: 17
    • View Profile
Search Category Names, Not File Names
« on: July 13, 2006, 04:08:08 AM »
site in question:
www.secretfilesandorigins.com

I'd like to be able to search just the category names, and have the results page have links to the categories that fit the description.  The focus of the site is going to be comic book covers, with the category being the series name, and the differnet issues just named whatever number issue it's for.

ie:

Category: DC
Subcategory: Action Comics

When you search for "action comics" right now, nothing comes up.  I've searched the boards and come up null :(

Offline tgiokdi

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Search Category Names, Not File Names
« Reply #1 on: July 15, 2006, 09:23:03 PM »
it's been a couple days, and no replies.  Has no one seriously figured out how to search the category names?  Is there a lmitation that I'm not aware of?  This is something that is desperately needed in a picture gallery, and I'm shocked, SHOCKED, that a category search isn't included.

Let me remind you. I am SHOCKED   :lol:

Offline tgiokdi

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Search Category Names, Not File Names
« Reply #2 on: August 09, 2006, 05:59:06 AM »
Anyone have any suggestions for an image gallery that will support category searches?  I'm flabbergasted that 4images doesn't support this very basic feature

Offline Jasmine

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Search Category Names, Not File Names
« Reply #3 on: August 12, 2006, 08:22:08 PM »
Here's a simple solution.  I'm sure it can be optimized.  It will find all instances of a keyword or keywords in a category tree. 

Important notes:
  • The code below doesn't even think about OR, AND, or NOT queries
  • It will match ANY of the keywords entered

Examples:

In search.php, find:
Code: [Select]
//-----------------------------------------------------
//--- Show Search Results -----------------------------
//-----------------------------------------------------

add after:
Code: [Select]
// MOD: Search category names for keywords (http://www.4homepages.de/forum/index.php?topic=13675#msg75934)
   if (isset($split_words)){
      $split_words1 = preg_replace("/^\*/", '', $split_words);
      $cat_search_keywords = stripslashes(htmlspecialchars(trim(join("|", $split_words1))));        // clean up user input
      $search_cat_result = array();                                                                 // initialize array

      $resultcat = $site_db->query("SELECT cat_id FROM ".CATEGORIES_TABLE."");                      // grab all cats
      while ($row = $site_db->fetch_array($resultcat)) {                                            // loop through cats
         if ( preg_match( "/($cat_search_keywords)/i", get_category_path_nohtml( $row['cat_id'])) & // find match(es) in cat tree
              check_permission("auth_viewcat", $row['cat_id']) ){                                   // check permission
                   $search_cat_result[] = get_category_path( $row['cat_id'],1);                     // add match to array
         }
      }
      $site_db->free_result();
   }
  $site_template->register_vars( 'cat_wordsearch', (empty($search_cat_result) ? "" : join("\n\n<li>", $search_cat_result)) );      // add result to template
// END MOD: Search category names for keywords

Add in search.html:
Code: [Select]
{if cat_wordsearch}
  <h4>category title results:</h4>
  <div style="font-size: 90%;height: 100px; border: 1px dashed #47697e; overflow: auto; background-color: #D7DED1">
         <p class="text">One or more of your search criteria resulted in a match the following category names.</p>
         <ul>{cat_wordsearch}</ul>
   </div>
{endif cat_wordsearch}
Corrections and enhancements are welcome.  :)

Note:  The get_category_path_nohtml subroutine is found in the [MOD] Dynamic Page Title for v1.7 & v1.7.1 topic.

Update 2006/08/16: Added auth_viewcat and updated add match to array line per V@no's suggestion below.
Update 2006/08/20: Mod now checks to ensure that a query was entered before executing.
Update 2006/08/20: Included V@no's modification to register cat_wordsearch when no search keywords present.
« Last Edit: September 16, 2009, 03:13:00 AM by V@no »

Offline WeZ

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Search Category Names, Not File Names
« Reply #4 on: August 16, 2006, 11:16:19 PM »
Hi All,

Anyone know where i can get the get_category_path_nohtml function?

i've tried to implement this mod but get an error when the line that calls this function?

Kind Regards,
WeZ

Offline Jasmine

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Search Category Names, Not File Names
« Reply #5 on: August 17, 2006, 08:03:29 PM »
Sorry about that.  My gallery uses so many mods, that I forget which subroutines are standard and which are mods.

The get_category_path_nohtml subroutine is found in the [MOD] Dynamic Page Title for v1.7 & v1.7.1 topic.

Offline WeZ

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Search Category Names, Not File Names
« Reply #6 on: August 18, 2006, 07:41:12 PM »
Hi Jasmine,

Thank-You for the update... all went well this time...

One last little problem though which i even see on your gallery site...

if you search for athe* then you get the results for athens, however if you search for *thens, then it crashes horribly  :?

think you can update the subroutine to cater for the leading * or am i asking for too much  :wink:

Kind Regards,
WeZ

Offline Jasmine

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Search Category Names, Not File Names
« Reply #7 on: August 19, 2006, 01:09:15 AM »
I've updated the first two lines of code.  Hope this helps.  Anyone else care to refine the code?

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
Re: Search Category Names, Not File Names
« Reply #8 on: August 19, 2006, 06:55:49 AM »
1) your code does not obey categories permissions, thereforе visitors will be able see the names and ids of categories they have no access to.
2)
Code: [Select]
array_push( $search_cat_result, get_category_path( $row['cat_id'],1));                   // add match to arrayis a slower equalent of
Code: [Select]
$search_cat_result[] = get_category_path( $row['cat_id'],1);                   // add match to array
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 WeZ

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Search Category Names, Not File Names
« Reply #9 on: August 19, 2006, 11:28:30 AM »
I've installed alot of mods, but this mod adds more Value add than most of the others because when you get images off the net, most of them have been renamed by the gallery application they were hosted under and most of the times, with no usable description in the file name. this way as long as you've saved them into a folder with a good description, youre sorted.

It is for this reason i would like to see this as prhaps a built in optional extra in future releases of 4Images.

but, thats just my .02c worth ;-)

V@no, That is quite a sneaky point you make. I also notice that if you click on the advanced search link, it lists all categories there as well - even if you are not logged in.

what can be done about it - Jasmine Maybe?
« Last Edit: August 19, 2006, 11:51:29 AM by WeZ »

Offline Jasmine

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Search Category Names, Not File Names
« Reply #10 on: August 19, 2006, 08:03:27 PM »
V@no,  thank you for pointing that out.  I've updated the original post.  Please let me know what you think. 

I'd also like to see it honor AND OR NOT queries, but php is not my first language, and that's about the best I can do for now :) 

Offline WeZ

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Search Category Names, Not File Names
« Reply #11 on: August 19, 2006, 09:33:15 PM »
Hi Jasmine,

Your code does now indeed look like it obeys security. one small bug though - if the user clicks the "advanced search" button "with no text actaully in the text box - you get a warning at the top of your page "Warning: join() [function.join]: Bad arguments" on this line:
[qcode]
$cat_search_keywords = stripslashes(htmlspecialchars(trim(join("|", $split_words1))));        // clean up user input
[/qcode]

i beleive it was because there was no user input :-) ... anyway, it's minor but seeing as it affects your site as well you will probably want to fix it ;-)

V@no, I Have a question for you... Attached, you can see my default search form. when the user selects "advanced search" how do i get it so that it only displays the default 4images form? i only want the "Category Title Results" and "Image Category Results" when there actually is a resultset.

Anyway, keep well both of you...

Kind Regards,
WeZ
« Last Edit: August 19, 2006, 10:12:12 PM by WeZ »

Offline Jasmine

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Search Category Names, Not File Names
« Reply #12 on: August 20, 2006, 08:48:56 PM »
Above code updated to ascertain if keywords were entered before executing. 

WeZ: Did you wrap your template output tags with if ... endif conditionals?

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
Re: Search Category Names, Not File Names
« Reply #13 on: August 20, 2006, 09:40:39 PM »
in order for {if cat_wordsearch} {endif cat_wordsearch} condition to work, the {cat_wordsearch} must be registered every time.
Right now, it only registered when you enter some keywords.
So
Code: [Select]
      $site_template->register_vars( 'cat_wordsearch', join("\n\n<li>", $search_cat_result) );      // add result to template
   }
// END MOD: Search category names for keywords
Can be replaced by:
Code: [Select]
   }
$site_template->register_vars( 'cat_wordsearch', (empty($search_cat_result) ? "" : join("\n\n<li>", $search_cat_result)) );      // add result to template
// END MOD: Search category names for keywords
« Last Edit: August 23, 2006, 05:58:58 AM by V@no »
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 Jasmine

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Search Category Names, Not File Names
« Reply #14 on: August 20, 2006, 10:46:52 PM »
Original post modified with your recommendation.  Thank you!