Uploaded image for project: 'Jackrabbit Content Repository'
  1. Jackrabbit Content Repository
  2. JCR-2557

JQOM Multiple Constraints Fail

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Won't Fix
    • 2.0
    • None
    • query
    • None

    Description

      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();

      Attachments

        Activity

          People

            stillalex Alex Deparvu
            chadmichael chad davis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: