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: search for whole words  (Read 4195 times)

0 Members and 1 Guest are viewing this topic.

blueberg

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 48
search for whole words
« on: February 05, 2010, 07:26:56 am »

http://www.birdmarks.com/coppermine/search.php

Is there a way to configure the search part of coppermine to search for entire words or (text strings)? As it is now, if you type in a single letter..it will return every item in the database that contains that letter in any part of any keyword.

For example, if a picture has the keyword of "iceberg" .. and someone does a search for the letter "c"  it brings up this image.

Can the search be made to look for the empty spaces between keywords and then use only the complete string it finds BETWEEN empty spaces to do its search?

Thanks.
Logged

Old RMN

  • Coppermine newbie
  • Offline Offline
  • Gender: Male
  • Posts: 8
    • www.primethai.com -Discover Thailand individually-
Re: search for whole words
« Reply #1 on: February 10, 2010, 12:50:18 pm »

Hello,

i think my problem is related to bluebergs question, so I am posting here:

in my gallery

 http://www.primethai.com

some keywords are 100% substrings of other keywords ( I had for example 'park' and 'national_park').

Using these as album keywords produces unwanted results:
all the pictures featuring the keyword with the longer string will be listed as linked files in the album, too, that has the substring as album keyword.

In my example, all the 'national_park' (s) ended up in the album with the keyword 'park' , too.

Is there any way to set Coppermine up so that the album keyword matches only the exact string in the keyword list of the pictures?

I am using 1.4.26 with Stramm's modpack and the 'Indexed and organized keyword list on search page' hack.
(http://forum.coppermine-gallery.net/index.php/topic,30900.msg143004.html#msg143004)

Thanks in advancy for any good advice.
Logged
Sometimes to find the way home one has to leave it.

Old RMN

  • Coppermine newbie
  • Offline Offline
  • Gender: Male
  • Posts: 8
    • www.primethai.com -Discover Thailand individually-
Re: search for whole words
« Reply #2 on: February 10, 2010, 01:36:00 pm »

I just found that my problem has been mentioned in

Topic: Album keyword matches on substring - Intended behavior?
http://forum.coppermine-gallery.net/index.php/topic,49360.0.html

and a related search behaviour in
Topic: Need help with search function, again....
http://forum.coppermine-gallery.net/index.php/topic,30310.msg140285.html#msg140285

and
Topic: Eliminating more false positives on partial search patterns?
http://forum.coppermine-gallery.net/index.php/topic,34219.0.html

But there seems to be no solution or workaround for the album-keyword-related problem yet.
-I am sure not the only one who does not want all his 'cartoon' and 'carnival' pictures ending up in his 'car' album.
Logged
Sometimes to find the way home one has to leave it.

blueberg

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 48
Re: search for whole words
« Reply #3 on: February 10, 2010, 10:23:10 pm »

Hey OLD RMN,

Thanks for replying to my post. Your suggestions led me to this post that actually seems to fix the problem.
http://forum.coppermine-gallery.net/index.php/topic,34219.msg160066.html#msg160066


the code switch that nibbler recommends in the include/search.inc.php file works

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

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


But this fix only applies to the words in your "keywords" field and not the title or caption fields.

My advanced search was set so that the Title, Caption and keywords were all 'checked' by default. So I simply changed that on the search.php page so that only the keywords field was 'checked' by default. The search will still pick up fragments of search words in the title and caption of your images, but only if those checkboxes are checked by your users. Most people start with the default search when searching...so they may never even check any of the other boxes if they find what they are looking for. I don't know how to add the other two fields to this code above, although it can probably be done easily by someone knwledgable about the code. Below is my workaround to change the default of the search page to search the keywords only until someone can help with the code to include the other fields. If I get time, I will play around with the code. If I figure it out, I will post it here.

To change the default settings of your search page so that only the keywords checkbox is checked by default, find search.php in your root coppermine gallery. First, make a copy of it in case you need to go back to it.

You basically want to "uncheck" the checkbox for title and for caption and only leave keywords checked.

Here's the code to look for and change in search.php:

Code: [Select]
<tr>
                                                <td><input type="checkbox" name="title" id="title" class="checkbox" checked="checked" /><label for="title" class="clickable_option">{$lang_adv_opts['title']}</label></td>
                                                <td align="right">{$lang_search_php['newer_than']} <input type="text" name="newer_than" size="3" maxlength="4" class="textinput" /> {$lang_search_php['days']}</td>
                                        </tr>
                                        <tr>
                                                <td><input type="checkbox" name="caption" id="caption" class="checkbox" checked="checked" /><label for="caption" class="clickable_option">{$lang_adv_opts['caption']}</label></td>
                                                <td align="right">{$lang_search_php['older_than']} <input type="text" name="older_than" size="3" maxlength="4" class="textinput" /> {$lang_search_php['days']}</td>
                                        </tr>

change the above code to:
Code: [Select]
<tr>
                                                <td><input type="checkbox" name="title" id="title" class="checkbox" /><label for="title" class="clickable_option">{$lang_adv_opts['title']}</label></td>
                                                <td align="right">{$lang_search_php['newer_than']} <input type="text" name="newer_than" size="3" maxlength="4" class="textinput" /> {$lang_search_php['days']}</td>
                                        </tr>
                                        <tr>
                                                <td><input type="checkbox" name="caption" id="caption" class="checkbox" /><label for="caption" class="clickable_option">{$lang_adv_opts['caption']}</label></td>
                                                <td align="right">{$lang_search_php['older_than']} <input type="text" name="older_than" size="3" maxlength="4" class="textinput" /> {$lang_search_php['days']}</td>
                                        </tr>

Then a search for "car" will no longer find "cartoons" and "carnival"

If nibbler can help with the code to make this work in all the search fields (i.e title and caption and user fields) then that would be even better. But for now, I simply am adding my title and caption terms into my keywords.
 
My test gallery is at http://www.birdmarks.com/coppermine

There are only bogus test words in there now.
If you type in "deer" into my default search you get 4 results. These 4 images have "deer" in their keywords. But if you type in "dee" you get NO results.

Now, If you go into the advanced search and check the "title" box (and keywords)  you get 5 results. I have "deer" in the title of one image.
Further, in the advanced search, if you check "title", caption" and "keywords" you get 6 results as I have "deer" in one caption as well.


But, if you do a search for "dee" while the title and caption box are checked, you get 2 results, the one with "deer" in the title and the one with "deer" in the caption.

So the best thing would be if someone could tweak the above code to include those other fields. I'm sure it can be done, and is probably a simple tweak if you know what you are doing. But in the meantime, the code works great for the keywords field.
Logged

Nibbler

  • Guest
Re: search for whole words
« Reply #4 on: February 10, 2010, 10:50:23 pm »

@Old RMN: Album keywords are not related to searching. Please start your own thread.

@blueberg:

Code: [Select]

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


Can be changed as required, eg.

Code: [Select]


if (in_array($param, $allowed)) $fields[] = ($param == 'keywords' || $param == 'title' || $param == 'caption')  ? "CONCAT(' ', $param, ' ') LIKE '% $word %'" : "$param LIKE '%$word%'";


« Last Edit: February 11, 2010, 06:34:34 pm by Nibbler »
Logged

blueberg

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 48
Re: search for whole words
« Reply #5 on: February 11, 2010, 12:28:19 am »

HI Nibbler,  Thanks for your reply...but unfortunately...I don't see anything in the example you sent. There is nothing but a long scroll bar beneath the field and nothing in the code field itself. Would you please be so kind as to send the example again?

Thank you so much. You always have the solutions!!!  ;D
Logged

Old RMN

  • Coppermine newbie
  • Offline Offline
  • Gender: Male
  • Posts: 8
    • www.primethai.com -Discover Thailand individually-
Re: search for whole words
« Reply #6 on: February 11, 2010, 02:24:40 am »

Hello blueberg,
thanks for the quick reply. In my case I am less concerned about too many unwanted hits in individual searches, but in an unwanted number of pictures displayed in albums with linked files.

Therefore,

Nibbler, thanks for the hint. New thread created at

http://forum.coppermine-gallery.net/index.php/topic,63702.0.html
Album keyword matches on substring produces unwanted results
Logged
Sometimes to find the way home one has to leave it.

blueberg

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 48
Re: search for whole words
« Reply #7 on: February 11, 2010, 06:20:53 pm »

NIbbler,

Could you please let me know how to tweak the code above to include the title field and the caption field in the searches? It looks like you tried to send me an example, but nothing came through. Thank you so much

Logged

Nibbler

  • Guest
Re: search for whole words
« Reply #8 on: February 11, 2010, 06:34:51 pm »

Try now. What web browser are you using?
Logged

blueberg

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 48
Re: search for whole words
« Reply #9 on: February 11, 2010, 07:11:45 pm »

I see it now,  IE8 browser. But can use Firefox if needed

Thanks
Logged

blueberg

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 48
Re: search for whole words
« Reply #10 on: February 11, 2010, 09:07:59 pm »

The code works great. Thanks Nibbler. I will resolve this thread :-)
Logged
Pages: [1]   Go Up
 

Page created in 0.026 seconds with 21 queries.