Jeroen Hoffman pushed to branch release/4.0 at cms-community / 
hippo-plugin-relateddocs


Commits:
871bf85d by Marijan Milicevic at 2016-10-19T15:25:12+02:00
HIPPLUG-1396 Regression: Related Documents - Adding suggested document 
doesn't remove it from the list of suggestions.
- remove existing documents from suggestion list
- don't suggest own document

- - - - -
21903f8a by Marijan Milicevic at 2016-10-20T12:38:43+02:00
HIPPLUG-1396 Regression: Related Documents - Adding suggested document 
doesn't remove it from the list of suggestions.
- remove existing documents from suggestion list
- don't suggest own document

- - - - -
3e1c8726 by Marijan Milicevic at 2016-10-20T12:40:29+02:00
Revert "HIPPLUG-1396 Regression: Related Documents - Adding suggested 
document doesn't remove it from the list of suggestions."

This reverts commit 21903f8ad7853406666793d7f0d086e7707c1943.

- - - - -
b7d83a81 by Marijan Milicevic at 2016-10-20T12:40:44+02:00
Revert "HIPPLUG-1396 Regression: Related Documents - Adding suggested 
document doesn't remove it from the list of suggestions."

This reverts commit 871bf85d6835bdb676418cc8c2128062eb64b948.

- - - - -
df375746 by Marijan Milicevic at 2016-10-20T12:42:15+02:00
HIPPLUG-1396 Regression: Related Documents - Adding suggested document 
doesn't remove it from the list of suggestions.
- remove existing documents from suggestion list
- don't suggest own document

- - - - -
a1c183ca by Jeroen Hoffman at 2016-10-24T14:59:22+02:00
HIPPLUG-1396 remove 'else' branch that will not be reached; rename some 
variables for readability (e.g. itsParent --> canonicalDocument)

- - - - -
3dc243ee by Jeroen Hoffman at 2016-10-25T11:29:03+02:00
HIPPLUG-1396 Llogging improvements

- - - - -
60b23aea by Jeroen Hoffman at 2016-10-25T11:31:15+02:00
HIPPLUG-1396 Indents only

- - - - -
72317a80 by Jeroen Hoffman at 2016-10-25T11:53:11+02:00
HIPPLUG-1396 Reintegrate branch 'bugfix/HIPPLUG-1396' into release/4.0

- - - - -


1 changed file:

- 
addon-cms/src/main/java/org/onehippo/forge/relateddocs/providers/SimilaritySearchRelatedDocsProvider.java


Changes:

=====================================
addon-cms/src/main/java/org/onehippo/forge/relateddocs/providers/SimilaritySearchRelatedDocsProvider.java
=====================================
--- 
a/addon-cms/src/main/java/org/onehippo/forge/relateddocs/providers/SimilaritySearchRelatedDocsProvider.java
+++ 
b/addon-cms/src/main/java/org/onehippo/forge/relateddocs/providers/SimilaritySearchRelatedDocsProvider.java
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2009-2015 Hippo B.V. (http://www.onehippo.com)
+ *  Copyright 2009-2016 Hippo B.V. (http://www.onehippo.com)
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ import javax.jcr.query.RowIterator;
 import org.hippoecm.frontend.model.JcrNodeModel;
 import org.hippoecm.frontend.plugin.IPluginContext;
 import org.hippoecm.frontend.plugin.config.IPluginConfig;
-import org.hippoecm.repository.api.HippoQuery;
+import org.hippoecm.repository.api.HippoNode;
 import org.onehippo.forge.relateddocs.RelatedDoc;
 import org.onehippo.forge.relateddocs.RelatedDocCollection;
 import org.onehippo.forge.relateddocs.RelatedDocsNodeType;
@@ -66,22 +66,22 @@ public class SimilaritySearchRelatedDocsProvider extends 
AbstractRelatedDocsProv
         try {
             nodeModel = new 
JcrNodeModel(documentModel.getNode().getNode(RelatedDocsNodeType.NT_RELATEDDOCS));
         } catch (PathNotFoundException e) {
-            //I think when a new document is opened, the document doesn't 
contain the "relateddocs" node yet, so we *may* need to create one -- Vijay
-            log.info("Relateddocs node for current document not found, 
returning empty docs, so creating one." + e.getMessage());
+            log.info("Relateddocs node for current document not found, 
returning empty docs, so creating one. Message={}.", e.getMessage());
             nodeModel = new 
JcrNodeModel(documentModel.getNode().addNode(RelatedDocsNodeType.NT_RELATEDDOCS,
 RelatedDocsNodeType.NT_RELATEDDOCS));
         }
 
         RelatedDocCollection currentCollection = new 
RelatedDocCollection(nodeModel);
-        Set<String> uuidSet = new HashSet<String>();
+        Set<String> currentUuidSet = new HashSet<>();
         for (RelatedDoc r : currentCollection) {
-            uuidSet.add(r.getUuid());
+            currentUuidSet.add(r.getUuid());
         }
 
         Node docNode = documentModel.getNode();
+        Node docHandleNode = docNode.getParent();
         String xpathQuery = createXPathQuery(docNode);
 
         if (log.isDebugEnabled()) {
-            log.debug("Executing query{}: ", xpathQuery);
+            log.debug("Executing query: {}", xpathQuery);
         }
         @SuppressWarnings(value = "deprecation")
         Query query = 
nodeModel.getNode().getSession().getWorkspace().getQueryManager().createQuery(
@@ -99,9 +99,27 @@ public class SimilaritySearchRelatedDocsProvider extends 
AbstractRelatedDocsProv
             // retrieve the found document from the repository
             try {
                 Node document = nodeModel.getNode().getSession().getNode(path);
+                Node canonicalDocument = ((HippoNode) 
document).getCanonicalNode();
+                if (docHandleNode.isSame(canonicalDocument)) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Skipping same handle node as 'self' at {}", 
canonicalDocument.getPath());
+                    }
+                    continue;
+                }
+
+                if (currentUuidSet.contains(document.getIdentifier())) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Not adding already selected document {}", 
document.getPath());
+                    }
+                    continue;
+                }
+
+                if (log.isDebugEnabled()) {
+                    log.debug("Adding related document {}", 
document.getPath());
+                }
                 collection.add(new RelatedDoc(new JcrNodeModel(document), 
this.score * myScore));
             } catch (RepositoryException e) {
-                log.error("Error handling SimilaritySearch results", 
e.getMessage());
+                log.error("{} handling SimilaritySearch result on path {}. 
Message={}", e.getClass().getName(), path, e.getMessage());
             }
         }
         return collection;



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-plugin-relateddocs/compare/07864e0004f5827fc19da942443312e8cb689296...72317a805c23b9249795e1cd47923a34cb21361b
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to