Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Eliminating more false positives on partial search patterns?  (Read 4251 times)

0 Members and 1 Guest are viewing this topic.

sjordan

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 52

Can someone help remedy a little annoyance?

I have photos from New York with keyword "NY". I also have photos from Germany. When I do a search on "NY" I of course get my New York pictures but also Germany as it matches the final two characters.

Insights on how to remedy this process would be appreciated.

Thank you in advance.

version 1.48

hoping not to incur the wrath -- i did search the form on "partial" "substring" "regex" "pattern" before posting
« Last Edit: July 25, 2006, 05:29:42 pm by Nibbler »
Logged

sjordan

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 52
Re: Eliminating more false positives on partial search patterns?
« Reply #2 on: July 25, 2006, 05:00:23 pm »

Hello Nibbler,

First thank you for the response.

I put your suggestion in place and it's not working for me. After looking at the code, your solution seems to work as long as the keywords  is just one. Meaning if the only keywords for a photo of new york is just "ny" then it would work. However, the moment I add multiple keywords, such as 'ny', 'the big apple', new york', etc. no results are found.

Allowing the wild card will find results, but then I'm back to having it find false positives like 'germany' as well.

Is this correct?

Thank you in advance.
Logged

Nibbler

  • Guest
Re: Eliminating more false positives on partial search patterns?
« Reply #3 on: July 25, 2006, 05:05:17 pm »

Try

Code: [Select]
if (in_array($param, $allowed))$fields[] = "$param LIKE '%$word%'";
change to

Code: [Select]
if (in_array($param, $allowed)) $fields[] = $param == 'keywords' ? "CONCAT(' ', $param, ' ') LIKE '% $word %'" : "$param LIKE '%$word%'";
Logged

sjordan

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 52
Re: Eliminating more false positives on partial search patterns?
« Reply #4 on: July 25, 2006, 05:19:25 pm »

Nibbler,

That seems to do the trick.

So basically it checks if the param is the literal 'keyword'. If so, slap some white space around the search target ($word) and use the wildcard. Basically, we're looking for whole words (analogous to the regex \b word boundaries). Otherwise, proceed as normal on the other params?

Thank you again.
Logged

Nibbler

  • Guest
Re: Eliminating more false positives on partial search patterns?
« Reply #5 on: July 25, 2006, 05:30:56 pm »

Yup. We need to pad the value in the db too so keywords at the start and end of the list can be matched.
Logged

sjordan

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 52
Re: Eliminating more false positives on partial search patterns?
« Reply #6 on: July 25, 2006, 05:34:39 pm »

Nibbler,

Can you help mean understand the need for mysql CONCAT?

This seems to work as well
Quote
if (in_array($param, $allowed)) $fields[] = $param == 'keywords' ? "$param LIKE '% $word %'" : "$param LIKE '%$word%'";

Nibbler, I really appreciate your help on this.
« Last Edit: July 25, 2006, 05:43:59 pm by sjordan »
Logged

Nibbler

  • Guest
Re: Eliminating more false positives on partial search patterns?
« Reply #7 on: July 25, 2006, 05:51:47 pm »

I just did explain that. If the keywords are "one two three four" then you will find ' two ' and ' three ' but not ' one ' or ' four '. That code makes the keywords into " one two three four " so they can all be found.
Logged

sjordan

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 52
Re: Eliminating more false positives on partial search patterns?
« Reply #8 on: July 25, 2006, 06:46:50 pm »

Oh sorry, I didn't understand how slick your code is. I mistook your statement about padding the db to mean I have to manually query the db and pad the keywords before it would work flawlessly. I didn't realize that by using CONCAT, that padding is effectively happening dynamically each time the query is run.

My bad.

Thank you again.

Logged
Pages: [1]   Go Up
 

Page created in 0.019 seconds with 20 queries.