Support » Plugin: WP Photo Album Plus » Duplicates in Search Results

  • Resolved gsdesign

    (@gsdesign)


    Greetings Jacob,

    I really appreciate your support and development of this plugin. I’m feeling like I’m bothering you, but someone within our company wants to know if there is a way to remove duplicates from searches. See, we have some of the same images with the same description and same filename in multiple galleries, and when you search, it picks up them all and puts them on the search results page. The person wants an image to only show up once in the search results.

    I noticed that someone asked about this 6 years ago, but there wasn’t a response. I don’t know if that was before you started working on the plugin, or if you have since developed a way to handle this. We are hoping there’s a way to do this.

    Even if this isn’t possible, I’d like to thank you for your work, its good.

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Author Jacob N. Breetvelt

    (@opajaap)

    I am maintaining this plugin since the end of 2009, but still learning every day…

    I understand your question and could implement this. However, I have one point of concern: The ‘duplicates’ are not really duplicates with respect to any possible reference to the album they belong. If this is no problem for you, i will implement it as an extra option setting (so it can be switched off when not needed) because it will have a noticable effect on the speed of finding the search results. I have to compare the actual image files on equality, because having the same name and description does not need to mean that the photofiles are identical.

    Wow Jacob, that would be great if you could implement something like that! I understand that each image is given a unique identifier, maybe if there was some way to link the identifiers for the files that should only appear in the search results once, in the interface somewhere, then the search function could look at them as a single item, maybe that would cut down on some of the overhead for the search engine and prevent problems with files being mistakenly taken out of the search results. Your the expert though, just a thought.

    Thank you so much for the response and for putting the effort into thinking of a way to handle this.

    Regards.

    Plugin Author Jacob N. Breetvelt

    (@opajaap)

    Sorry, but your suggestion is too much overhead, complex and vulnerble to db incostistencies.

    I implemented your request; it works as follows:

    After the search results (photo ids) are found, they will all be checked against each other:

    If the photonames are equal:
    If the photodescriptions (prior to possible expanding w#-keywords) are equal:
    If the display files are equal:
    Remove the latter one from the search results

    If you are using w#-keywords like w#albumname in the photo description, this will not be transalted to test equality, so even in this case they are seen as equal.

    The number of file compares is no more than the number of cases where both the names and descriptions are equal.
    You may expect noticable performance issues (i did some tests) only when the number of found items is coniderably high, say 100 or more. This is caused by the fact that there are (n*(n-1))/2 checks to be done for n items; the number increases by n to the power of 2.

    Do as explained here: https://wppa.nl/docs-by-subject/development-version/ ,
    tick Table IX-E21 Extended duplicate removal Remove found items from search when name, description and image are identicaland, and tell me if it suits your needs.
    If you experience performance issues, you can limit the number of found images in Table IX-E9 Max photos found.

    If you want any changes or if you experience issues, pls let me know, its easier to change anything before the official release.

    PS: It works not only for regular search, but also for searching on tags (e.g. tagcloud) etc.

    Hey Jacob,

    It’s incredible that you were willing and able to do that so quickly! I installed the development version. (BTW it seems to be compatible with WordPress 5.2.1 in case it hasn’t been tested on that yet).

    I ran into one snag though. It seems that, everything being the same, if the tags are different, they get picked up as two separate files and duplicates occur in the search results (that’s the only explanation I can find for what I’m seeing on the staging server). We have some images that have different tags depending on the gallery. So this is a little bit of a problem. Just thought I’d make you aware of that.

    Also can you clarify, is the Filename compared? It may be better to use the Photo name, because that is alterable, and photos could lumped together intentionally (also, don’t ask how, but there were issues where we have the same photo name and the same file, but uploaded under a different filename because of some sort of intermittent upload error that was worked around).

    Sorry if that complicates things a bit. Its just exciting to work with such an engaged developer.

    Someone here was so encouraged by your response to this issue that he may want to make requests for future improvements/additions. Is there a place to make such suggestions?

    Thank you so much.

    Regards.

    Plugin Author Jacob N. Breetvelt

    (@opajaap)

    Strange. On my testsite it works correctly with different tags, if the second photo is a copied version of the first, i.e. the photo names, descriptions and files are identical.

    A silly question: did you see it working anyway?

    Maybe the name(s) or description(s) have been edited and there is a tiny difference, like a trailing space or so. Currently the comparision is strict.

    To give you tech details (if you can read php):

    The decision if the ‘extended’ duplicate removal should be performed is made in wppa-functions.php, line 1948:

    	// Extended dups removal?
    	$exduprem = wppa_switch( 'extended_duplicate_remove' ) &&
    				( wppa( 'src' ) || wppa( 'is_tag' ) || wppa( 'supersearch' ) );
    

    This means: If the feature is enabled (wppa_switch( 'extended_duplicate_remove' )) AND either it is regular search (wppa( 'src' )) OR it is tag search (wppa( 'is_tag' )) OR it is supersearch (wppa( 'supersearch' )), do the extended dup removal.

    The actual code is in line 2030:

    // Remove duplicates where name, description and display files are identical
    function wppa_extended_duplicate_remove( &$thumbs ) {
    
    	if ( is_array( $thumbs ) ) {
    		$c = count( $thumbs );
    		$i = 0;
    		while ( $i < ( $c - 1 ) ) {
    			if ( isset( $thumbs[$i] ) ) {
    				$j = $i + 1;
    				while ( $j < $c ) {
    					if ( isset( $thumbs[$j] ) ) {
    						if ( wppa_get_photo_item( $thumbs[$i]['id'], 'name' ) == wppa_get_photo_item( $thumbs[$j]['id'], 'name' ) ) {
    							if ( wppa_get_photo_item( $thumbs[$i]['id'], 'description' ) == wppa_get_photo_item( $thumbs[$j]['id'], 'description' ) ) {
    								$p = wppa_get_photo_path( $thumbs[$i]['id'] );
    								$q = wppa_get_photo_path( $thumbs[$j]['id'] );
    								if ( wppa_get_contents( $p ) == wppa_get_contents( $q ) ) {
    									wppa_log( 'dbg', 'Items ' . $thumbs[$i]['id'] . ' and ' . $thumbs[$j]['id'] . ' are identical' );
    									unset( $thumbs[$j] );
    								}
    							}
    						}
    					}
    					$j++;
    				}
    			}
    			$i++;
    		}
    	}
    }
    

    wppa_get_photo_item( $id, $item ) gets the raw data from the db.

    As you can see, only photo name and photo description are checked, no tags of filename.
    If they both match, the filecontent is compared.

    I would like to see it myself.
    You may email me to supply admin login details if you are willing to give me that.
    Also give me an example of what to do to see it going wrong. You may also ask me for enhancements. You can mail me at opajaap at opajaap dot nl

    Plugin Author Jacob N. Breetvelt

    (@opajaap)

    Please install this zip like you did with the dev version:
    https://downloads.wordpress.org/plugin/wp-photo-album-plus.7.1.11.007.zip

    I made the following changes:
    The check on equality of name and description is a little looser:
    case insensitive, and insensitive for differences in spaces and newlines.

    I also added a few more debug messages. If you tick the box in Table XI-A9.5: Log Debug messages, and inspect the logfile (Table VIII-C1) you will see messages like (most recet first):

    Dbg: on:25.05.2019 09:20:06: opajaap: wppa_extended_duplicate_remove() took 0.03 seconds
    Dbg: on:25.05.2019 09:20:05: opajaap: Items 1569 and 283 are identical
    Dbg: on:25.05.2019 09:20:05: opajaap: Items 1574 and 283 have the same name but different descriptions
    Dbg: on:25.05.2019 09:20:05: opajaap: Items 1574 and 1569 have the same name but different descriptions
    Dbg: on:25.05.2019 09:20:05: opajaap: Items 1575 and 283 have the same name and descriptions but different files
    Dbg: on:25.05.2019 09:20:05: opajaap: Items 1575 and 1569 have the same name and descriptions but different files
    Dbg: on:25.05.2019 09:20:05: opajaap: Items 1575 and 1574 have the same name but different descriptions
    

    This should enabe you to find out why you see duplicates as you reorted before.

    Plugin Author Jacob N. Breetvelt

    (@opajaap)

    Fixed 7.1.11

    gsdesign

    (@gsdesign)

    Hey Jacob,

    It’s amazing that you did all that work. I’m sorry I couldn’t do much beta testing on our site and I’m so late getting back to you. Your work has cut down the number of duplicates significantly, but we are still experiencing duplicates in our search results … not as many, but one or two here or there. I know you may be racking your brain, so maybe you can explain what properties exactly you are using to sift through the photos and remove duplicates. I want to make sure that all that matches up before/if you start diving into the code again.

    Anyway, the work you’ve done is amazing. Thanks for supporting and developing this plugin.

    Regards.

    gsdesign

    (@gsdesign)

    Hey Jacob,

    I went through debugging (the checkbox for enabling debugging is actually under settings IXA9.5 not XIA9.5). Anyway. It says that I have some files that have the same name and description but are different files. I checked out one of those (I believe they were copies as they were sequential 495 and 496 (we often copy the same image to multiple albums after upload)) and they indeed showed up multiple times in the search results … just as an example. I’m not sure how in that case, why they are being identified as different files, since they seem (I know we have some that aren’t) direct copies from one album to another. Is there a way to have an option to loosen the criteria even more, just go by name and description?

    You’ve done some amazing work so far, I don’t mean to add to the load of all that you have going on, but such a feature would good, because it would allow the duplicate matching to be user controlled, instead of based partially on something that can get complicated in systems such as ours.

    Thanks again for developing and supporting this plugin.

    Regards.

    Plugin Author Jacob N. Breetvelt

    (@opajaap)

    IXA9.5 not XIA9.5

    Sorry, typo.

    Skipping a test on file equality is unacceptable because of the risk of finding false positives.

    However, i first opted for maybe the most strict way of testing equal files. I can imagine that one of them has been (differently) optimized by e.g. ewww-image-optimizer.

    I did the test on – in your example – the equality of the filecontent of the files
    …/wp-content/uploads/wppa/495.jpg and …/wp-content/uploads/wppa/496.jpg (assuming .jpg and flat filesystem structure).

    I can imagine that the files are to big to do this properly with the php function file_get_contents( $file );

    Please do the following: Use an ftp program like Filezilla and see if you can find differences between the two files and between the corresponding thumbnail files, e.g. …/wp-content/uploads/wppa/thumbs/495.jpg and …/wp-content/uploads/wppa/thumbs/496.jpg.
    Maybe you find a somewhat less strictly tests that will identify the equality between the two items, think of filesize or identical thumbnails.

    If you save the source files, and after you examined the above, try to remake files of these two items (on the photo admin screen press the Remake files button and check if they are now find to be identical.

    To change the code, i would think about something like testing on equality of sourcefiles, display files (as now), thumbnail files, and maybe the assumption that equal filesizes mean equal photos…??

    Conclusion: I have a lot of ideas to make this better, but i really would be glad to know why your items 495 and 496 are currently seen as different and what they might have in common with respect to the files.

    gsdesign

    (@gsdesign)

    Hey Jacob,

    Thanks for the response, I’m in a bit of a rush today, but I did log in to the server and here’s the output for those files on in the wppa directory (the source files, I believe):

    -rw-r–r– 1 ********** inetuser 180361 Mar 5 15:37 495.jpg
    -rw-r–r– 1 ********** inetuser 180083 Mar 5 15:37 496.jpg

    I forgot to look at the thumbnails before remaking them, but here was the output from that folder after remaking them:

    -rw-r–r– 1 ********** inetuser 101710 Jun 19 11:05 495.jpg
    -rw-r–r– 1 ********** inetuser 101710 Jun 19 11:05 496.jpg

    As you can see the source files are slightly different in size for some reason. But the thumbnails are the same size. Despite the thumbnails being the same size, the problem with the duplicates is still there.

    Like I wrote, I’m a little busy today, but hopefully that gives you some info to work from.

    Thanks so much.

    Regards.

    Plugin Author Jacob N. Breetvelt

    (@opajaap)

    I changed the algorithm to work as follows:

    Two items are regarded to be the same when:
    Photo names, descriptions and filenames are the same and one of the following statements is true:
    – The EXIF ImageUniqueIDs have been recorded in the wppa_exif db table and are non empty and are identical. Flag = 0x0001.
    – The EXIF Date/Time originnals were present during uploaded and are identical. Flag = 0x0002.
    – At least three of the following tests are positive:
    – – Source files exist and have the same filesize. Flag = 0x4000.
    – – Display files exist and have the same filesize. Flag = 0x2000.
    – – Thumbnail files exist and have the same filesize. Flag = 0x1000.
    – – Thumbnail files exist and have the same content. Flag = 0x0100.
    – – Display files exist and have the same content. Flag = 0x0200.
    – – Source files exist and have the same content. Flag = 0x0400.
    Status codes (flags) are combined bits and are printed as hex numbers in the debug log like:
    Dbg: on:20.06.2019 10:42:06: opajaap: Items 1574 and 1569 are identical. Flags = 0x3100

    This version (7.2.01.000) is available as current development version, see: https://wppa.nl/docs-by-subject/development-version/

    If you have time to do so, please test this version and tell me if you get warning debug messages like:
    War: on ...: user: Items nn and mm have the same name, filename and description but score only x out of 6 possible matches. Flags = 0x...

    Greetings Jacob,

    You’re doing a great job with the plug-in. I’m noticing even still fewer duplicates.

    A couple of weeks ago I tried to manually install the development package but it wouldn’t install for some reason. I followed the directions and everything and the development package just wouldn’t install. I tried 3 times on the staging server doing an manual install through WordPress and it just wouldn’t go (I tried a few different things each time, but still, it would not go). I didn’t have the time to get over to the forums … sorry. So I waited for the release to come out to use WP Update function and that seemed to work. My apologies for not being able to work on a pre-release and give you feedback.

    From the current update, I’m getting fewer duplicates, but still getting some duplicates, for some reason.

    I checked the log and did find the some of the new debug warnings you mentioned earlier in the thread (for some reason Microsoft’s Edge has a hard time with the Log overlay, so I’ll just retype what some of the output is): All the warnings start with: “… have the same name, filename and description” then they differ, a couple have “2 out of 6 possible matches. Flags = 0x04110” and one has “0 out of 6 possible matches. Flags = 0x040”

    You’re probably tired of working on this. It’s working much better than before. If you are still working on this, it’s much appreciated. If your done with this function, it’s understandable. Just thought I’d give you some feedback. Your work is tremendous and much appreciated. If you can iron out the kinks, it seems like you’re in the homestretch with this new debug data.

    Many thanks.

    Regards.

    • This reply was modified 4 months, 1 week ago by gsdesign.
    Plugin Author Jacob N. Breetvelt

    (@opajaap)

    It would not be too difficult to loosen the conditions a bit more.
    A few questions:

    – pls verify the flags, as it looks you did not correctly copy them into your reply.

    – Are you saving the sourcefiles?

    Plugin Author Jacob N. Breetvelt

    (@opajaap)

    Tip: Add the logfile to the menu (Table VIII-C1 checkbox). Running the log from the manu displayes it on a normal admin page.

    Probably the upload of the zip fails (i have that also sometimes) when the upload time is too long due to poor or busy internet connection.
    If you install plugin https://wordpress.org/plugins/wordpress-beta-tester/ you can update beta versions (when they are tagged) like normal updates.

Viewing 15 replies - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.