forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 miscellaneous => Topic started by: Big_T on July 15, 2010, 08:04:57 am

Title: 1.5.6 Exact Keyword search phrases
Post by: Big_T on July 15, 2010, 08:04:57 am
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



Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Αndré on July 15, 2010, 09:29:37 am
Board rules / Forum policies: Post Links (http://forum.coppermine-gallery.net/index.php/topic,55415.msg270616.html#msg270616)
Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Big_T on July 15, 2010, 08:46:03 pm
Board rules / Forum policies: Post Links (http://forum.coppermine-gallery.net/index.php/topic,55415.msg270616.html#msg270616)

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/

Title: Re: 1.5.6 Exact Keyword search phrases
Post by: phill104 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.

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?
Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Αndré on July 15, 2010, 09:12:47 pm
I'm not sure what difference it makes?
Here's the difference:
The search is working as expected for me. I selected AND in the box the the keywords pure green returned only 2 images.
Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Big_T on July 15, 2010, 10:33:28 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?



Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Αndré on July 16, 2010, 05:39:17 am
Has been asked/discussed many times before. Please use the search function of this board.
Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Big_T on July 16, 2010, 06:06:53 pm
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


Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Αndré on July 19, 2010, 07:52:17 am
Which of the two solutions did you try?
Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Big_T on July 19, 2010, 07:43:06 pm
I tried both solutions,

Each solution seemed to disable the search function.



Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Αndré on July 20, 2010, 01:26:41 pm
In include/search.inc.php, find
Code: [Select]
                        } 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
Code: [Select]
                        } 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) . ')' : ''; 
                        }
Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Big_T on July 21, 2010, 07:07:44 pm
 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.


Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Α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.
Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Big_T on July 22, 2010, 12:57:57 am
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
Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Big_T on July 22, 2010, 02:17:40 am
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
Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Αndré on July 22, 2010, 08:51:27 am
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.
Title: Re: 1.5.6 Exact Keyword search phrases
Post by: Big_T on July 23, 2010, 06:40:31 am
Ahhh, I think I understand what you mean.

I'll try to figure it out.

I appreciate your help on it so far.


T