https://bugs.kde.org/show_bug.cgi?id=302923
--- Comment #6 from Mario Frank <mario.fr...@uni-potsdam.de> --- After a longish phase on crawling the code and testing, I do have a working solution. Sorting by similarity is quite easy. The only missing thing for this feature was the similarity property, i.e. the similarity of a found picture to the original one. This similarity was printed during duplicates/fuzzy search but there is neither a field in the ImageInfo nor in the properties. Thus I extended the ImageProperties. Since my current staged changes also concern Bug https://bugs.kde.org/show_bug.cgi?id=320666 , I will describe my solution in detail for both bugs here. It will be quite technical since I want to make clear why I did what. I can also upload a patch for review if wished. So here is the description: In short: For sorting by similarity, a new option Sort by similarity with default order descending was introduced. This option is only active if the fuzzy search sidebar is active, i.e. fuzzy/duplicates/sketch search. To compare two pictures, it is necessary to get their similarity to the original picture. Since this information was only printed to console but not saved in the image info, SAlbum query or the properties, I do that myself. For every similar picture, a property similarityTo_X with X being the id of the original image and the similarity are stored as image property. When the image with id X is deleted, the property is removed to keep the DB small. Also, the property is removed from images if the fuzzy/duplicates search is done for image X such that old similarity values are removed. Though the similarity of image X to image Y is symmetric, I do not want to store both. This would bloat the DB. Only the detected similarities are explicitly stored. This way, Sorting works in fuzzy, duplicates and sketch search. - The DigikamApp is extended with the new QAction sort by similarity which is disabled on start and only is enabled if the fuzzy search sidebar is active. - The DigikamView is signalled by the FuzzySearchSidebarWidget with the signal signalActive(bool) and the DigikamView triggers the slot slotFuzzySidebarActive(bool). This signal is forwarded to the DigikamApp where setEnabled(bool) of the QAction (sort by similarity) is called. Also, the DigikamView is signalled by the FuzzySearchSidebarWidget with the signal signalImageChanged() and the DigikamView triggers the slot slotUpdateFuzzyReferenceImage(). Here, the selected reference image is loaded from the application settings and set in the ImageFilterModel. The slot slotSortImages of the DigikamView is extended in a way that the reference image for sorting is set in the ImageFilterModel if the sort role is SortBySimilarity. - The SearchModificationHelper is extended with a method createFuzzySearchFromDropped and a slot slotCreateFuzzySearchFromDropped which gets the path of the image file as parameter. The method generates a new SAlbum query with the new type image and sketchtype scanned and sets the file path as value of the query. - The LeftSidebarWidget is extended with a slot and signal ImageChanged() and a signal signalActive(bool). The signal signalActive is emitted every time, setActive(bool) is called. - The slot slotImageChanged is triggered by a signal signalReferenceImageSelected() from the FuzzySearchView. This slot forwards the signal by emitting signalImageChanged(). - The slot slotImagesDeleted of the AlbumManager is extended. Here, the property “similarityTo_”imageid is deleted for every deleted image. Meaning, all similarity connections to the image to delete are removed from database. - The CoreDb is extended with a method removeImagePropertyByName which does exactly that. All ImageProperties that have the given name are deleted. - The ImageExtendedProperties are extended with a method similarityTo which returns the similarity (double value) of the image to the image given by the parameter. Also, a setter setSimilarityTo and a deletion method removeSimilarityTo were implemented. - The ImageInfo is extended with a function similarityTo that gets the similarity from the ImageExtendedProperties. - HaarIface is extended with a method bestMatchesForImageWithThreshold which gets the file path together with the similarity thresholds, generates a QImage with the existing method loadQImage, generates the signature of the image and starts a fuzzy search for this temporary image with the temporary image id -1. The method bestMatchesWithThreshold now stores the similarity to the original image for every found image as property in the database. - The method listHaarSearch from the ImageLister is extended and triggers bestMatchesForImageWithThreshold if the search query has the type image. - The ImageFilterModel is extended with a method setReferenceImageId which sets the id of the image for that a fuzzy search is done in the sorter. - The ImageSortSettings are extended with the new SortRole, a field for the reference image id and a setter for this field. Moreover, the default sort order for sort by similarity is set to descending in the method defaultSortOrderForCategorizationMode. Also, the compare method is extended with a case for sort by similarity where the similarity to the reference image given by the id is used for comparison. The watch flags for sort by similarity are set to DatabaseFields::Name. I am not sure whether there is a better solution. There is nothing to watch for, is it? - The ApplicationSettings are extended with a setter and getter for the reference image id for fuzzy search. - The slot slotDuplicatesAlbumActived of the FindDuplicatesView sets the reference image id which is the name of the SAlbum. This way, sorting by similarity is possible for every album in the duplicates view. But if multiple SAlbums are selected in the FindDuplicatesView, the reference image id is the one of the first selected SAlbum. I do not see a better solution. Does Anyone else? - The FuzzySearchView is extended in the following way. For dropping external images, a new field (a QURL) was introduced which is set during the drop action. An external image can only be dragged into the image label if the mime type that Qt gets is a URL which leads to a local file that can be read by Qt as image. If these restrictions are confirmed, the dropping of the image is allowed. Then, the URL is set in the FuzzySearchView, a QImage and a temporary ImageInfo are generated. By setting the URL, it is possible to refresh the similar pictures when the thresholds are modified (via slotTimerImageDone). A temporary thumbnail is generated and the file name and file path are set in the view. In order to be able to sort by similarity, the temporary image id -1 is used which cannot be existent in database. Also, setCurrentImage is extended to set the reference image id in the ApplicationSettings and emit the signal that the reference image was changed. -- You are receiving this mail because: You are watching all bug changes.