Jeroen Hoffman pushed to branch bugfix/HIPPLUG-1396 at cms-community / hippo-plugin-relateddocs
Commits: 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 - - - - - 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 @@ -21,7 +21,7 @@ import java.util.Set; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; -import javax.jcr.query.Query; +import javax.jcr.query .Query; import javax.jcr.query.Row; import javax.jcr.query.RowIterator; @@ -29,7 +29,6 @@ import org.hippoecm.frontend.model.JcrNodeModel; import org.hippoecm.frontend.plugin.IPluginContext; import org.hippoecm.frontend.plugin.config.IPluginConfig; import org.hippoecm.repository.api.HippoNode; -import org.hippoecm.repository.api.HippoNodeType; import org.onehippo.forge.relateddocs.RelatedDoc; import org.onehippo.forge.relateddocs.RelatedDocCollection; import org.onehippo.forge.relateddocs.RelatedDocsNodeType; @@ -67,23 +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<>(); + Set<String> currentUuidSet = new HashSet<>(); for (RelatedDoc r : currentCollection) { - uuidSet.add(r.getUuid()); + currentUuidSet.add(r.getUuid()); } Node docNode = documentModel.getNode(); - Node parentNode = docNode.getParent(); + 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( @@ -101,34 +99,27 @@ public class SimilaritySearchRelatedDocsProvider extends AbstractRelatedDocsProv // retrieve the found document from the repository try { Node document = nodeModel.getNode().getSession().getNode(path); - Node itsParent = ((HippoNode) document).getCanonicalNode(); - if (parentNode.isSame(itsParent)) { + Node canonicalDocument = ((HippoNode) document).getCanonicalNode(); + if (docHandleNode.isSame(canonicalDocument)) { if (log.isDebugEnabled()) { - log.debug("Found parent {}", itsParent.getPath()); + log.debug("Skipping same handle node as 'self' at {}", canonicalDocument.getPath()); } continue; } - if (document.isNodeType(HippoNodeType.NT_HANDLE)) { - if (uuidSet.contains(document.getIdentifier())) { - continue; - } + + if (currentUuidSet.contains(document.getIdentifier())) { if (log.isDebugEnabled()) { - log.debug("Found related document {}", document.getPath()); - } - collection.add(new RelatedDoc(new JcrNodeModel(document), this.score * myScore)); - } else if (itsParent.isNodeType(HippoNodeType.NT_HANDLE)) { - if (uuidSet.contains(itsParent.getIdentifier())) { - continue; - } - // exclude prototype stuff: note need to check this - final JcrNodeModel jcrNodeModel = new JcrNodeModel(itsParent); - if (jcrNodeModel.getNode().getPath().endsWith("hippo:prototype")) { - continue; + log.debug("Not adding already selected document {}", document.getPath()); } - collection.add(new RelatedDoc(jcrNodeModel, this.score * myScore)); + 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/df3757461ccffd96ab3c1ce57552d1ba38380178...3dc243ee4a5945254633b7bfb3390a034cfa3e13
_______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.onehippo.org https://lists.onehippo.org/mailman/listinfo/hippocms-svn