You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "Alex Parvulescu (JIRA)" <ji...@apache.org> on 2011/04/20 21:59:05 UTC

[jira] [Commented] (JCR-2557) JQOM Multiple Constraints Fail

    [ https://issues.apache.org/jira/browse/JCR-2557?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13022342#comment-13022342 ] 

Alex Parvulescu commented on JCR-2557:
--------------------------------------

It seems to me that the QOM ChildNode condition is more suited in this scenario.
The issue reporter goes to great lengths to turn the DescendantNode condition into a ChildNode.

I'd opt to close this issue as now we have a simpler /cleaner way to build this kind of queries.

See the api compliance tests for example of how the ChildNode [1] constraint works vs the DescendantNode [2] one.

[1] http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeTest.java?view=markup
[2] http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeTest.java?view=markup

> JQOM Multiple Constraints Fail
> ------------------------------
>
>                 Key: JCR-2557
>                 URL: https://issues.apache.org/jira/browse/JCR-2557
>             Project: Jackrabbit Content Repository
>          Issue Type: Bug
>          Components: query
>    Affects Versions: 2.0.0
>            Reporter: chad davis
>            Priority: Critical
>
> I'm unable to correctly execute the following search logic.  I have a
> folder node with documents and folders in it.  I would like to search
> the folder's contents, but I would NOT like the search to enter the
> child folders.  
> With this in mind, I'm trying to build a search query that hits
> everything in the target folder, but not in the target folders' child
> folders. This leads me to use a descendent node, for the target folder, AND'd
> with a number of NOT descedent nodes, one for each of the child folders of the 
> target folder.  
> I'll describe my query building logic, then show my code.
> 1) Build a source that is a selector of all nt:base nodes in the repo
> 2) build a fullTextSearch constraint with my query string
> 3) build a DescendantNode constraint that limits my hits to descedants
> of my target folder
> 4) build a AND constraint of these first two
> Note: this works just fine so far
> 5) build a DescendentNode constraint for the first of the children
> folders of the target folder
> 6) build a NOT constraint from the descendant constraint in step 5
> 7) build an AND constraint of this NOT and the AND from step 4
> This also works fine.  Here's  the problem area.
> 8) build a DescendantNode constraint for the second of the children
> folders of the target folder
> 9) build a NOT constraint from the desc. constraint from step 8
> 10) build an AND constraint of this NOT and the AND from step 7
> This doesn't work.  Interestingly, it seems like you just can't add
> AND's to the tree; the second child folder NOT'd and AND'd to the
> original query, doesn't work.  Maybe I'm misunderstanding how to
> achieve this.  Here's my code:
> //Select all nt:base
> Source allDocsSelector = qomFactory.selector("nt:base", "allDocs");
> //Build the fullTextSearchConstraint AND'd with the target folder
> Constraint fullTextSearchConstraint =
> buildFullTextSearchConstraint(session, queryString, qomFactory);
> Constraint targetFolderConstraint = buildRootFolderConstraint(session,
> targetFolder, qomFactory);
> And textQueryANDTargetFolderConstraint = qomFactory.and(
> fullTextSearchConstraint, targetFolderConstraint );
> //Build NOT descendant constraints to keep the search out of child folders
> //NOT descendant of "folderOne", one of the child folders of the target folder
> String path = "/BIP/1/1/folderOne/";
> Constraint descendantOfFolderOne = qomFactory.descendantNode("allDocs", path );
> Not notDescendantOfFolderOne = qomFactory.not(descendantOfFolderOne);
> And targetedFullTextANDNotFolderOne =
> qomFactory.and(textQueryANDTargetFolderConstraint,
> notDescendantOfFolderOne );
> String apath = "/BIP/1/1/folderTwo/";
> Constraint descendantOfFolderTwo = qomFactory.descendantNode("allDocs", apath );
> Not notDescendantOfFolderTwo = qomFactory.not(descendantOfFolderTwo);
> And targetedFullTextANDNotFolderOneANDNotFolderTwo =
> qomFactory.and(targetedFullTextANDNotFolderOne,
> notDescendantOfFolderTwo );
> QueryObjectModel queryObjectModel = qomFactory.createQuery(
> allDocsSelector, targetedFullTextANDNotFolderOneANDNotFolderTwo, null,
> null);
> QueryResult results = queryObjectModel.execute();

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira