search for whole words search for whole words
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

search for whole words

Started by blueberg, February 05, 2010, 07:26:56 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

blueberg

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.

Old RMN

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.
Sometimes to find the way home one has to leave it.

Old RMN

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.
Sometimes to find the way home one has to leave it.

blueberg

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
if (in_array($param, $allowed))$fields[] = "$param LIKE '%$word%'";


to this
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:

<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:
<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.

Nibbler

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

@blueberg:



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



Can be changed as required, eg.




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




blueberg

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

Old RMN

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
Sometimes to find the way home one has to leave it.

blueberg

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


Nibbler

Try now. What web browser are you using?

blueberg

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

Thanks

blueberg

The code works great. Thanks Nibbler. I will resolve this thread :-)