1.5.6 Exact Keyword search phrases 1.5.6 Exact Keyword search phrases
 

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

1.5.6 Exact Keyword search phrases

Started by Big_T, July 15, 2010, 08:04:57 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Big_T

Hello,

I have been searching the forums for some time try to get a solution to this problem.

If I have keywords for 3 separate images labeled:

#1 pure black
#2 pure white
#3 pure green

If I type "pure white" in the search box all 3 images come up because they all share the word "pure"

Is there a workaround or code I can add to only match exact search phrases when using multiple search keywords?

I have found these posts which seemed promising:

http://forum.coppermine-gallery.net/index.php/topic,34219.msg160066.html#msg160066

http://forum.coppermine-gallery.net/index.php/topic,30310.msg140285.html#msg140285



but I believe they pertain only to 1.4 as when I alter the code on search.inc.php file located in the include folder, it seems to deactivate the search function all together?



Best regards,

Big_T




Αndré


Big_T

Quote from: Αndré on July 15, 2010, 09:29:37 AM
Board rules / Forum policies: Post Links

I'm not sure what difference it makes? The problem is described in original post.

Here is the link to my gallery in progress:

http://hd8y37tu8.mkoh.com/cpg15x/


phill104

The search is working as expected for me. I selected AND in the box the the keywords pure green returned only 2 images.

http://hd8y37tu8.mkoh.com/cpg15x/thumbnails.php?search=pure+green&submit=search&album=search&title=on&newer_than=&caption=on&older_than=&keywords=on&type=AND

The search for pure white returned

http://hd8y37tu8.mkoh.com/cpg15x/thumbnails.php?search=pure+white&submit=search&album=search&title=on&newer_than=&caption=on&older_than=&keywords=on&type=AND

While some of the keyword in the image - http://hd8y37tu8.mkoh.com/cpg15x/displayimage.php?album=search&cat=0&pid=358#top_display_media are pure black you also have "black & white, white" etc and more uses of those keywords so what do you expect to happen?
It is a mistake to think you can solve any major problems just with potatoes.

Αndré

Quote from: Big_T on July 15, 2010, 08:46:03 PM
I'm not sure what difference it makes?
Here's the difference:
Quote from: Phill Luckhurst on July 15, 2010, 09:05:26 PM
The search is working as expected for me. I selected AND in the box the the keywords pure green returned only 2 images.

Big_T

Quote from: Αndré on July 15, 2010, 09:12:47 PM
Here's the difference:



Ok let me rephrase and give an different example as the problem remains the same:

For most images of people I have the keyword either "Male" or "Female"  Well if you type in "male" you get all the females as well. 

One more example:

If you type in "pure white" you get all the "black and white" images.



My question remans the same: Is there a way to have the keywords match exactly? so if looking for "male" all them images tagged "female" will not show up in the search results?




Αndré

Has been asked/discussed many times before. Please use the search function of this board.

Big_T

Quote from: Αndré on July 16, 2010, 05:39:17 AM
Has been asked/discussed many times before. Please use the search function of this board.


Please read my original post.

I found the results to be unsatisfactory that is why I am asking for 1.5.6.

I have used the search function and found the following results:

http://forum.coppermine-gallery.net/index.php/topic,34219.msg160066.html#msg160066

http://forum.coppermine-gallery.net/index.php/topic,30310.msg140285.html#msg140285


I don't believe these solutions work in 1.5.6 unless I'm doing something wrong. All I did was replace the code in the "include/search.inc.php" file as instructed and reuploaded.


Do the fixes listed in the above post link work in 1.5.6? Possibly I'm doing something wrong, For me they do not work , when the fix code is replaced the entire search function does not yield any results at all.



Big_T



Αndré

Which of the two solutions did you try?

Big_T

I tried both solutions,

Each solution seemed to disable the search function.




Αndré

In include/search.inc.php, find
                        } elseif (strlen($string)) {
                                $words = explode(' ', $string);
                                foreach ($words as $word) {
                                        if (strlen($word)) {
                                                $word = addslashes($word);
                                                $fields = array();
                                                if ($superCage->get->keyExists('album_title') || $superCage->get->keyExists('category_title')) $albcat_terms[] = " LIKE '%$word%'";
                                                foreach ($search_params['params'] as $param => $value) {
                                                        if (in_array($param, $allowed)) $fields[] = "$param LIKE '%$word%'";
                                                }
                                                $sections[] = count($fields) ? '(' . implode(' OR ', $fields) . ')' : ''; 
                                        }
                                }
                        }

and replace with
                        } elseif (strlen($string)) {
                                $string = addslashes($string);
                                $fields = array();
                                if ($superCage->get->keyExists('album_title') || $superCage->get->keyExists('category_title')) $albcat_terms[] = " LIKE '%$word%'";
                                foreach ($search_params['params'] as $param => $value) {
                                        if (in_array($param, $allowed)) $fields[] = "$param LIKE '%$string%'";
                                }
                                $sections[] = count($fields) ? '(' . implode(' OR ', $fields) . ')' : ''; 
                        }

Big_T

 That didn't seem to work? It seemed to not generate any thing and the search function seemed to hang up. (Different from previous code changes, not displaying bottom graphics)

Could it have to do with the amount of "}" ?

At first I copied exactly as stated above thinking the amount of "}" was off,

then I copied and pasted right from the top to the last line: $sections[] = count($fields) ? '(' . implode(' OR ', $fields) . ')' : ''; 

But still yielded the same response.



Αndré

The code works for me as you want it to work. If it doesn't work for you, then you're doing something wrong. Sorry, but you give so little information that I lost the interest to help you.

Big_T

Quote from: Αndré on July 21, 2010, 09:27:50 PM
The code works for me as you want it to work. If it doesn't work for you, then you're doing something wrong. Sorry, but you give so little information that I lost the interest to help you.

Let me know know what information you need and I would be happy to provide. Sorry for being so vauge. What I did was replace the code as described and reupload the file to include folder.

Here is a link to what my search.inc.php file looks like as it sits now in the include folder : http://hd8y37tu8.mkoh.com/search.txt

Here is the result:  http://hd8y37tu8.mkoh.com/cpg15x/search.php


Type anything in the search box and you will see it does not work. I'm wondering what did I do wrong?


Thanks

Big_T

Disregard my previous post.  My bad I must have copied and pasted the code wrong sorry, fascinating how I could mess up such a simple task.

This code is useful in that it will match exact keywords, but, it will now not recognize keyword combinations. So if I have an image that is keyword tagged for "seamless" and "white"  (seamless,white). If I type "white seamless" in the search box. Nothing comes up.

Also still if I type "Male" all the "Female" tagged images still come up?

http://hd8y37tu8.mkoh.com/cpg15x/search.php


Tom

Αndré

If you want to achieve what you described, you have to choose a character which tells Coppermine where a keyword starts and where it ends (= where they are separated in the user input).

Example: if you enter 'pure white', are these 2 keywords or just one? Coppermine can't know.

But if you specify that a semi-colon is the separator and you enter 'pure;white' then Coppermine can handle them as 2 keywords. This specification has to be set in the code!

It's not trivial, as you have to split the keywords and compare them separately (or with a regex). Maybe I find some spare time later to create that code.

Big_T

Ahhh, I think I understand what you mean.

I'll try to figure it out.

I appreciate your help on it so far.


T