Search tags by exact phrase

I'm using ZP 1.2.1 on a site for a printer. I'm creating dynamic albums to show the available fonts for printing. This works great except for font albums titled "serif" and "sans serif". If a user types in "serif" they get both serif and sans serif fonts.

In looking for ways to make ZP to search for exact matches of tags, I found on the Changelog page for this version a listing for "The return of 'partial match search of tags' ", but no information about what this means.

How do I get an exact match? Is it possible?

Comments

  • Finally, a supportive voice. Zenphoto 1.2.1 required exact matches for tags. But everyone objected, so they reverted to partial matches. This is what the change log means.

    There is a sql statement generated in class-search.php in the tagserach function right at the front of the function. Currently it uses `LIKE %%` change it to `=`
  • Haha, what about putting the "exact tag" or "partial search" as a checkable option?
  • acrylian Administrator, Developer
    That might be an idea, but maybe we could try it differently. I think basically all search engines support exact term search if you put the term into quotes. Stephen, maybe we could get that into that, too?
  • Great, thanks a lot. I just wanted to ask this question :)
  • The quotes thing is a great idea too. Maybe both the option and stick the quotes thing into partial search.. but what if the tag had quotes?
  • Ideally, it would be nice to be able to create a dynamic album using an exact search, but still allow partial matches for general searches. Probably a much more complicated code change, but might be a nice feature. Don't know what the answer is, but I appreciate you telling me what to look for in the code.
  • acrylian Administrator, Developer
    Well, I think if and how that can be done is more sbillard's part... He did the most of the search anyway.

    @albeezie. Since tags are naturally one word keywords I think quotes may be quite unusual...
  • Sometimes tags aren't single words tho, for example, a name whether it be a two-word city name or even a person, which would sometimes mean multiple words in a tag. Or like in the above example "sans serif".. It would be nice to have a drop-down menu option that the average user could choose by the search box that would pick exact match or partial match.
  • sbillard: I should probably mention that I am fairly new to PHP. I can't find the exact code you mention above... closest is `$sql .= '`name`LIKE "%'.$singlesearchstring.'%" OR ';`
    Is this the line I need to edit? I've tried several ways of changing LIKE to = and none work.

    A little more help please and thank you.
  • acrylian Administrator, Developer
    @albeezie: Of course you are right....
  • Hmm.. judging from the tone of your post, I apologize if I offended you in some way, acrylian..

    I was not trying to be "right" but I do have multiple word tags in my photos, which is why I was one of those people who wanted the partial search match. I didn't see the point in exact match tag, but kenholmes has shed light on that for me.
  • acrylian Administrator, Developer
    Absolutly no offense taken!!! I just wanted to agree that tags not always are one word and maybe even include quotes sometime. I had not thought about that.
  • It is not practical to base exact tag searching on use of quote marks. An option is possible, though.
  • While I certainly appreciate the programming debate over whether to quote or not to quote, can someone please help me find the correct line in the code to change to disable the partial match search?

    What sbillard offered earlier: "There is a sql statement generated in class-search.php in the tagserach function right at the front of the function. Currently it uses `LIKE %% change it to ="` doesn't seem to apply to the code I am looking at. That

    I do find: `$sql .= 'name' LIKE "%'.$singlesearchstring.'%" OR ';`
    But making similar changes to this line breaks the search.
  • A spirited debate has ensued over the use of quote marks in searches, which is commendable. But it steps right past the answer to my problem. Please see above post.

    As I stated before, I am fairly new to PHP (but I ain't stupid), so please lend a hand... Please? I need to create dynamic albums for fonts. Tags include "Serif" and "Sans Serif". Because exact search don't work, sans serif items come up when searching for "serif".

    SBillard gave a solution to the problem - see thread above - but the code given doesn't exist anywhere in the install. So... anyone? Or do I switch to Gallery? Or should I just live with the problem and resolve myself that you get what you pay for with free open source software?
  • acrylian Administrator, Developer
    I think you got the right part of the code.
    `$sql .= 'name' LIKE "%'.$singlesearchstring.'%" OR ';`
    (in the svn: `$sql .= '`name`LIKE "%'.mysql_real_escape_string($singlesearchstring).'%" OR ';`)

    should work if changed to

    `$sql .= 'name' = "'.$singlesearchstring.'" OR ';`
  • Bless you. This works fine, although it includes the album (not the images) for my "sans serif" fonts as an item when when searching for "serif". Hope that makes sense. This isn't as big an issue as the partial search problem, but it would be nice if it wasn't there.

    Thanks!
  • If you are saying you don't wish the albums having the tags to show, you can omit the album loop from the search page.
  • Thanks, I'll give that a try!
Sign In or Register to comment.